您好我一直在弄清楚这段代码有什么问题。我正在尝试制作一个Tic-Tac-Toe游戏,你可以选择广场的大小,但每次我尝试游戏都会在我选择的列中放一个x。代码的某些部分已被删除,因为我已经检查它们是否已经存在问题,因此在代码的开头可能会有一些无用的变量。
编辑:变量在完整代码中实际上没用,但它们位于有问题的块中
x=int(input('How big would you like the square to be (eg if you put 4 the board will be 4X4)? '))-1
fboard=[]
for counter in range(x+1):
fboard.append('-')
board=[]
for counter in range(x+1):
board.append(fboard)
print('Welcome to Gay Als SUPER noughts and crosses adventure!')
gameOver=False
Player=1
gameOverValidation=0
while gameOver==False:
Row=False
Column=False
valid=False
if Player%2!=0:
currentPlayer='x'
else:
currentPlayer='o'
print('Player',currentPlayer,'Is up next')
for row in range(x+1):
for column in range(x+1):
print(board[row][column],end=' ')
print()
while valid==False:
Row=False
while Row==False:
newRow=int(input('Which row would YOU like to put your piece in ,darling? '))
if newRow>(x+1) or newRow<1:
print ("Invalid value. mmmmaybe come to GAY AL's cove of WONDERS!")
else:
Row=True
Column=False
while Column==False:
newColumn=int(input('Mmmkay, interesting. The column por favor? '))
if newColumn>(x+1) or newColumn<1:
print('GOD DAMN STUPID **** **** ***** **** **** THAT IS NOT VALID!')
else:
Column=True
if board[newRow-1][newColumn-1]!='-':
print('Umm, that space is taken already, babe.')
else:
valid=True
board[newRow-1][newColumn-1]=currentPlayer
(然后有循环来判断游戏是否已经赢了)
Player+=1