コード例 #1
0
        public void GetAllPotentialMoves(Board board, Move[] moves, ref int moveCount, Bitboard checkers, Bitboard pinned)
        {
            var checkCount = checkers.PopCount();

            if (checkCount > 1)
            {
                GetPotentialKingMoves(board, moves, ref moveCount);
                return;
            }

            var allowedFrom = ~0UL;
            var allowedTo   = ~0UL;

            if (checkCount == 1)
            {
                allowedFrom = ~pinned;

                var checkerPos = checkers.BitScanForward();
                allowedTo = BitboardConstants.Between[board.KingPositions[board.ColorToMove]][checkerPos] | checkers;
            }
            else
            {
                GetPotentialCastlingMoves(board, moves, ref moveCount);
            }

            GetPotentialKnightMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialBishopMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialRookMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialQueenMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialKingMoves(board, moves, ref moveCount);

            if (board.WhiteToMove)
            {
                GetPotentialWhitePawnCaptures(board, allowedFrom, allowedTo, moves, ref moveCount);
                GetPotentialWhitePawnMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            }
            else
            {
                GetPotentialBlackPawnCaptures(board, allowedFrom, allowedTo, moves, ref moveCount);
                GetPotentialBlackPawnMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            }

            //moves.Sort((m1, m2) => m1.Key2.CompareTo(m2.Key2));
        }
コード例 #2
0
        public void GetAllPotentialCaptures(Board board, Move[] moves, ref int moveCount, Bitboard checkers, Bitboard pinned)
        {
            var allowedFrom   = ~0UL;
            var allowedToKing = board.WhiteToMove ? board.BlackPieces : board.WhitePieces;
            var allowedTo     = allowedToKing;

            var checkCount = checkers.PopCount();

            if (checkCount > 1)
            {
                GetPotentialKingCaptures(board, allowedToKing, moves, ref moveCount);
                return;
            }

            if (checkCount == 1)
            {
                allowedFrom = ~pinned;
                allowedTo   = checkers;
            }

            GetPotentialKnightMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialBishopMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialRookMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialQueenMoves(board, allowedFrom, allowedTo, moves, ref moveCount);
            GetPotentialKingCaptures(board, allowedToKing, moves, ref moveCount);

            if (board.WhiteToMove)
            {
                GetPotentialWhitePawnCaptures(board, allowedFrom, allowedTo, moves, ref moveCount);
            }
            else
            {
                GetPotentialBlackPawnCaptures(board, allowedFrom, allowedTo, moves, ref moveCount);
            }

            //moves.RemoveAll(m => m.TakesPiece == 0);
        }