我开始为python编写命令行象棋。我成功地创建了这样一个表:
def setup_grid():
grid = [[' ' for i in range(gridsize)] for i in range(gridsize)] # Creates a grid of 0 of the size set by user
return(grid)
# Displaying the grid to the user
def show_grid(grid):
gridsize = len(grid)
horizontal = ' '+4*gridsize*'-'+'-' # This prints the horizontal borders of the grid
#####################################################
toplabel = ' ' #
for i in string.ascii_lowercase[:gridsize]: # This creates the letters according
toplabel = toplabel+i+' ' # to how big the grid is. This prints the top letters
print '\n'+toplabel+'\n'+horizontal #
#####################################################
#########################################
for idx,i in enumerate(grid): #
row = '{0:2} |'.format(idx+1) #
for j in i: # This creates the numbers
row = row+' '+j+' |' # for the left side of the grid
print row+'\n'+horizontal #
print '' #
#########################################
def play_game():
gridsize = 8
currgrid = [[' ' for i in range(gridsize)] for i in range(gridsize)]
show_grid(currgrid)
grid = []
play_game()
现在我正在努力为白皇后定义wq
这样的作品。
玩家选择移动哪一个棋子的方法是在网格上选择坐标,然后输入新的坐标移动棋子。我不知道的是如何确保零件按要求移动。我不知道怎样才能证实他们的行动。你知道吗
移动验证有点复杂,但是,下面是一个如何验证女王的移动的可能性。首先,您可能希望将游戏布局移动到一个类中,以便更简单地访问棋盘和棋子。然后,创建一个方法来移动一个工件。方法可以由装饰器包装,装饰器将验证传递给方法的坐标:
因此,你还有两件事要做:
创建一个
staticmethod
的完整列表,以获得板上所有工件的完整移动。在
wrapper
中建立methods
字典来存储move finder函数对象。相关问题 更多 >
编程相关推荐