Python 我已经建立了一个井字游戏,但有一个错误,没有办法验证一个球员是否赢了,然后打破循环

Python 我已经建立了一个井字游戏,但有一个错误,没有办法验证一个球员是否赢了,然后打破循环,python,python-3.x,tic-tac-toe,Python,Python 3.x,Tic Tac Toe,这是Tictatcoe游戏的代码,我有一个bug,玩家可以重写彼此的动作。我最终解决了这个问题,但另一个错误是,一旦玩家赢了,循环就不会中断。另外,如果有一个玩家获胜后,可以要求重播 一些琐碎的信息:currentField列表的每个子列表中的空格分别指的是游戏板的每一列。我无法告诉你如何验证一方是否获胜,如果你已经赢了,我假设你会赢,因为这不是你问题的主题 对于中断while循环的问题,可以使用中断,例如: def DrawField(field): for row in range(

这是Tictatcoe游戏的代码,我有一个bug,玩家可以重写彼此的动作。我最终解决了这个问题,但另一个错误是,一旦玩家赢了,循环就不会中断。另外,如果有一个玩家获胜后,可以要求重播
一些琐碎的信息:currentField列表的每个子列表中的空格分别指的是游戏板的每一列。

我无法告诉你如何验证一方是否获胜,如果你已经赢了,我假设你会赢,因为这不是你问题的主题

对于中断
while
循环的问题,可以使用
中断
,例如:

def DrawField(field):
    for row in range(5):  
        if row%2 == 0:
            practicalrow = int(row/2)
            for column in range(5): 
                if column%2 == 0:
                    practicalcolumn = int(column/2)
                    if column !=4:
                        print(field[practicalcolumn][practicalrow],end="")
                    else:
                        print(field[practicalcolumn][practicalrow])
                else:
                    print("|",end="")
        else:
            print("-----")

Player = 1
CurrentField = [[" ", " ", " "],[" ", " ", " "],[" ", " ", " "]]
print(CurrentField)
DrawField(CurrentField)
while(True):
    print("Players Turn:", Player)
    MoveRow = int(input("PLease enter the row\n"))
    MoveCol = int(input("PLeasae enter the column\n"))
    if Player == 1:
        if CurrentField[MoveCol][MoveRow] == " ":
            CurrentField[MoveCol][MoveRow] = "X"
            #make move for player 1
            Player = 2
        else:
            continue
    else:
        if CurrentField[MoveCol][MoveRow] == " ":
            CurrentField[MoveCol][MoveRow] = "O"
            #make move for player 2
            Player = 1
        else:
            continue

    DrawField(CurrentField)
if语句将是while循环中的第一个检查,它在开始时很重要,因为如果它是在结束时,回合将发生,并且检查上一回合的游戏是否结束只会发生


break
可用于
循环,而
可用于
循环,因为此时它只是在循环外断开

您应该在此处发布代码,这样我们就可以看到您目前拥有的代码。您需要添加一些代码,这样我们就可以看到如何帮助您解决问题
while True:
    if has_won == true:
        break

    ####other code