0
我想創建一個連接四個遊戲,但我無法弄清楚如何在棋盤上打印跳棋。我需要它在用戶輸入的列中最低的可用點處打印X.每次我運行這個程序,我都會得到同樣的空白6乘7板。請幫忙。謝謝!Python連接4遊戲 - 在板上打印X
#ConnectFour
numRows=6
numCols=7
numPlayers=2
board=[]
checkers=['X','O']
turn=0
win = False
for row in range(numRows):
tempList=[]
for col in range(numCols):
tempList.append('.')
board.append(tempList)
while not win:
turn = (turn+1)%numPlayers
userCol = input ("Player"+str(turn+1)+"please enter your col: ")
while not userCol.isdigit() or not int(userCol) in range(numCols):
userCol = input ("Player"+str(turn+1)+"please enter your col: ")
for row in range(numRows):
for col in range(numCols):
print(board[row][col], end='')
print()
for repeat in range(numRows-2):
for row in range(numRows,-1,-1):
for col in range(numCols):
if board[row][int(userCol)]==".":
board[row+1][int(userCol)]="X"
print
break
#print board
for row in range(numRows):
for col in range(numCols):
print(board[row+1][userCol],end=' ')
print()
print ("Player", checkers[turn],"has won the game.")