我是python的新手。我正在制作一个类似于井字棋的游戏,但规模更大。我能够在用户输入之前看到网格,但是在用户输入他们希望他们的作品去哪里之后,更新的网格不会显示。输出只会说没有。我认为我的问题在于我如何显示板,但我不确定。请帮忙
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(["O"] * 19)
#function to print board
def print_board():
board = []
for i in range(19):
board.append(["O"] * 19)
for row in board:
print (row)
#function to place player piece
def drop_point(board, row, col, piece):
board[row][col] = piece
#function checks for empty spot
def valid_location(board, row, col):
return board[row][col] == 0
# this loop handles user's piece
print_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):
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):
drop_point(board, row1, col1, 2)
print_board()
turn += 1
turn = turn % 2
慕无忌1623718
相关分类