Exemplo n.º 1
0
        private Eval fullEval()
        {
            //
            //[Note]StaticEvaluations = TotalEvaluations - FullEvaluations
            // Draws are included; because they exit early.
            //
            GameState.AtomicIncrement(ref State.FullEvals);

            var mValue = staticEval(out PawnPosition pp);

            //
            // Load PawnFeature Deltas from the PawnPositions hash table,
            // based on HashPawn, the Zobrist Hashcode summed over Pawns.
            //
            if (Pawn == 0)              // PawnHash == default(Hashcode)}
            {
#if EvalKBNvKMateCorner
                if ((FlagsEG & EGFlags.KBNvK) != 0)
                {
                    var mReward = rewardKBNvKMateCorner();
                    mValue += mReward;
                }
#endif
            }
            else
            {
#if EvalOutsideSquare
                if ((FlagsEG & EGFlags.OutsideSquare) != 0)
                {
                    var mReward = punishOutsideSquare();
                    mValue += mReward;
                }
#endif
#if EvalKQvKPDistance
                if ((FlagsEG & EGFlags.KQvKP) != 0)
                {
                    var mReward = rewardKQvKPProximity();
                    mValue += mReward;
                }
#endif
#if EvalRookBehindPasser
                if (Rook != 0)
                {
#if PawnPositionByValue
                    var bDefault = (pp.BlackPRP & PRPFlags.IsValid) == 0;
#else
                    var bDefault = pp == default(PawnPosition);
#endif
                    if (bDefault)
                    {
                        pp = State.GetPXP(this);
                    }
                    const Boolean bWhiteRook        = true;
                    var           mRooksBehindBlack = rookBehindPasser(!bWhiteRook, pp.BlackPassers);
                    var           mRooksBehindWhite = rookBehindPasser(bWhiteRook, pp.WhitePassers);
#if TestRookBehindPasser
                    if (mRooksBehindBlack != 0 ||
                        mRooksBehindWhite != 0)
                    {
                        DisplayCurrent("pieceval()");
                    }
#endif
                    mValue += mRooksBehindWhite;
                    mValue -= mRooksBehindBlack;
                }
#endif
            }

            var mAbs = Abs(mValue);
            Debug.Assert(mAbs < MateMin, "Mate value returned by staticEval()");
            if (mAbs <= mDeltaBaseWeight) //[ToDo]Define a new threshold
            {
#if BuildAtxTo
                buildAtxTo(RankPiece);
#endif
#if Mobility
                mValue += mobility();
#endif
            }

            //
            // The following helps find Draw3
            //
            if (IsDraw2() && mAbs < MateMin)
            {
                mValue /= 4;            //[IBV]Care will be needed to protect the EvalType here
            }
            return(mValue);
        }
Exemplo n.º 2
0
        //
        //[ToDo]Add evaluation of practical Draws where helpmate is possible:
        //
        // KKNN or KNKNN
        // KBKB opposite color
        // KNKBN, KBKBN. KBKBB pair [Note: KNKBB pair can be won; but perhaps not in 50 moves]
        //
        // More Complex Draws, assuming weaker side in time to defend:
        //
        // KKP if weaker side maintains opposition
        // Distant Opposition vs. Key/Critical Squares vs Corresponding or Relative Squares!?
        //
        // KBKBP of opposite color
        // KPKQ if P to queen on ACFH-file and sronger K too far to help
        //

        //
        // Development [initial move per piece, delaying heavy pieces]
        // Control of the Center by Pawns
        // Control of Squares around King
        // Castling and King Safety [Corner Squares] vs King Activity in the Endgame
        //
        // Rooks on Open Files
        // Rook or Queen on 7th [or 2nd] Rank
        // Protected Piece and Connected Rook Bonus
        // Knight Scope and Outpost [free of Pawn harrassment]
        // Bishop Scope [and Bad Bishop Detection]
        //
        // Bonus for Bishop with color of Promotion Square for any Passed Pawns, especially
        // Rook Pawns.  Applies to defense and Passed Opposing Pawns, as well as to offense.
        //
        // Attack Pawn Chains at the base
        // Bonus for Passed Pawn Couples
        //
        // Piece Values depending on Opening, Middle, End Game Phase and Relative Advantage:
        // Stronger side favors [vice versa Weaker side is averse to]
        // Bishops of Opposite Colors in Middle Game; and Bishops of Same Color in Endgame.
        //

        //
        // Technical and Tablebase Draws:
        // KRKRP if weaker side can attain Philidor Position
        //
        // EGTB Alternatives: Syzygy by Ronald de Man, Gaviota EGTB by Miguel A. Ballicora,
        // Nalimov by Eugene Nalimov.  Syzygy is preferred by Houdini.  It is compact; but
        // does not provide Distance to Mate (DTM).  They provide Wind-Draw-Loss (WDL) and
        // Distance to Zero (DTZ).
        //
        // The Syzygy 6-man EGTB is available at http://tablebase.sesse.net/syzygy, where
        // the (290) 3-4-5-men files require 938 MB; and (730) 6-men files require 149 GB.
        //
        protected Eval staticEval(out PawnPosition pp)  //[New]~9.666 MHz vs ~13.333 MHz w/o EvalRookBehindPasser
        {
            pp = default;
            if (IsInsufficient())
            {
                return(contempt());
            }

            GameState.AtomicIncrement(ref State.TotalEvals); // vs. FullEvaluations

            setEndGameFlags();

            if (EvalUndefined < StaticDelta)
            {
                return(StaticDelta);
            }

            //
            // Retrieve material balance from the Composition:
            //
            getValue(out Eval mDelta, out Eval mTotal);

            if (Pawn != 0)              // Else PawnHash == default(Hashcode)
            {
                pp = State.GetPXP(this);

                mDelta += pp.Delta;
                mTotal += pp.Total;
#if EvalWrongBishop
                if (punishWrongBishop(pp.BlackPRP & PRPFlags.Both, Side[Black].FlagsHi))
                {
                    mDelta += mWrongBishopWeight; // Black has Wrong Bishop
                }
                if (punishWrongBishop(pp.WhitePRP & PRPFlags.Both, Side[White].FlagsHi))
                {
                    mDelta -= mWrongBishopWeight; // White has Wrong Bishop
                }
#endif
            }
#if TradePieces
            if (mTotal > 0)
            {
                //
                // The following provides an incentive for the stronger
                // side to exchange material and for the weaker side to
                // avoid such exchanges.  The value is Zero in an equal
                // position, and grows to a maximum of one centipawn if
                // the weaker side has been stripped of all material.
                //
                // Intuitively: Exchanges reduce the Total material but
                // leave the Delta unaffected; and Delta can range from
                // Zero to the Total.  Thus, their quotient ranges from
                // Zero to One.
                //
                //[Note]A refinement is needed to prefer trading Pieces
                // over Pawns in the endgame.
                //
                var mIncentive = (Eval)(mPawnWeight * mDelta / mTotal);
                mDelta += mIncentive;
            }
#endif
            //
            //[Note]staticEval() prepares StaticTotal for any isEndgame() tests
            //
            StaticTotal = mTotal;       // Update for isEndgame()
            StaticDelta = mDelta;
            return(mDelta);
        }