1
0
Fork 0
mirror of https://gitlab.com/oloturia/damastodon.git synced 2025-01-08 22:47:14 +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,34 +39,26 @@ 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: player = board[row][col]
count = 0 offX = 0
count += checkSide(board,row,col,offset[0]) offY = 0
count += checkSide(board,row,col,offset[1]) #TODO
if count >= 4:
points += 1
return points return points
def checkPly(board,row,col,player):
def checkSide(board,row,col,incs): if row < 0 or col < 0:
incY,incX = incs return False
count = 0 try:
player = board[row][col] if board[row][col] == player:
offsetX = 0 return True
offsetY = 0 else:
while count < 4: return False
try: except IndexError:
if board[row+offsetX][col+offsetY] == player: return False
count += 1
offsetX += incX
offsetY += incY
else:
break
except IndexError:
break
return count
if __name__ == "__main__": if __name__ == "__main__":
@ -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!")