我在使用 Python 进行的早期国际象棋游戏中为棋子生成有效棋子时遇到了问题……我遇到了 Bishop 的问题。这是我的程序的一瞥...选择了右下角的白色主教,红色方块代表有效的移动...很明显主要问题是什么。
如果有块,我希望我的程序停止添加更多潜在动作,
^^ 不重复;我咨询过其他来源
主教课程:
class Bishop(Piece):
def __init__(self, x, y, pl, im):
Piece.__init__(self, x, y, pl, im)
def findAvailableMoves(self):
for i in range(1, 8):
for (dx, dy) in [(i, i), (i, -i), (-i, i), (-i, -i)]:
if self.inBoundsPiece(self.cor.x + dx, self.cor.y + dy):
if board.board[self.cor.y + dy][self.cor.x + dx] == None:
self.potentialMoves.append((self.cor.y + dy, self.cor.x + dx))
class WBishop(Bishop):
def __init__(self, x, y):
Bishop.__init__(self, x, y, 1, wBishop)
class BBishop(Bishop):
def __init__(self, x, y):
Bishop.__init__(self, x, y, 2, bBishop)