Exemplo n.º 1
0
        public GameState(ICommand Command)
        {
            if (Command is null)
            {
                throw new ArgumentNullException("Command");
            }

            this.Command = Command;

            //
            //[ToDo]Allocate a separate Pool of positions for each thread:
            //
            PositionPool = new Pool <Position>();

            Bound = new SearchBound();
            Rule  = new CastleRule();
            Case  = new PerfCase();

            newBestMoves(wDepthMax);
            newTimers();
            SeededRandom = new Random(); // Variable seed based on Environment.TickCount

            loadEndgameValue();
            loadExtensionLimit();
#if KillerCompositionHash
            var uBottleLength = 8191U;
#else
            var uBottleLength = wPlyHistory;
#endif
#if UseKillers
            Bottle = new MoveBottle(uBottleLength);
#endif                                  // UseKillers
            wireControls();

            newNodeDelta(wDepthMax);
            newEarlyMoveCounts(wPlyHistory);
            newPVDoubleCounts(wPlyHistory);
#if MaterialBalance
            newCXPMemo(uDefaultComposition2);
#else
            newCXPMemo(uDefaultCompositions);
#endif
            newPXPMemo(uDefaultPawnPositions);

            //clear();
        }
Exemplo n.º 2
0
        public Eval IteratePlies(SearchBound bound)
        {
            var mValue       = EvalUndefined; // Return Value
            var vDepthLimit  = bound.Plies;
            var wMovesToMate = bound.MovesToMate;

#if DisplayDepth
            var sw = State.IterationTimer;
            if (sw is null)
            {
                throw new PositionException("Null IterationTimer Stopwatch");
            }
            else
            {
                sw.Start();
            }

            var qTotal1 = (UInt64)State.NodeTotal;
#if DisplayPrediction
            var qPredicted1 = 0UL;
#endif
#endif
            var vStartDepth = vStartDepthDefault;
            if (vDepthLimit.HasValue && vDepthLimit < vStartDepth)
            {
                vStartDepth = vDepthLimit.Value;
            }

            for (var vDepth = vStartDepth;
                 !vDepthLimit.HasValue || vDepth <= vDepthLimit;
                 vDepth++)
            {
#if DisplayDepth
                if (UCI.IsDebug)
                {
                    LogInfoNewLine(Level.note);
                    LogInfo(Level.note, $"Depth = {vDepth} at {DateTime.Now:yyyy-MM-dd HH:mm:ss.ff}");
                }
#endif
                mValue = beginIteration(vDepth, mValue);
                endIteration(vDepth);
#if DisplayDepth
                if (UCI.IsDebug)
                {
                    sw.Stop();
                    var dElapsedMS = (Double)sw.ElapsedMilliseconds;
                    var qTotal2    = (UInt64)State.NodeTotal;
                    var qNodeDelta = qTotal2 - qTotal1;

                    GameState.displayRate(dElapsedMS, qNodeDelta);
#if DisplayPrediction
                    var qPredicted2 =
#if !TestRegression                     // Elide final prediction
                        vDepth == vDepthLimit ? 0UL :
#endif
                        State.Predict(vStartDepth, vDepth, qNodeDelta);

                    GameState.DisplayPrediction(dElapsedMS, qNodeDelta, qPredicted1, qPredicted2);
                    qPredicted1 = qPredicted2;
#endif                                  // DisplayPrediction
                    qTotal1 = qTotal2;
                    sw.Restart();
                }
#endif                                  // DisplayDepth
                if (wMovesToMate.HasValue)
                {
                    var mAbs = Abs(mValue);
                    if (MateMin <= mAbs && MateMax <= mAbs + wMovesToMate)
                    {
                        break;          // End search early if a MovesToMate bound has been satisfied
                    }
                }
            }

            return(mValue);
        }