示例#1
0
        private static void AddMove(this IPosition pos, MoveList moves, Piece piece, Square from, Square to, Piece promoted, Emgf flags, EMoveType type = EMoveType.Quiet)
        {
            Move move;

            if (type.HasFlagFast(EMoveType.Capture))
            {
                move = new Move(piece, pos.GetPiece(to), from, to, type, promoted);
            }
            else if (type.HasFlagFast(EMoveType.Epcapture))
            {
                move = new Move(piece, EPieceType.Pawn.MakePiece(~pos.State.SideToMove), from, to, type, promoted);
            }
            else
            {
                move = new Move(piece, from, to, type, promoted);
            }

            // check if move is actual a legal move if the flag is enabled
            if (flags.HasFlagFast(Emgf.Legalmoves) && !pos.IsLegal(move, piece, from, type))
            {
                return;
            }

            moves.Add(move);
        }
示例#2
0
        public static MoveList GenerateMoves(this IPosition pos, Emgf flags = Emgf.Legalmoves, bool useCache = true, bool force = false)
        {
            pos.State.Pinned = flags.HasFlagFast(Emgf.Legalmoves)
                ? pos.GetPinnedPieces(pos.GetPieceSquare(EPieceType.King, pos.State.SideToMove), pos.State.SideToMove)
                : BitBoards.EmptyBitBoard;

            var moves = new MoveList();

            pos.GenerateCapturesAndPromotions(moves, flags);
            pos.GenerateQuietMoves(moves, flags);

            return(moves);
        }
示例#3
0
        private static void AddPawnMoves(this IPosition pos, MoveList moves, BitBoard targetSquares, Direction direction, EMoveType type, Emgf flags)
        {
            if (targetSquares.Empty())
            {
                return;
            }

            var stm   = pos.State.SideToMove;
            var piece = EPieceType.Pawn.MakePiece(stm);

            var promotionRank       = stm.PromotionRank();
            var promotionSquares    = targetSquares & promotionRank;
            var nonPromotionSquares = targetSquares & ~promotionRank;

            while (nonPromotionSquares)
            {
                var to   = nonPromotionSquares.Lsb();
                var from = to - direction;
                pos.AddMove(moves, piece, from, to, PieceExtensions.EmptyPiece, flags, type);
                BitBoards.ResetLsb(ref nonPromotionSquares);
            }

            type |= EMoveType.Promotion;

            if (flags.HasFlagFast(Emgf.Queenpromotion))
            {
                var sqTo   = promotionSquares.Lsb();
                var sqFrom = sqTo - direction;
                pos.AddMove(moves, piece, sqFrom, sqTo, EPieceType.Queen.MakePiece(stm), flags, type);
                BitBoards.ResetLsb(ref promotionSquares);
            }
            else
            {
                while (promotionSquares)
                {
                    var sqTo   = promotionSquares.Lsb();
                    var sqFrom = sqTo - direction;
                    for (var promotedPiece = EPieceType.Queen; promotedPiece >= EPieceType.Knight; promotedPiece--)
                    {
                        pos.AddMove(moves, piece, sqFrom, sqTo, promotedPiece.MakePiece(stm), flags, type);
                    }

                    BitBoards.ResetLsb(ref promotionSquares);
                }
            }
        }