本文整理汇总了Python中Move.Move.pessant方法的典型用法代码示例。如果您正苦于以下问题:Python Move.pessant方法的具体用法?Python Move.pessant怎么用?Python Move.pessant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Move.Move
的用法示例。
在下文中一共展示了Move.pessant方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getPossibleMoves
# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import pessant [as 别名]
def getPossibleMoves(self):
currentPosition = self.position
# Pawn moves one up
movement = C(0, 1) if self.side == WHITE else C(0, -1)
advanceOnePosition = currentPosition + movement
if self.board.isValidPos(advanceOnePosition):
#Check if piece at position to move to
if self.board.pieceAtPosition(advanceOnePosition) is None:
col = advanceOnePosition[1]
if col == 7 or col == 0:
#print("promotion is happening without a capture")
'''
piecesForPromotion = \
[Rook(self.board, self.side, advanceOnePosition, self.number), #added self.number to these
Knight(self.board, self.side, advanceOnePosition, self.number),
Bishop(self.board, self.side, advanceOnePosition, self.number),
Queen(self.board, self.side, advanceOnePosition, self.number)]
for piece in piecesForPromotion:
'''
move = Move(self, advanceOnePosition)
move.promotion = True
move.specialMovePiece = Queen(self.board, self.side, advanceOnePosition, self.number)
#print(move.specialMovePiece)
#print(move)
yield (move)
else:
yield (Move(self, advanceOnePosition))
# Pawn moves two up
if self.movesMade == 0:
movement = C(0, 2) if self.side == WHITE else C(0, -2)
advanceTwoPosition = currentPosition + movement
if self.board.isValidPos(advanceTwoPosition):
if self.board.pieceAtPosition(advanceTwoPosition) is None and \
self.board.pieceAtPosition(advanceOnePosition) is None:
yield Move(self, advanceTwoPosition)
# Pawn takes
movements = [C(1, 1), C(-1, 1)] \
if self.side == WHITE else [C(1, -1), C(-1, -1)]
# Pawn captures another piece
for m in movements:
newPosition = self.position + m
if self.board.isValidPos(newPosition):
pieceToTake = self.board.pieceAtPosition(newPosition)
if pieceToTake and pieceToTake.side != self.side:
col = newPosition[1]
#print("Piece for pawn to take: ")
#print(pieceToTake)
#print(pieceToTake.board)
# Promotion with a capture
if col == 7 or col == 0:
#print("promotion is happening with capture")
'''
piecesForPromotion = \
[Knight(self.board, self.side, newPosition, self.number),
Rook(self.board, self.side, newPosition, self.number),
Bishop(self.board, self.side, newPosition, self.number),
Queen(self.board, self.side, newPosition, self.number)]
for piece in piecesForPromotion:
'''
move = Move(self, newPosition, pieceToCapture=pieceToTake)
move.promotion = True
move.specialMovePiece = Queen(self.board, self.side, newPosition, self.number)
#print("reset special move piece")
#print(move.specialMovePiece)
#print(move)
yield (move)
else:
yield (Move(self, newPosition,
pieceToCapture=pieceToTake))
# En pessant
movements = [C(1, 1), C(-1, 1)] \
if self.side == WHITE else [C(1, -1), C(-1, -1)]
for movement in movements:
posBesidePawn = self.position + C(movement[0], 0)
if self.board.isValidPos(posBesidePawn):
pieceBesidePawn = self.board.pieceAtPosition(posBesidePawn)
lastPieceMoved = self.board.getLastPieceMoved()
lastMoveWasAdvanceTwo = False
lastMove = self.board.getLastMove()
if lastMove:
if lastMove.newPos - lastMove.oldPos == C(0, 2) or \
lastMove.newPos - lastMove.oldPos == C(0, -2):
lastMoveWasAdvanceTwo = True
if pieceBesidePawn and \
pieceBesidePawn.stringRep == 'p' and \
pieceBesidePawn.side != self.side and \
lastPieceMoved is pieceBesidePawn and \
lastMoveWasAdvanceTwo:
move = Move(self, self.position + movement,
pieceToCapture=pieceBesidePawn)
move.pessant = True
move.specialMovePiece = pieceBesidePawn
#.........这里部分代码省略.........
示例2: get_possible_moves
# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import pessant [as 别名]
def get_possible_moves(self):
pos = self.position
# Pawn moves one up
movement = C(0, 1) if self.side == WHITE else C(0, -1)
up_pos = pos + movement
if self.board.is_valid_pos(up_pos):
# Promotion moves
if self.board.get_piece_at_pos(up_pos) is None:
col = up_pos[1]
if col == 7 or col == 0:
piecesForPromotion = \
[Rook(self.board, self.side, up_pos),
Knight(self.board, self.side, up_pos),
Bishop(self.board, self.side, up_pos),
Queen(self.board, self.side, up_pos)]
for piece in piecesForPromotion:
move = Move(self, up_pos)
move.promotion = True
move.specialMovePiece = piece
yield move
else:
yield Move(self, up_pos)
# Pawn moves two up
if self.movesMade == 0:
movement = C(0, 2) if self.side == WHITE else C(0, -2)
up2_pos = pos + movement
if self.board.is_valid_pos(up2_pos):
if self.board.get_piece_at_pos(up2_pos) is None and \
self.board.get_piece_at_pos(up_pos) is None:
yield Move(self, up2_pos)
# Pawn takes
movements = [C(1, 1), C(-1, 1)] \
if self.side == WHITE else [C(1, -1), C(-1, -1)]
for movement in movements:
new_pos = self.position + movement
if self.board.is_valid_pos(new_pos):
pieceToTake = self.board.get_piece_at_pos(new_pos)
if pieceToTake and pieceToTake.side != self.side:
col = new_pos[1]
# Promotions
if col == 7 or col == 0:
piecesForPromotion = \
[Rook(self.board, self.side, new_pos),
Knight(self.board, self.side, new_pos),
Bishop(self.board, self.side, new_pos),
Queen(self.board, self.side, new_pos)]
for piece in piecesForPromotion:
move = Move(self, up_pos)
move.promotion = True
move.specialMovePiece = piece
yield move
else:
yield Move(self, new_pos,
piece_to_capture=pieceToTake)
# En pessant
movements = [C(1, 1), C(-1, 1)] \
if self.side == WHITE else [C(1, -1), C(-1, -1)]
for movement in movements:
posBesidePawn = self.position + C(movement[0], 0)
if self.board.is_valid_pos(posBesidePawn):
pieceBesidePawn = self.board.get_piece_at_pos(posBesidePawn)
lastPieceMoved = self.board.getLastPieceMoved()
lastMoveWasAdvanceTwo = False
lastMove = self.board.getLastMove()
if lastMove:
if lastMove.new_pos - lastMove.old_pos == C(0, 2) or \
lastMove.new_pos - lastMove.old_pos == C(0, -2):
lastMoveWasAdvanceTwo = True
if pieceBesidePawn and \
pieceBesidePawn.stringRep == 'p' and \
pieceBesidePawn.side != self.side and \
lastPieceMoved is pieceBesidePawn and \
lastMoveWasAdvanceTwo:
move = Move(self, self.position + movement,
piece_to_capture=pieceBesidePawn)
move.pessant = True
move.specialMovePiece = pieceBesidePawn
yield move
示例3: getPossibleMoves
# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import pessant [as 别名]
def getPossibleMoves(self) :
currentPosition = self.position
# Pawn moves one up
movement = C(0, 1) if self.side == WHITE else C(0, -1)
advanceOnePosition = currentPosition + movement
if self.board.isValidPos(advanceOnePosition) :
#Promotion moves
if self.board.pieceAtPosition(advanceOnePosition) is None :
col = advanceOnePosition[1]
if col == 7 or col == 0:
piecesForPromotion = [Rook(self.board, self.side, advanceOnePosition), Knight(self.board, self.side, advanceOnePosition), Bishop(self.board, self.side, advanceOnePosition), Queen(self.board, self.side, advanceOnePosition)]
for piece in piecesForPromotion :
move = Move(self, advanceOnePosition)
move.promotion = True
move.specialMovePiece = piece
yield move
else :
yield Move(self, advanceOnePosition)
#Pawn moves two up
if self.movesMade == 0 :
movement = C(0, 2) if self.side == WHITE else C(0, -2)
advanceTwoPosition = currentPosition + movement
if self.board.isValidPos(advanceTwoPosition) :
if self.board.pieceAtPosition(advanceTwoPosition) is None and self.board.pieceAtPosition(advanceOnePosition) is None:
yield Move(self, advanceTwoPosition)
#Pawn takes
movements = [C(1,1), C(-1,1)] if self.side == WHITE else [C(1,-1), C(-1,-1)]
for movement in movements :
newPosition = self.position + movement
if self.board.isValidPos(newPosition) :
pieceToTake = self.board.pieceAtPosition(newPosition)
if pieceToTake and pieceToTake.side != self.side :
col = newPosition[1]
#Promotions
if col == 7 or col == 0:
piecesForPromotion = [Rook(self.board, self.side, newPosition), Knight(self.board, self.side, newPosition), Bishop(self.board, self.side, newPosition), Queen(self.board, self.side, newPosition)]
for piece in piecesForPromotion :
move = Move(self, advanceOnePosition)
move.promotion = True
move.specialMovePiece = piece
yield move
else :
yield Move(self, newPosition, pieceToCapture = pieceToTake)
#En pessant
movements = [C(1,1), C(-1,1)] if self.side == WHITE else [C(1,-1), C(-1,-1)]
for movement in movements :
posBesidePawn = self.position + C(movement[0], 0)
if self.board.isValidPos(posBesidePawn) :
pieceBesidePawn = self.board.pieceAtPosition(posBesidePawn)
lastPieceMoved = self.board.getLastPieceMoved()
lastMoveWasAdvanceTwo = False
lastMove = self.board.getLastMove()
if lastMove :
if lastMove.newPos - lastMove.oldPos == C(0,2) or lastMove.newPos - lastMove.oldPos == C(0,-2) :
lastMoveWasAdvanceTwo = True
if pieceBesidePawn and pieceBesidePawn.stringRep == 'p' and pieceBesidePawn.side != self.side and lastPieceMoved is pieceBesidePawn and lastMoveWasAdvanceTwo:
move = Move(self, self.position + movement, pieceToCapture = pieceBesidePawn)
move.pessant = True
move.specialMovePiece = pieceBesidePawn
yield move