예제 #1
0
        private static bool isOwnKingAttackable(ChessBoard cb, ColoredBitBoard legalMove, ChessPieceColors color)
        {
            List <ColoredBitBoard> legalMoves  = new List <ColoredBitBoard>();
            EmptyBitBoard          blackPieces = new EmptyBitBoard();
            EmptyBitBoard          whitePieces = new EmptyBitBoard();
            EmptyBitBoard          allPieces   = new EmptyBitBoard();

            cb.Update(legalMove);

            blackPieces = MoveGenUtils.SetBlackBoard(cb);
            whitePieces = MoveGenUtils.SetWhiteBoard(cb);
            allPieces   = MoveGenUtils.SetWholeBoard(cb);

            legalMoves.AddRange(GeneratePseudoLegalNonSlidingMoves(cb, color, blackPieces, whitePieces, allPieces));
            legalMoves.AddRange(GeneratePseudoLegalSlidingMoves(cb, color, blackPieces, whitePieces, allPieces));

            foreach (ColoredBitBoard cbb in legalMoves)
            {
                if (color == ChessPieceColors.White && (cb.BlackKing.Bits & cbb.Bits) != 0)
                {
                    cb.Undo();
                    return(true);
                }
                else if (color == ChessPieceColors.Black && (cb.WhiteKing.Bits & cbb.Bits) != 0)
                {
                    cb.Undo();
                    return(true);
                }
            }

            cb.Undo();
            return(false);
        }
예제 #2
0
        private static bool isEnemyKingAttackable(ChessBoard cb, ColoredBitBoard legalMove, ChessPieceColors color)
        {
            List <ColoredBitBoard> legalMoves  = new List <ColoredBitBoard>();
            EmptyBitBoard          blackPieces = new EmptyBitBoard();
            EmptyBitBoard          whitePieces = new EmptyBitBoard();
            EmptyBitBoard          allPieces   = new EmptyBitBoard();

            cb.Update(legalMove);

            blackPieces = MoveGenUtils.SetBlackBoard(cb);
            whitePieces = MoveGenUtils.SetWhiteBoard(cb);
            allPieces   = MoveGenUtils.SetWholeBoard(cb);

            if (legalMove is PawnBitBoard)
            {
                legalMoves.AddRange(PawnMoveGen.PawnBitBoardResults(cb, color, blackPieces, whitePieces, allPieces));
            }
            else if (legalMove is BishopBitBoard)
            {
                legalMoves.AddRange(BishopMoveGen.BishopBitBoardResults(cb, color, blackPieces, whitePieces, allPieces));
            }
            else if (legalMove is KingBitBoard)
            {
                legalMoves.AddRange(KingMoveGen.KingBitBoardResults(cb, color, blackPieces, whitePieces, allPieces));
            }
            else if (legalMove is KnightBitBoard)
            {
                legalMoves.AddRange(KnightMoveGen.KnightBitBoardResults(cb, color, blackPieces, whitePieces, allPieces));
            }
            else if (legalMove is QueenBitBoard)
            {
                legalMoves.AddRange(QueenMoveGen.QueenBitBoardResults(cb, color, blackPieces, whitePieces, allPieces));
            }
            else if (legalMove is RookBitBoard)
            {
                legalMoves.AddRange(RookMoveGen.RookBitBoardResults(cb, color, blackPieces, whitePieces, allPieces));
            }

            foreach (ColoredBitBoard cbb in legalMoves)
            {
                if (color == ChessPieceColors.White && (cb.BlackKing.Bits & cbb.Bits) != 0)
                {
                    cb.Undo();
                    return(true);
                }
                else if (color == ChessPieceColors.Black && (cb.WhiteKing.Bits & cbb.Bits) != 0)
                {
                    cb.Undo();
                    return(true);
                }
            }

            cb.Undo();
            return(false);
        }
예제 #3
0
        public static List <ColoredBitBoard> GenerateLegalMoves(ChessBoard inputChessBoard, ChessPieceColors color)
        {
            List <ColoredBitBoard> result      = new List <ColoredBitBoard>();
            EmptyBitBoard          blackPieces = MoveGenUtils.SetBlackBoard(inputChessBoard);
            EmptyBitBoard          whitePieces = MoveGenUtils.SetWhiteBoard(inputChessBoard);
            EmptyBitBoard          allPieces   = MoveGenUtils.SetWholeBoard(inputChessBoard);

            result.AddRange(GeneratePseudoLegalNonSlidingMoves(inputChessBoard, color, blackPieces, whitePieces, allPieces));
            result.AddRange(GeneratePseudoLegalSlidingMoves(inputChessBoard, color, blackPieces, whitePieces, allPieces));

            result = RemoveOwnKingChecks(inputChessBoard, result, color);
            result = SetDoesCheck(inputChessBoard, result, color);

            var sortedMoves = MoveGenUtils.SortMoves(result, inputChessBoard, blackPieces, whitePieces);

            return(sortedMoves);
        }