Beispiel #1
0
        public Eval AddPV(Eval mAlpha, Eval mValue, Move move, List <Move> line)
        {
            var bWTM = WTM();
            //[Lock]UCI may change this at any time.  See GameState.newVariations()
            var bHasValue = 0 < State.VariationCount;
            var bGrow     = State.VariationCount < State.MultiPVLength;

            if (bGrow)
            {
                State.VariationCount++;
            }

            var bRoomToGrow = State.VariationCount < State.MultiPVLength;
            var vn          = State.Variation;
            var nFinal      = State.VariationCount - 1;
            var bPlace      = bGrow || bHasValue && mValue > vn[nFinal].Value;

            if (bPlace)
            {
                vn[nFinal].Value = mValue;
                bHasValue        = true;

                if (vn[nFinal].Moves is null)
                {
                    vn[nFinal].Moves = new List <Move>();
                }

                var lineMoves = vn[nFinal].Moves;
                lineMoves.Clear();

                if (!isDefined(move))
                {
                    Debug.Assert(isDefined(move), "Undefined Move [AddPV]");
                    move = Move.NullMove;
                }

                lineMoves.Add(move);

                var bPonder = line.Count > 0; //!bChildFinal
                if (bPonder)
                {
                    lineMoves.AddRange(line);
                }

                //
                // Insert at correct position:
                //
                var nPlace = vn.Insert(nFinal);

                if (nPlace == 0)
                {
                    var sb    = new StringBuilder();
                    var mEval = reflectValue(bWTM, mValue);
                    sb.UpdateBestInfo(State.BestMoves, lineMoves, mEval, bPonder, State.Rule)
                    .FlushLine();
                }
#if DebugPlace
                if (UCI.IsDebug)
                {
                    var sb    = new StringBuilder();
                    var sGrow = bGrow ? "Placed" : "Replaced";
                    sb.AppendFormat($"{sGrow} vn[{nPlace}]");
                    LogInfo(Level.note, sb.ToString());
                    sb.Clear();
                    State.MovePosition.writePV(sb, nPlace, bWTM);
                }
#endif
            }

            //
            // Avoid raising Alpha until we have a candidate for the weakest Variation:
            //
            return(bRoomToGrow ? mAlpha : bHasValue?vn[nFinal].Value : mValue);
        }
Beispiel #2
0
 internal static UInt32 captured(Move move)
 {
     return((UInt32)move >> nCaptiveBit & vPieceMask);
 }
Beispiel #3
0
 internal static UInt32 promoted(Move move)
 {
     return((UInt32)move >> nPromoteBit & vPieceMask);
 }
Beispiel #4
0
 internal static Int32 to(Move move)
 {
     return((Int32)move >> nToBit & (Int32)uSquareMask);
 }
Beispiel #5
0
 private static UInt32 moved(Move move)
 {
     return((UInt32)move >> nPieceBit & vPieceMask);
 }
Beispiel #6
0
 internal static bool isCapture(Move move)
 {
     return((move & Move.CaptiveMask) != 0);
 }
Beispiel #7
0
 protected static Int32 from(Move move)
 {
     return((Int32)move >> nFromBit & (Int32)uSquareMask);
 }
Beispiel #8
0
 internal static Boolean isCastles(Move move)
 {
     return((move & Move.Castles) != 0);
 }
Beispiel #9
0
 internal static Boolean isNullMove(Move move)
 {
     return((move & Move.NormalMask) == Move.NullMove);
 }
Beispiel #10
0
 internal static Boolean isEmptyMove(Move move)
 {
     return((move & Move.NormalMask) == Move.EmptyMove);
 }
Beispiel #11
0
 internal static Boolean isDefined(Move move)
 {
     return((move & Move.NormalMask) != Move.Undefined);
 }
Beispiel #12
0
 internal static Boolean isDefinite(Move move)
 {
     return(isDefined(move) && !isEmptyMove(move));
 }