Esempio n. 1
0
        public void IterateCases()
        {
#if DisplayDepth
            var sw = State.IterationTimer;
            if (sw is null)
            {
                throw new PositionException("Null IterationTimer Stopwatch");
            }
            else
            {
                sw.Start();
            }

            var qTotal1 = State.NodeTotal;
#if DisplayPrediction
            var qPredicted1 = 0UL;
#endif
#endif
            var testCases = getTestCases();

            var pc = State.Case;
            foreach (var tc in testCases)
            {
                var vDepth = tc.Plies;
#if DisplayDepth
                if (UCI.IsDebug)
                {
                    LogInfoNewLine(Level.note);
                    LogInfo(Level.note, $"Depth = {vDepth} at {DateTime.Now:yyyy-MM-dd HH:mm:ss.ff}");
                }
#endif
                //[Init]Reset PerfCase counts prior to the recursive search for each test case
                pc.Clear();
                perft(vDepth);
#if DisplayDepth
                if (UCI.IsDebug)
                {
                    sw.Stop();
                    var dElapsedMS = (Double)sw.ElapsedMilliseconds;
                    var qNodeDelta = pc.TotalNodes.HasValue ? pc.TotalNodes.Value : 0;
                    GameState.displayRate(dElapsedMS, qNodeDelta);
#if DisplayPrediction
                    var qPredicted2 = State.Predict(0, vDepth, qNodeDelta);
                    GameState.DisplayPrediction(dElapsedMS, qNodeDelta, qPredicted1, qPredicted2);
                    qPredicted1 = qPredicted2;
#endif                                  // DisplayPrediction
                    qTotal1 = State.NodeTotal;
                    sw.Restart();
                }
#endif                                  // DisplayDepth
                if (!tc.Passed(pc))
                {
                    LogInfo(Level.error, $"{Name} failed at Depth = {tc.Plies}");
                }
            }
        }
Esempio 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);
        }