예제 #1
0
        // Note that this doesn't check if a pawn can be taken en passant
        public bool IsAttacked(int defenderIx, Color defenderColor)
        {
            // check in roughly descending order of power

            // rook and queen
            var potentialRookCaptures = RookMoveTable.GetMoves(defenderIx, GetOccupied());

            if ((potentialRookCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Rook)) > 0)
            {
                return(true);
            }

            if ((potentialRookCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Queen)) > 0)
            {
                return(true);
            }

            // bishop and queen
            var potentialBishopCaptures = BishopMoveTable.GetMoves(defenderIx, GetOccupied());

            if ((potentialBishopCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Bishop)) > 0)
            {
                return(true);
            }

            if ((potentialBishopCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Queen)) > 0)
            {
                return(true);
            }

            var potentialKnightCaptures = KnightMoveTable.GetMoves(defenderIx);

            if ((potentialKnightCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Knight)) > 0)
            {
                return(true);
            }

            var potentialKingCaptures = KingMoveTable.GetMoves(defenderIx);

            if ((potentialKingCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.King)) > 0)
            {
                return(true);
            }

            var potentialPawnCaptures = PawnCaptureMoveTable.GetMoves(defenderIx, defenderColor);

            if ((potentialPawnCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Pawn)) > 0)
            {
                return(true);
            }

            // we checked all possible attacks by all possible piece types
            return(false);
        }
예제 #2
0
        private void GenerateKingNormalMoves(List <Move> moves, Position position, ulong sourceSquares)
        {
            while (Bits.TryPopLsb(ref sourceSquares, out var sourceIx))
            {
                var dstSquares = KingMoveTable.GetMoves(sourceIx);
                // don't allow king to move on piece of same color
                dstSquares &= ~position.GetOccupied(position.SideToMove);

                GenerateMoves(moves, MoveType.Normal, PieceType.King, sourceIx, dstSquares, position.GetOccupied());
            }
        }