1
0
Fork 0
mirror of https://gitlab.com/oloturia/damastodon.git synced 2025-01-08 06:27:15 +01:00

todo: checkFour

This commit is contained in:
oloturia 2022-04-30 19:01:35 +02:00
parent 209fdc7f05
commit 97298be316

View file

@ -39,35 +39,27 @@ def dropChip(board,move_str,player):
return board, checkFour(board,free_space,move) return board, checkFour(board,free_space,move)
def checkFour(board,row,col): def checkFour(board,row,col):
offset_pairs = ( ((0,1),(0,-1)) , ((1,0),(-1,0)) , ((1,1),(-1,-1)) , ((-1,1),(1,-1)) ) sumOr = lambda a,b : (a[0]+b[0], a[1]+b[1])
points = 0 orients = { "N":(1,0),"S":(-1,0),"E":(0,1),"W":(0,-1) }
for offset in offset_pairs:
count = 0
count += checkSide(board,row,col,offset[0])
count += checkSide(board,row,col,offset[1])
if count >= 4:
points += 1
return points
def checkSide(board,row,col,incs):
incY,incX = incs
count = 0
player = board[row][col] player = board[row][col]
offsetX = 0 offX = 0
offsetY = 0 offY = 0
while count < 4: #TODO
try:
if board[row+offsetX][col+offsetY] == player:
count += 1 return points
offsetX += incX
offsetY += incY def checkPly(board,row,col,player):
else: if row < 0 or col < 0:
break return False
except IndexError: try:
break if board[row][col] == player:
return count return True
else:
return False
except IndexError:
return False
if __name__ == "__main__": if __name__ == "__main__":
board = initChequerboard() board = initChequerboard()
@ -77,6 +69,8 @@ if __name__ == "__main__":
points_2 = 0 points_2 = 0
while match: while match:
drawChequerboard(board) drawChequerboard(board)
print("Player 1:"+str(points_1))
print("Player 2:"+str(points_2))
move = input("Player "+str(player)+" turn:") move = input("Player "+str(player)+" turn:")
if move == "q": if move == "q":
print("quitting") print("quitting")
@ -102,7 +96,7 @@ if __name__ == "__main__":
print("Player 2 scored "+str(points_2)+" points") print("Player 2 scored "+str(points_2)+" points")
if points_1 > points_2: if points_1 > points_2:
print("Player 1 won!") print("Player 1 won!")
elif points_2 > points_2: elif points_2 > points_1:
print("Player 2 won!") print("Player 2 won!")
else: else:
print("Draw!") print("Draw!")