问题描述
几天来我一直在寻找一个涉及我的黑卒的问题。我发现问题在于我的撤消键只是为了移动我的黑色棋子。我必须先移动3个白色棋子,然后撤消其中的2个,才能移动黑色棋子。我不确定我是否设置了错误的流程。在过去的几天里,我只是相信转弯系统才是问题所在。
转弯东西:
`self.whitetoMove = True
def getAllPossibleMoves(self):
moves = []
for r in range(len(self.board)): # number of rows
for c in range(len(self.board[r])): # number of cols in given row
turn = self.board[r][c][0]
if (turn == 'w' and self.whitetoMove) or (turn == 'b' and not self.whitetoMove):
piece = self.board[r][c][1]
self.moveFunctions[piece](r,c,moves)`
撤消操作:
elif e.type == p.KEYDOWN:
if e.key == p.K_u: # undo when 'u' is pressed
gs.undoMove()
moveMade = True
我不确定是否应该以这种方式设置pawn。
def getPawnMoves(self,r,moves):
if self.whitetoMove: # white pawn moves
if self.board[r-1][c] == "--": # 1 square pawn advance
moves.append(Move((r,c),(r-1,self.board))
if r == 6 and self.board[r-2][c] == "--": # 2 square pawn move
moves.append(Move((r,(r-2,self.board))
if c-1 >= 0: # capture to the left
if self.board[r-1][c-1][0] == 'b': # enemy piece to capture
moves.append(Move((r,c-1),self.board))
if c+1 <= 7: # capture to the right
if self.board[r-1][c+1][0] == 'b': # enemy piece to capture
moves.append(Move((r,c+1),self.board))
else: # black pawn moves
if self.board[r + 1][c] == "--": # 1 square move
moves.append(Move((r,(r + 1,self.board))
print("b")
if r == 1 and self.board[r + 2][c] == "--": # 2 square moves
moves.append(Move((r,(r + 2,self.board))
# captures
if c-1 >= 0: # capture to left
if self.board[r + 1][c - 1][0] == 'w':
moves.append(Move((r,c - 1),self.board))
if c+1 <= 7: # capture to right
if self.board[r + 1][c + 1][0] == 'w':
moves.append(Move((r,c + 1),self.board))
# add pawn promotions later
让我知道您是否希望我对此进行精简或更具体。我还是整个编程游戏的新手。这是我的第一个项目。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)