本文整理汇总了Python中action.Action.promotion方法的典型用法代码示例。如果您正苦于以下问题:Python Action.promotion方法的具体用法?Python Action.promotion怎么用?Python Action.promotion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类action.Action
的用法示例。
在下文中一共展示了Action.promotion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validMoves
# 需要导入模块: from action import Action [as 别名]
# 或者: from action.Action import promotion [as 别名]
def validMoves(self, config):
valid_moves = []
x,y = self.pos
self.player_pieces_pos = config.getPlayerPositions(self.color)
self.enemy_pieces_pos = config.getEnemyPositions(self.color)
self.enemy_pieces = config.getEnemyPieces(self.color)
if self.color == "White":
# moving pawn one tile in front
if util.isNotOutofBounds(x,y+1) and (x,y+1) not in self.player_pieces_pos+self.enemy_pieces_pos:
valid_moves.append((x,y+1))
# moving pawn two tiles in front
if y == 1 and (x,y+1) not in self.player_pieces_pos+self.enemy_pieces_pos and (x,y+2) not in self.player_pieces_pos+self.enemy_pieces_pos:
valid_moves.append((x,y+2))
# Attacking diagonally 1 -> Normal Attack
if util.isNotOutofBounds((x+1), (y+1)) and ((x+1), (y+1)) in self.enemy_pieces_pos:
valid_moves.append((x+1,y+1))
if util.isNotOutofBounds((x-1), (y+1)) and ((x-1), (y+1)) in self.enemy_pieces_pos:
valid_moves.append((x-1, y+1))
# Attacking diagonally 2 -> en passant
if util.isNotOutofBounds((x+1),y) and ((x+1),y) in self.enemy_pieces_pos:
index = util.getIndexof(self.enemy_pieces_pos, (x+1,y))
enemyPiece = self.enemy_pieces[index]
if enemyPiece.toString() == "P" and abs(enemyPiece.lastpos[1] - enemyPiece.pos[1]) == 2:
valid_moves.append((x+1,y+1))
if util.isNotOutofBounds((x-1),y) and ((x-1),y) in self.enemy_pieces_pos:
index = util.getIndexof(self.enemy_pieces_pos, (x-1,y))
enemyPiece = self.enemy_pieces[index]
if enemyPiece.toString() == "P" and abs(enemyPiece.lastpos[1] - enemyPiece.pos[1]) == 2:
valid_moves.append((x-1,y+1))
else:
# moving pawn one tile in front
if util.isNotOutofBounds(x,y-1) and (x,y-1) not in self.player_pieces_pos+self.enemy_pieces_pos:
valid_moves.append((x,y-1))
# moving pawn two tiles in front
if y == 6 and (x,y-1) not in self.player_pieces_pos+self.enemy_pieces_pos and (x,y-2) not in self.player_pieces_pos+self.enemy_pieces_pos:
valid_moves.append((x,y-2))
# Attacking diagonally 1 -> Normal Attack
if util.isNotOutofBounds((x-1), (y-1)) and ((x-1), (y-1)) in self.enemy_pieces_pos:
valid_moves.append((x-1,y-1))
if util.isNotOutofBounds((x+1), (y-1)) and ((x+1), (y-1)) in self.enemy_pieces_pos:
valid_moves.append((x+1, y-1))
# Attacking diagonally 2 -> en passant
if util.isNotOutofBounds((x+1),y) and ((x+1),y) in self.enemy_pieces_pos:
index = util.getIndexof(self.enemy_pieces_pos, (x+1,y))
enemyPiece = self.enemy_pieces[index]
if enemyPiece.toString() == "P" and abs(enemyPiece.lastpos[1] - enemyPiece.pos[1]) == 2:
valid_moves.append((x+1,y-1))
if util.isNotOutofBounds((x-1),y) and ((x-1),y) in self.enemy_pieces_pos:
index = util.getIndexof(self.enemy_pieces_pos, (x-1,y))
enemyPiece = self.enemy_pieces[index]
if enemyPiece.toString() == "P" and abs(enemyPiece.lastpos[1] - enemyPiece.pos[1]) == 2:
valid_moves.append((x-1,y-1))
for (newx,newy) in valid_moves:
# Check for collisions
action = Action(self, (newx,newy), config)
if not action.isValid(): valid_moves.remove((newx,newy))
# Pawn Promotion?
if newy == 7 or newy == 0:
action.promotion = True
return valid_moves