如果这不容易理解,我道歉。我正在努力完善我的问题以及我的Python技能。感谢大家的帮助。
由用户输入选择具有动态大小变化的tic tac toe游戏
。
我的问题是,如何使顶部的行列引用数字动态化。现在它们是静态的。
以下代码是我需要帮助的地方:
for count, row in enumerate(game_map):
在此行代码中的"for count,row In enumerate(game_map)“列中,我如何添加?
或者我需要在代码块中编写不同的代码行吗?
Bellow是游戏板的代码块和子句:
def game_board(game_map, player=0, row=0, column=0, just_display=False):
try:
if game_map[row][column] != 0: #Done
print("This spot taken try again.") #Done
return game_map, False #Done
print(" 0 1 2")
if not just_display:
game_map[row][column] = player
for count, row in enumerate(game_map):
print(count, row)
return game_map, True
这就是我对此输出所做的工作
try:
if game_map[row][column] != 0: #Done
print("This spot taken try again.") #Done
return game_map, False #Done
#print(" 0 1 2")
if not just_display:
game_map[row][column] = player
for count, row, column, in enumerate(game_map):
print(count, row)
return game_map, True
发布于 2020-05-18 06:05:11
用print(" " + " ".join(map(str, range(len(game_map)))))
替换print(" 0 1 2")
。这是取game_map
的长度,这是您想要的数字的数量,并在此基础上创建一个范围。然后使用map
将范围内的所有int
转换为str
,并用空格将它们连接在一起。然后在开头添加空格!
https://stackoverflow.com/questions/61861727
复制相似问题