]> git.sesse.net Git - stockfish/commitdiff
Use average complexity for time management
authorRui Coelho <ruicoelhopedro@gmail.com>
Mon, 17 Jan 2022 16:51:20 +0000 (16:51 +0000)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Mon, 17 Jan 2022 18:48:23 +0000 (19:48 +0100)
This patch is a variant of the idea by locutus2 (https://tests.stockfishchess.org/tests/view/61e1f24cb1f9959fe5d88168) to adjust the total time depending on the average complexity of the position.

Passed STC
LLR: 2.94 (-2.94,2.94) <0.00,2.50>
Total: 39664 W: 10765 L: 10487 D: 18412
Ptnml(0-2): 162, 4213, 10837, 4425, 195
https://tests.stockfishchess.org/tests/view/61e2df8b65a644da8c9ea708

Passed LTC
LLR: 2.94 (-2.94,2.94) <0.50,3.00>
Total: 127656 W: 34505 L: 34028 D: 59123
Ptnml(0-2): 116, 12435, 38261, 12888, 128
https://tests.stockfishchess.org/tests/view/61e31db5babab931824dff5e

closes https://github.com/official-stockfish/Stockfish/pull/3892

Bench: 4464962

src/misc.h
src/search.cpp
src/thread.h

index 688d00e7e55c967335367be8fb2f0287bffeb5c6..b962673384b97e2c9660cfd6e2aeee122ea385cd 100644 (file)
@@ -105,6 +105,9 @@ class RunningAverage {
       bool is_greater(int64_t a, int64_t b)
         { return b * average > a * PERIOD * RESOLUTION ; }
 
+      int64_t value()
+        { return average / (PERIOD * RESOLUTION); }
+
   private :
       static constexpr int64_t PERIOD     = 4096;
       static constexpr int64_t RESOLUTION = 1024;
index c81496d17a35aa6a00374c9ec9be9115ea720c49..c9d5da64c2f8efa0e6602f3c6f2cc28cafeb038a 100644 (file)
@@ -329,6 +329,7 @@ void Thread::search() {
 
   doubleExtensionAverage[WHITE].set(0, 100);  // initialize the running average at 0%
   doubleExtensionAverage[BLACK].set(0, 100);  // initialize the running average at 0%
+  complexityAverage.set(232, 1);
 
   nodesLastExplosive = nodes;
   nodesLastNormal    = nodes;
@@ -496,7 +497,10 @@ void Thread::search() {
           double reduction = (1.47 + mainThread->previousTimeReduction) / (2.32 * timeReduction);
           double bestMoveInstability = 1.073 + std::max(1.0, 2.25 - 9.9 / rootDepth)
                                               * totBestMoveChanges / Threads.size();
-          double totalTime = Time.optimum() * fallingEval * reduction * bestMoveInstability;
+          int complexity = mainThread->complexityAverage.value();
+          double complexPosition = std::clamp(1.0 + (complexity - 232) / 1750.0, 0.5, 1.5);
+
+          double totalTime = Time.optimum() * fallingEval * reduction * bestMoveInstability * complexPosition;
 
           // Cap used time in case of a single legal move for a better viewer experience in tournaments
           // yielding correct scores and sufficiently fast moves.
@@ -806,6 +810,8 @@ namespace {
     improving = improvement > 0;
     complexity = abs(ss->staticEval - (us == WHITE ? eg_value(pos.psq_score()) : -eg_value(pos.psq_score())));
 
+    thisThread->complexityAverage.update(complexity);
+
     // Step 7. Futility pruning: child node (~25 Elo).
     // The depth condition is important for mate finding.
     if (   !ss->ttPv
index a6b0b5a0bc95577924856325ad70330d369c3661..c3d38f3cf310c1c1c6255304093aca122f18565b 100644 (file)
@@ -61,6 +61,7 @@ public:
   Material::Table materialTable;
   size_t pvIdx, pvLast;
   RunningAverage doubleExtensionAverage[COLOR_NB];
+  RunningAverage complexityAverage;
   uint64_t nodesLastExplosive;
   uint64_t nodesLastNormal;
   std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;