我创建一个井字游戏。我有一个功能,将取代由用户选择的主板的一部分,然后电脑会做出一出戏。功能被建立以插入两个参数(user_choices和computer_choices)。然而,第一轮结束之后,我需要的功能,能够利用多种选择在user_choices和computer_choices。
我想用一个列表可以解决这个问题,但我想参数不能拿列出的数据。
我是很新的编码,所以我可能失去了一些东西完全明显。有什么想法吗?
def making_new_board(user_choices, computer_choices):
new_board = ""
for character in board:
if character == user_choices:
new_board += user_symbol
elif character == computer_choices:
new_board += computer_symbol
else:
new_board += character
time.sleep(1)
print(new_board)
相反,做这样的我建议你使用一个3x3格
board = []
for i in range(3):
board.append([""], [""], [""]) # This will create a board of 3 by 3
您可以使用该打印
for i in board:
print(i)
要在板编辑特定的一块,你可以使用这个
board[y][x] = "O"
注:Y值从顶部进入底部,而不是底部到顶部。