1 回答
TA贡献1744条经验 获得超4个赞
好的,您的代码中有一些错误。
1.) 在valid_location函数中,0即使您将其指定为"O"
2.) 在print_board您每次制作新板的功能中。
3.) 在drop_point函数中,你只是board在函数内部赋值
这是一些新的和改进的代码:
print("This is Gomoku Deluxe!")
#starting off with tic-tac-toe
import os
#this is where the code for the game starts
board = []
for i in range(19):
board.append([0] * 19)
#function to print board
def print_board(brd):
for row in brd:
print (row)
#function to place player piece
def drop_point(brd, row, col, piece):
brd[row][col] = piece
return brd
#function checks for empty spot
def valid_location(board, row, col):
return board[row][col] == 0
# this loop handles user's piece
print_board(board)
turn = 0
game_over = False
while not game_over:
if turn == 0:
row = int(input("Player 1 Select a row: "))
col = int(input("Player 1 Select a col: "))
if valid_location(board, row, col):
board = drop_point(board, row, col, 1)
else:
row1 = int(input("Player 2 Select a row: "))
col1 = int(input("Player 2 Select a col: "))
if valid_location(board, row1, col1):
board = drop_point(board, row1, col1, 2)
print_board(board)
turn += 1
turn = turn % 2
添加回答
举报