Пример #1
0
        internal static void generate_quiet_check(Position pos, MoveStack[] ms, ref int mpos)
        {
            /// generate<MV_NON_CAPTURE_CHECK> generates all pseudo-legal non-captures and knight
            /// underpromotions that give check. Returns a pointer to the end of the move list.
            Debug.Assert(!pos.in_check());

            var ci = CheckInfoBroker.GetObject();
            ci.CreateCheckInfo(pos);
            var target = ~pos.occupied_squares;
            var dc = ci.dcCandidates;

            while (dc != 0)
            {
                var from = Utils.pop_lsb(ref dc);
                var pt = Utils.type_of(pos.piece_on(from));

                if (pt == PieceTypeC.PAWN)
                {
                    continue; // Will be generated together with direct checks
                }

                var b = pos.attacks_from_PTS(pt, from) & ~pos.occupied_squares;

                if (pt == PieceTypeC.KING)
                {
                    b &= ~Utils.PseudoAttacks[PieceTypeC.QUEEN][ci.ksq];
                }

                while (b != 0)
                {
                    ms[mpos++].move = Utils.make_move(from, Utils.pop_lsb(ref b));
                }
            }

            generate_all(GenType.QUIET_CHECKS, pos, ms, ref mpos, pos.sideToMove, target, ci);

            CheckInfoBroker.Free();
        }
Пример #2
0
        internal static void generate_quiet_check(Position pos, MoveStack[] ms, ref int mpos)
        {
            /// generate<MV_NON_CAPTURE_CHECK> generates all pseudo-legal non-captures and knight
            /// underpromotions that give check. Returns a pointer to the end of the move list.
            Debug.Assert(!pos.in_check());

            Color us = pos.sideToMove;
            CheckInfo ci = CheckInfoBroker.GetObject();
            ci.CreateCheckInfo(pos);
            Bitboard dc = ci.dcCandidates;

            while (dc != 0)
            {
                Square from = Utils.pop_1st_bit(ref dc);
                PieceType pt = Utils.type_of(pos.piece_on(from));

                if (pt == PieceTypeC.PAWN)
                    continue; // Will be generated together with direct checks

                Bitboard b = pos.attacks_from_PTS(pt, from) & ~pos.occupied_squares;

                if (pt == PieceTypeC.KING)
                    b &= ~Utils.PseudoAttacks[PieceTypeC.QUEEN][ci.ksq];

                while (b != 0) { ms[mpos++].move = Utils.make_move(from, Utils.pop_1st_bit(ref b)); }
            }

            generate_pawn_moves(us, MoveType.MV_QUIET_CHECK, pos, ms, ref mpos, ci.dcCandidates, ci.ksq);

            generate_direct_checks(PieceTypeC.KNIGHT, pos, ms, ref mpos, us, ci);
            generate_direct_checks(PieceTypeC.BISHOP, pos, ms, ref mpos, us, ci);
            generate_direct_checks(PieceTypeC.ROOK, pos, ms, ref mpos, us, ci);
            generate_direct_checks(PieceTypeC.QUEEN, pos, ms, ref mpos, us, ci);

            if (pos.can_castle_C(us) != 0)
            {
                generate_castle(CastlingSideC.KING_SIDE, true, pos, ms, ref mpos, us);
                generate_castle(CastlingSideC.QUEEN_SIDE, true, pos, ms, ref mpos, us);
            }

            CheckInfoBroker.Free();
        }
Пример #3
0
        private static void generate_moves(
            int Pt,
            bool Checks,
            Position pos,
            MoveStack[] mlist,
            ref int mpos,
            int us,
            ulong target,
            CheckInfo ci)
        {
            Debug.Assert(Pt != PieceTypeC.KING && Pt != PieceTypeC.PAWN);

            var pl = pos.pieceList[us][Pt];
            var plPos = 0;
            
            for (var from = pl[plPos]; from != SquareC.SQ_NONE; from = pl[++plPos])
            {
                if (Checks)
                {
                    if ((Pt == PieceTypeC.BISHOP || Pt == PieceTypeC.ROOK || Pt == PieceTypeC.QUEEN)
                        && ((Utils.PseudoAttacks[Pt][from] & (ulong)target & ci.checkSq[Pt]) == 0))
                    {
                        continue;
                    }

                    if ((ci.dcCandidates != 0) && (Utils.bit_is_set(ci.dcCandidates, from) != 0))
                    {
                        continue;
                    }
                }

                var b = pos.attacks_from_PTS(Pt, from) & (ulong)target;

                if (Checks)
                {
                    b &= ci.checkSq[Pt];
                }

                // SERIALIZE(b);
                while (b != 0)
                {
                    mlist[mpos++].move = Utils.make_move(from, Utils.pop_lsb(ref b));
                }
            }
        }
Пример #4
0
        private static void generate_direct_checks(PieceType Pt, Position pos, MoveStack[] ms, ref int mpos, Color us, CheckInfo ci)
        {
            Debug.Assert(Pt != PieceTypeC.KING && Pt != PieceTypeC.PAWN);

            Bitboard b, target;

            Square[] pl = pos.pieceList[us][Pt];
            int plPos = 0;
            Square from = pl[plPos];

            if ((from = pl[plPos]) != SquareC.SQ_NONE)
            {
                target = ci.checkSq[Pt] & ~pos.occupied_squares; // Non capture checks only

                do
                {
                    if ((Pt == PieceTypeC.BISHOP || Pt == PieceTypeC.ROOK || Pt == PieceTypeC.QUEEN)
                        && ((Utils.PseudoAttacks[Pt][from] & target) == 0))
                        continue;

                    if ((ci.dcCandidates != 0) && (Utils.bit_is_set(ci.dcCandidates, from) != 0))
                        continue;

                    b = pos.attacks_from_PTS(Pt, from) & target;
                    while (b != 0) { ms[mpos++].move = Utils.make_move(from, Utils.pop_1st_bit(ref b)); }

                } while ((from = pl[++plPos]) != SquareC.SQ_NONE);
            }
        }