这个井字游戏脚本有问题。由于某种原因,我的赢家'功能导致错误。但是我调整了胜利者函数,我在print语句后的行上出现语法错误。当我评论胜利者函数时,脚本按预期运行。我无法看到语法错误的位置。感谢。
def winner(board):
if board[0][0]==board[0][1]==board[0][2] or board[1][0]==board[1][1]==board[1][2] or board[2][0]==board[2][1]==board[2][2] or board[0][0]==board[1][0]==board[2][0] or board[0][1]==board[1][1]==board[2][1] or board[0][2]==board[1][2]==board[2][2] or board[0][0]==board[1][1]==board[2][[2] or board[0][2]==board[1][1]==board[2][0]:
print('Player {} wins!!!'.format(player))
return False
else:
return True
def move(coord, player):
marker = ' X '
if player == 2:
marker = ' O '
if coord == '0,0':
board[0][0] = marker
elif coord == '0,1':
board[0][1] = marker
elif coord == '0,2':
board[0][2] = marker
elif coord == '1,0':
board[1][0] = marker
elif coord == '1,1':
board[1][1] = marker
elif coord == '1,2':
board[1][2] = marker
elif coord == '2,0':
board[2][0] = marker
elif coord == '2,1':
board[2][1] = marker
elif coord == '2,2':
board[2][2] = marker
board = [[(0,0), (0,1), (0,2)],
[(1,0), (1,1), (1,2)],
[(2,0), (2,1), (2,2)]]
turn = 2
while True:
print('\n'.join(map(str, board)))
player = turn % 2 + 1
x = input('Player {}, where will you play? (i.e. 0,0 for upper left) '.format(player))
move(x,player)
winner(board)
turn += 1