Skip to content

Commit 2b03723

Browse files
ruicoelhopedrovondele
authored andcommitted
Use average complexity for time management
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 #3892 Bench: 4464962
1 parent d11101e commit 2b03723

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/misc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class RunningAverage {
105105
bool is_greater(int64_t a, int64_t b)
106106
{ return b * average > a * PERIOD * RESOLUTION ; }
107107

108+
int64_t value()
109+
{ return average / (PERIOD * RESOLUTION); }
110+
108111
private :
109112
static constexpr int64_t PERIOD = 4096;
110113
static constexpr int64_t RESOLUTION = 1024;

src/search.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void Thread::search() {
329329

330330
doubleExtensionAverage[WHITE].set(0, 100); // initialize the running average at 0%
331331
doubleExtensionAverage[BLACK].set(0, 100); // initialize the running average at 0%
332+
complexityAverage.set(232, 1);
332333

333334
nodesLastExplosive = nodes;
334335
nodesLastNormal = nodes;
@@ -496,7 +497,10 @@ void Thread::search() {
496497
double reduction = (1.47 + mainThread->previousTimeReduction) / (2.32 * timeReduction);
497498
double bestMoveInstability = 1.073 + std::max(1.0, 2.25 - 9.9 / rootDepth)
498499
* totBestMoveChanges / Threads.size();
499-
double totalTime = Time.optimum() * fallingEval * reduction * bestMoveInstability;
500+
int complexity = mainThread->complexityAverage.value();
501+
double complexPosition = std::clamp(1.0 + (complexity - 232) / 1750.0, 0.5, 1.5);
502+
503+
double totalTime = Time.optimum() * fallingEval * reduction * bestMoveInstability * complexPosition;
500504

501505
// Cap used time in case of a single legal move for a better viewer experience in tournaments
502506
// yielding correct scores and sufficiently fast moves.
@@ -806,6 +810,8 @@ namespace {
806810
improving = improvement > 0;
807811
complexity = abs(ss->staticEval - (us == WHITE ? eg_value(pos.psq_score()) : -eg_value(pos.psq_score())));
808812

813+
thisThread->complexityAverage.update(complexity);
814+
809815
// Step 7. Futility pruning: child node (~25 Elo).
810816
// The depth condition is important for mate finding.
811817
if ( !ss->ttPv

src/thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Thread {
6161
Material::Table materialTable;
6262
size_t pvIdx, pvLast;
6363
RunningAverage doubleExtensionAverage[COLOR_NB];
64+
RunningAverage complexityAverage;
6465
uint64_t nodesLastExplosive;
6566
uint64_t nodesLastNormal;
6667
std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;

0 commit comments

Comments
 (0)