# 当我尝试在Python中运行tictactoe游戏时，它不是在检查玩家是否赢了。有人可以帮我吗？ [关闭]

``````gamestillgoing=True
gameover=False
if gamestillgoing and not gameover:

board = ["#", "-", "-", "-","-", "-", "-", "-", "-", "-"]
turn = input("Choose your turn X or O?\n")
def displayboard():
print(board[1] + "|" + board[2] + "|" + board[3])
print(board[4] + "|" + board[5] + "|" + board[6])
print(board[7] + "|" + board[8] + "|" + board[9])
displayboard()

def spacecheck(board,position):
board[position]=" "

def fullboardcheck():
for i in range(1,0):
if spacecheck(board,i):
print("The board is full!")
gameover=False
gamestillgoing=True

def checkwinrow():
row1 = board[1] == board[2] == board[3]
row2 = board[4] == board[5] == board[6]
row3 = board[7] == board[8] == board[9]
if row1!="-"and row1=="X"or row2!="-"and row2=="X"or row3!="-"and row3=="X":
print("Player X has won!\n ")
gameover=False
elif  row1!="-"and row1=="O"or row2!="-"and row2=="O"or row3!="-"and row3=="O":
print("Player O has won!\n ")
gameover=False
else:
gamestillgoing=True
checkwinrow()

def checkwincolumn():
column1 = board[1] == board[4] == board[7]
column2 = board[2] == board[5] == board[8]
column3 = board[3] == board[6] == board[9]
if column1!="-"and column1=="X"or column2!="-" and column2=="X"or column3!="-"and column3=="X":
print("Player X has won!\n")
gameover = False
elif column1!="-"and column1=="O"or column2!="-" and column2=="O"or column3!="-"and column3=="O":
print("Player O has won!\n")
gameover = False
else:
gamestillgoing=True
checkwincolumn()

def checkwindiagonal():
diagonal1 = board[1] == board[5] == board[9]
diagonal2 = board[3] == board[5] == board[7]

if (diagonal1!="-"and diagonal1=="X")or (diagonal2!="-"and diagonal2=="X"):
print("Player X has won!\n")
gameover=False

elif diagonal1 != "-" and diagonal1 == "X" or diagonal2 != "-" and diagonal2 == "X":
print("Player O has won!\n")
gameover=False

else:
gamestillgoing=True
checkwindiagonal()

def checkwinner():
checkwinrow()
checkwincolumn()
checkwindiagonal()
checkwinner()

def gameend():
checkwinner()
fullboardcheck()
gameend()

def choosepositionO():
print("Now turn goes to player O!\n")
range = [1,2,3,4,5,6,7,8,9]
position = input("Choose the position from 1-9\n")
position=int(position)
while position not in range:
position=int(input("Choose the valid input.\n"))
if board[position]=="-":
board[position] = "O"
gameend()
else:
while not board[position]=="-":
print("You can't go there!\n")
choosepositionO()
displayboard()
choosepositionX()

def choosepositionX():
print("Now turn goes to player X!\n")
range = [1,2,3,4,5,6,7,8,9]
position = input("Choose the position from 1-9\n")
position=int(position)
while position not in range:
position = int(input("Choose the valid input.\n"))
if board[position]=="-":
board[position] = "X"
gameend()
else:
while not board[position]=="-":
print("You can't go there!\n")
choosepositionX()
displayboard()
choosepositionO()

if turn=="X":
choosepositionX()
elif turn=="O":
choosepositionO()
else:
while turn!="X" and turn!="O":
print("Choose a valid input")
``````