如何将棋子放入Python棋盘网格中?
我是一名正在从事大学项目的初学者,我需要制作一个在 python 控制台中运行的国际象棋游戏(不能使用国际象棋导入),我刚刚完成了棋盘,但现在我不知道如何将棋子放入,有人可以帮忙吗?(它们可以用 Pawn=P 等字母表示)
这就是我到目前为止所做的
def create_grid():
""" Creates the grid return=an array that represents the grid """
tab = []
for i in range(GRID_SIZE - 1):
tab.append([])
for j in range(GRID_SIZE):
tab[i].append('')
return tab
def print_grid(tab):
""" prints the grid """
print( ' 1','2','3','4','5','6','7','8')
for i in range(GRID_SIZE - 1):
print("{} ".format(i+1), end="")
for j in range(GRID_SIZE):
print(" {}".format(tab[i][j]), end="")
if j < GRID_SIZE:
print("|", end="")
if i < GRID_SIZE:
print()
print_grid(create_grid)
I am a begginer working on a college project and i need to make a chess game that works in the python console(can´t use the chess import), i just completed the board but now i have no idea how to put the pieces in,can someone help?(they can be represented by letters like Pawn=P )
this is what i did so far
def create_grid():
""" Creates the grid return=an array that represents the grid """
tab = []
for i in range(GRID_SIZE - 1):
tab.append([])
for j in range(GRID_SIZE):
tab[i].append('')
return tab
def print_grid(tab):
""" prints the grid """
print( ' 1','2','3','4','5','6','7','8')
for i in range(GRID_SIZE - 1):
print("{} ".format(i+1), end="")
for j in range(GRID_SIZE):
print(" {}".format(tab[i][j]), end="")
if j < GRID_SIZE:
print("|", end="")
if i < GRID_SIZE:
print()
print_grid(create_grid)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下并根据需要进行改进。我考虑了 @GC 的评论来打印 unicodes。
它会打印出这样的东西
Try this and improve as needed. I considered @G.C's comment to print unicodes.
It will print something like this