python - 跳棋1V1,不能移动
问题描述
我正在写一个关于跳棋的项目(1V1)。当我试图移动士兵时,它打印相同的板,我做错了什么?谢谢
示例:我正在尝试从 2X3 移动到 3X4
rows = 8
cols = 8
board = [['B', '-', 'B', '-', 'B', '-', 'B', '-'], ['-', 'B', '-', 'B', '-', 'B', '-', 'B'],
['B', '-', 'B', '-', 'B', '-', 'B', '-'], ['-', '-', '-', '-', '-', '-', '-', '-'],
['-', '-', '-', '-', '-', '-', '-', '-'], ['-', 'w', '-', 'w', '-', 'w', '-', 'w'],
['w', '-', 'w', '-', 'w', '-', 'w', '-'], ['-', 'w', '-', 'w', '-', 'w', '-', 'w']]
def create_game_board(): ##### this function create the game board#####
for i in range(rows):
list = []
for j in range(cols):
list.append(" ")
board.append(list)
return board
validTurn = True
def valid_Move_position(board):
currentRowCube = input("what is the row of the player that you want to move? ")
currentColCube = input("what is the col of the player that you want to move? ")
targetRowCube = input("which cube do you want to move to? ")
targetColCube = input("which cube do you want to move to? ")
#def move(,targetColCube, targetRowCube ):
#if (targetRowCube, targetColCube =="-"):
#currentRowCube = "B"
#currentColCube = "B"
def print_board(board): #####This function is drawing the board#####
print(" 0 1 2 3 4 5 6 7 ")
print(" A B C D E F G H ")
for i in range(cols):
print(i, " |", end="")
for j in range(rows):
current_cell = board[i][j]
print(current_cell + "|", end="")
print("")
解决方案
您的功能create_game_board
出现故障。如果您的目标是创建默认板的副本,那么您可以使用单行。相反,您的函数会将 8x8 空格列表附加到默认板,因此对其进行修改。
我建议你试试这个:
def create_game_board():
return [[v for v in line] for line in board]
推荐阅读
- c# - 将复杂的源扁平化到目标时如何重用现有的映射配置?
- php - 从 Woocommerce 中删除数量字段,而不阻止添加多个购物车?
- c++ - sizeof unsigned char,将 std::string 转换为 unsigned char
- azure - 默认情况下,Azure 子网中的 VM 之间的所有端口是否都打开
- sql - 在 T-SQL 中解析对象内的 JSON 数组
- django - Django AJAX删除deleteView中的对象
- wordpress - Wordpress /Cloudflare(完整 SSL)的这个 GTmetrix SSL 错误是什么意思?
- laravel - 如何解决 Laravel6 中的控制器错误?
- vba - 通过 VBA 检查文件是否存在于 OneDrive 中
- python - 如何在 django 中获取 updateview 的 url 参数?