当前位置: 首页>>代码示例>>Python>>正文


Python Move.specialMovePiece方法代码示例

本文整理汇总了Python中Move.Move.specialMovePiece方法的典型用法代码示例。如果您正苦于以下问题:Python Move.specialMovePiece方法的具体用法?Python Move.specialMovePiece怎么用?Python Move.specialMovePiece使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Move.Move的用法示例。


在下文中一共展示了Move.specialMovePiece方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getPossibleMoves

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import specialMovePiece [as 别名]
    def getPossibleMoves(self):
        currentPos = self.position
        movements = [C(0, 1), C(0, -1), C(1, 0), C(-1, 0), C(1, 1), C(1, -1), C(-1, 1), C(-1, -1)]
        for movement in movements:
            newPos = currentPos + movement
            if self.board.isValidPos(newPos):
                pieceAtNewPos = self.board.pieceAtPosition(newPos)
                if self.board.pieceAtPosition(newPos) is None:
                    yield Move(self, newPos)
                elif pieceAtNewPos.side != self.side:
                    yield Move(self, newPos, pieceToCapture=pieceAtNewPos)

        # Castling
        if self.movesMade == 0:
            inCheck = False
            kingsideCastleBlocked = False
            queensideCastleBlocked = False
            kingsideCastleCheck = False
            queensideCastleCheck = False
            kingsideRookMoved = True
            queensideRookMoved = True

            kingsideCastlePositions = [self.position + C(1, 0), self.position + C(2, 0)]
            for pos in kingsideCastlePositions:
                if self.board.pieceAtPosition(pos):
                    kingsideCastleBlocked = True

            queensideCastlePositions = [self.position - C(1, 0), self.position - C(2, 0), self.position - C(3, 0)]
            for pos in queensideCastlePositions:
                if self.board.pieceAtPosition(pos):
                    queensideCastleBlocked = True

            if kingsideCastleBlocked and queensideCastleBlocked:
                return

            otherSideMoves = self.board.getAllMovesUnfiltered(not self.side, includeKing=False)
            for move in otherSideMoves:
                if move.newPos == self.position:
                    inCheck = True
                    break
                if move.newPos == self.position + C(1, 0) or move.newPos == self.position + C(2, 0):
                    kingsideCastleCheck = True
                if move.newPos == self.position - C(1, 0) or move.newPos == self.position - C(2, 0):
                    queensideCastleCheck = True

            kingsideRookPos = self.position + C(3, 0)
            kingsideRook = self.board.pieceAtPosition(kingsideRookPos) if self.board.isValidPos(kingsideRookPos) else None
            if kingsideRook and kingsideRook.stringRep == 'R' and kingsideRook.movesMade == 0:
                kingsideRookMoved = False

            queensideRookPos = self.position - C(4, 0)
            queensideRook = self.board.pieceAtPosition(queensideRookPos) if self.board.isValidPos(queensideRookPos) else None
            if queensideRook and queensideRook.stringRep == 'R' and queensideRook.movesMade == 0:
                queensideRookMoved = False

            if not inCheck:
                if not kingsideCastleBlocked and not kingsideCastleCheck and not kingsideRookMoved:
                    move = Move(self, self.position + C(2, 0))
                    rookMove = Move(self.position, self.position + C(1, 0))
                    move.specialMovePiece = self.board.pieceAtPosition(kingsideRookPos)
                    move.kingsideCastle = True
                    move.rookMove = rookMove
                    yield move
                if not queensideCastleBlocked and not queensideCastleCheck and not queensideRookMoved:
                    move = Move(self, self.position - C(2, 0))
                    rookMove = Move(self.position, self.position - C(1, 0))
                    move.specialMovePiece = self.board.pieceAtPosition(queensideRookPos)
                    move.queensideCastle = True
                    move.rookMove = rookMove
                    yield move
开发者ID:Daniel-NJ,项目名称:command-line-chess,代码行数:72,代码来源:King.py

示例2: getPossibleMoves

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import specialMovePiece [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
#.........这里部分代码省略.........
开发者ID:DerekDY,项目名称:THE-KNIGHT,代码行数:103,代码来源:Pawn.py

示例3: get_possible_moves

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import specialMovePiece [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
开发者ID:ArthurChiao,项目名称:code-snippets,代码行数:87,代码来源:Pawn.py

示例4: getPossibleMoves

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import specialMovePiece [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
开发者ID:AndersJing,项目名称:command-line-chess,代码行数:70,代码来源:Pawn.py


注:本文中的Move.Move.specialMovePiece方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。