Пример #1
0
        protected Int32 generateSwaps(List <Move> moves, Int32 nTo)
        {
            var qpTo     = BIT0 << nTo;
            var bWTM     = WTM();
            var friend   = getSide(bWTM);
            var qpFriend = friend.Piece;
            var vKingPos = getKingPos(bWTM);
            var bInCheck = InCheck();

            clearPseudoSwapLists(moves); // ~32 MHz
#if UnshadowRay2
            var bRayCheck = false;
#endif
            if (bInCheck)
            {
                var qpChx = checkers(bWTM);
#if UnshadowRay
                bRayCheck = (qpChx & (DiagPiece | RectPiece)) != 0;
#endif
                var bSingleCheck = IsOneOrNone(qpChx);
                if (bSingleCheck)
                {
                    var qpFoe = qpChx & qpTo;

                    if (qpFoe != 0)
                    {
                        addPieceCaptures(qpFoe, qpFriend);
                        addPawnCaptures(friend, qpFoe);
                    }
                }                       // bSingleCheck
            }                           //!bInCheck
            else
            {
                var qpFoe = qpTo & ~qpFriend;
                addPieceCaptures(qpFoe, qpFriend);
                addPawnCaptures(friend, qpFoe);
            }                           //!bInCheck
#if UnshadowRay2
            addKingCaptures(qpTo & ~qpFriend, vKingPos, bRayCheck);
#else
            addKingCaptures(qpTo & ~qpFriend, vKingPos);
#endif
            addPseudoSwaps(moves);
            return(State.IncPseudoMoveTotal(moves.Count));
        }
Пример #2
0
        protected Int32 generateMaterialMoves(List <Move> moves)
        {
            var bWTM     = WTM();
            var bInCheck = InCheck();

            (BoardSide friend, BoardSide foe) = getSides(bWTM);
            var qpFriend = friend.Piece;
            var vKingPos = getKingPos(bWTM);

            clearPseudoMaterialMoveLists(moves);
#if UnshadowRay2
            var bRayCheck = false;
#endif
            if (bInCheck)
            {
                var qpChx = checkers(bWTM);
#if UnshadowRay
                bRayCheck = (qpChx & (DiagPiece | RectPiece)) != 0;
#endif
                var qpChx2       = qpChx;
                var nChx         = RemoveLo(ref qpChx2);
                var bSingleCheck = qpChx2 == 0;

                if (bSingleCheck)
                {
                    var qpRay = interpositions(nChx, vKingPos);

                    if (qpChx != 0)
                    {
                        addPieceCaptures(qpChx, qpFriend);

                        var qpPawnCapture = qpChx;
                        if (IsPassed() && (qpChx & Pawn) != 0)
                        {
                            qpPawnCapture |= BIT0 << ep(FlagsLo);
                        }

                        addPawnCaptures(friend, qpPawnCapture);
                        addPromotions(friend, qpRay);
                    }
                }                       // bSingleCheck
            }                           //!bInCheck
            else
            {
                var qpFoe = foe.Piece;
                addPieceCaptures(qpFoe, qpFriend);

                var qpPawnCapture = qpFoe;
                if (IsPassed())
                {
                    qpPawnCapture |= BIT0 << ep(FlagsLo);
                }

                addPawnCaptures(friend, qpPawnCapture);
                addPromotions(friend, ~RankPiece);
            }                           //!bInCheck
#if UnshadowRay2
            addKingCaptures(~qpFriend, vKingPos, bRayCheck);
#else
            addKingCaptures(~qpFriend, vKingPos, bWTM);
#endif
            addPseudoMaterialMoves(moves);
            return(State.IncPseudoMoveTotal(moves.Count));
        }
Пример #3
0
        protected Int32 generate(List <Move> moves, Boolean bSwap)      // Adds all Pseudo Moves at 400 to 1000 KHz; Generates moves at ~18 MHz
        {
            var bWTM     = WTM();
            var bInCheck = InCheck();

            (BoardSide friend, BoardSide foe) = getSides(bWTM);
            var qpFriend = friend.Piece;
            var vKingPos = getKingPos(bWTM);

            clearPseudoMoveLists(moves, bSwap);
#if UnshadowRay2
            var bRayCheck = false;
#endif
            if (bInCheck)
            {
                var qpChx = checkers(bWTM);
#if UnshadowRay
                bRayCheck = (qpChx & (DiagPiece | RectPiece)) != 0;
#endif
                var qpChx2       = qpChx;
                var nChx         = RemoveLo(ref qpChx2);
                var bSingleCheck = qpChx2 == 0;

                if (bSingleCheck)
                {
                    //
                    // Interposition includes capture of the checking
                    // piece, and interpositions along a ray giving check.
                    // Only Moves for these To Squares will be considered:
                    //
                    var qpRay = interpositions(nChx, vKingPos);
                    var qpTo  = qpChx | qpRay;
                    if (qpTo != 0)
                    {
                        addPieceCapturesAndMoves(qpTo, qpFriend);
                    }

                    var qpPawnCapture = qpChx;
                    if (IsPassed() && (qpChx & Pawn) != 0)
                    {
                        qpPawnCapture |= BIT0 << ep(FlagsLo);
                    }

                    addPawnCaptures(friend, qpPawnCapture);
                    addPawnMoves(friend, qpRay);
                }                       // bSingleCheck
            }
            else                        //!bInCheck
            {
                addPieceCapturesAndMoves(~qpFriend, qpFriend);

                var qpFoe         = foe.Piece;
                var qpPawnCapture = qpFoe;
                if (IsPassed())
                {
                    qpPawnCapture |= BIT0 << ep(FlagsLo);
                }

                addPawnCaptures(friend, qpPawnCapture);
                addPawnMoves(friend, ~RankPiece);

                var friendRule = getRule(bWTM);
                addCastles(friend, friendRule, foe);
            }                           //!bInCheck
#if UnshadowRay2
            addKingCapturesAndMoves(~qpFriend, vKingPos, bRayCheck);
#else
            addKingCapturesAndMoves(~qpFriend, vKingPos);
#endif
            if (bSwap && !bInCheck)
            {
                addPseudoMovesGood(moves);
            }
            else
            {
                addPseudoMoves(moves);
            }

            return(State.IncPseudoMoveTotal(moves.Count));
        }