Skip to content

Commit 499d711

Browse files
VizvezdenecJoachim26
authored andcommitted
Tune search at very long time control
This patch is a result of tuning done by user @candirufish after 150k games. Since the tuned values were really interesting and touched heuristics that are known for their non-linear scaling I decided to run limited games LTC match, even if the STC test was really bad (which was expected). After seeing the results of the LTC match, I also run a VLTC (very long time control) SPRTtest, which passed. The main difference is in extensions: this patch allows much more singular/double extensions, both in terms of allowing them at lower depths and with lesser margins. Failed STC: https://tests.stockfishchess.org/tests/view/620d66643ec80158c0cd3b46 LLR: -2.94 (-2.94,2.94) <0.00,2.50> Total: 4968 W: 1194 L: 1398 D: 2376 Ptnml(0-2): 47, 633, 1294, 497, 13 Performed well at LTC in a fixed-length match: https://tests.stockfishchess.org/tests/view/620d66823ec80158c0cd3b4a ELO: 3.36 +-1.8 (95%) LOS: 100.0% Total: 30000 W: 7966 L: 7676 D: 14358 Ptnml(0-2): 36, 2936, 8755, 3248, 25 Passed VLTC SPRT test: https://tests.stockfishchess.org/tests/view/620da11a26f5b17ec884f939 LLR: 2.96 (-2.94,2.94) <0.50,3.00> Total: 4400 W: 1326 L: 1127 D: 1947 Ptnml(0-2): 13, 309, 1348, 526, 4 closes official-stockfish#3937 Bench: 6318903
1 parent 5f3e851 commit 499d711

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

src/search.cpp

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace {
6565

6666
// Futility margin
6767
Value futility_margin(Depth d, bool improving) {
68-
return Value(147 * (d - improving));
68+
return Value(168 * (d - improving));
6969
}
7070

7171
// Reductions lookup table, initialized at startup
@@ -75,9 +75,9 @@ namespace {
7575
int r = Reductions[d] * Reductions[mn];
7676

7777
if (rootDelta != 0)
78-
return (r + 1627 - int(delta) * 1024 / int(rootDelta)) / 1024 + (!i && r > 992);
78+
return (r + 1463 - int(delta) * 1024 / int(rootDelta)) / 1024 + (!i && r > 1010);
7979
else // SFplus: avoid divide by zero error
80-
return (r + 1627 - int(delta) * 1024) / 512 + (!i && r > 992); // 512 for rootDelta == 0.5
80+
return (r + 1463 - int(delta) * 1024) / 1024 + (!i && r > 1010); //leave it 1024
8181
}
8282

8383
constexpr int futility_move_count(bool improving, Depth depth) {
@@ -86,7 +86,7 @@ namespace {
8686

8787
// History and stats update bonus, based on depth
8888
int stat_bonus(Depth d) {
89-
return std::min((8 * d + 281) * d - 241 , 1949);
89+
return std::min((9 * d + 270) * d - 311 , 2145);
9090
}
9191

9292
// Add a small random component to draw evaluations to avoid 3-fold blindness
@@ -163,7 +163,7 @@ namespace {
163163
void Search::init() {
164164

165165
for (int i = 1; i < MAX_MOVES; ++i)
166-
Reductions[i] = int((21.14 + std::log(Threads.size()) / 2) * std::log(i));
166+
Reductions[i] = int((20.81 + std::log(Threads.size()) / 2) * std::log(i));
167167
}
168168

169169

@@ -346,10 +346,10 @@ void Thread::search() {
346346

347347
multiPV = std::min(multiPV, rootMoves.size());
348348

349-
complexityAverage.set(211, 1);
349+
complexityAverage.set(202, 1);
350350

351351
trend = SCORE_ZERO;
352-
optimism[ us] = Value(33);
352+
optimism[ us] = Value(39);
353353
optimism[~us] = -optimism[us];
354354

355355
int searchAgainCounter = 0;
@@ -419,16 +419,16 @@ void Thread::search() {
419419
if (rootDepth >= 4)
420420
{
421421
Value prev = rootMoves[pvIdx].averageScore;
422-
delta = Value(19) + int(prev) * prev / 18321;
422+
delta = Value(16) + int(prev) * prev / 19178;
423423
alpha = std::max(prev - delta,-VALUE_INFINITE);
424424
beta = std::min(prev + delta, VALUE_INFINITE);
425425

426426
// Adjust trend and optimism based on root move's previousScore
427-
int tr = sigmoid(prev, 4, 11, 92, 119, 1);
427+
int tr = sigmoid(prev, 3, 8, 90, 125, 1);
428428
trend = (us == WHITE ? make_score(tr, tr / 2)
429429
: -make_score(tr, tr / 2));
430430

431-
int opt = sigmoid(prev, 9, 18, 115, 12250, 187);
431+
int opt = sigmoid(prev, 8, 17, 144, 13966, 183);
432432
optimism[ us] = Value(opt);
433433
optimism[~us] = -optimism[us];
434434
}
@@ -529,17 +529,17 @@ void Thread::search() {
529529
&& !Threads.stop
530530
&& !mainThread->stopOnPonderhit)
531531
{
532-
double fallingEval = (66 + 12 * (mainThread->bestPreviousAverageScore - bestValue)
533-
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 809.70;
532+
double fallingEval = (69 + 12 * (mainThread->bestPreviousAverageScore - bestValue)
533+
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 781.4;
534534
fallingEval = std::clamp(fallingEval, 0.5, 1.5);
535535

536536
// If the bestMove is stable over several iterations, reduce time accordingly
537-
timeReduction = lastBestMoveDepth + 8 < completedDepth ? 1.73 : 0.94;
538-
double reduction = (1.66 + mainThread->previousTimeReduction) / (2.35 * timeReduction);
537+
timeReduction = lastBestMoveDepth + 10 < completedDepth ? 1.63 : 0.73;
538+
double reduction = (1.56 + mainThread->previousTimeReduction) / (2.20 * timeReduction);
539539
double bestMoveInstability = 1.073 + std::max(1.0, 2.25 - 9.9 / rootDepth)
540540
* totBestMoveChanges / Threads.size();
541541
int complexity = mainThread->complexityAverage.value();
542-
double complexPosition = std::clamp(1.0 + (complexity - 293) / 1525.0, 0.5, 1.5);
542+
double complexPosition = std::clamp(1.0 + (complexity - 326) / 1618.1, 0.5, 1.5);
543543

544544
double totalTime = Time.optimum() * fallingEval * reduction * bestMoveInstability * complexPosition;
545545

@@ -560,7 +560,7 @@ void Thread::search() {
560560
}
561561
else if ( Threads.increaseDepth
562562
&& !mainThread->ponder
563-
&& Time.elapsed() > totalTime * 0.49)
563+
&& Time.elapsed() > totalTime * 0.43)
564564
Threads.increaseDepth = false;
565565
else
566566
Threads.increaseDepth = true;
@@ -836,7 +836,7 @@ namespace {
836836
// margin and the improving flag are used in various pruning heuristics.
837837
improvement = (ss-2)->staticEval != VALUE_NONE ? ss->staticEval - (ss-2)->staticEval
838838
: (ss-4)->staticEval != VALUE_NONE ? ss->staticEval - (ss-4)->staticEval
839-
: 184;
839+
: 175;
840840

841841
improving = improvement > 0;
842842
complexity = abs(ss->staticEval - (us == WHITE ? eg_value(pos.psq_score()) : -eg_value(pos.psq_score())));
@@ -847,8 +847,8 @@ namespace {
847847
// If eval is really low check with qsearch if it can exceed alpha, if it can't,
848848
// return a fail low.
849849
if ( !PvNode
850-
&& depth <= 6
851-
&& eval < alpha - 486 - 314 * depth * depth)
850+
&& depth <= 7
851+
&& eval < alpha - 348 - 258 * depth * depth)
852852
{
853853
value = qsearch<NonPV>(pos, ss, alpha - 1, alpha);
854854
if (value < alpha)
@@ -861,24 +861,24 @@ namespace {
861861
&& depth < 8
862862
&& eval - futility_margin(depth, improving) - (ss-1)->statScore / 256 >= beta
863863
&& eval >= beta
864-
&& eval < 22266) // larger than VALUE_KNOWN_WIN, but smaller than TB wins.
864+
&& eval < 26305) // larger than VALUE_KNOWN_WIN, but smaller than TB wins.
865865
return eval;
866866

867867
// Step 9. Null move search with verification search (~22 Elo)
868868
if ( !PvNode
869869
&& (ss-1)->currentMove != MOVE_NULL
870-
&& (ss-1)->statScore < 15075
870+
&& (ss-1)->statScore < 14695
871871
&& eval >= beta
872872
&& eval >= ss->staticEval
873-
&& ss->staticEval >= beta - 18 * depth - improvement / 19 + 215 + complexity / 30
873+
&& ss->staticEval >= beta - 15 * depth - improvement / 15 + 198 + complexity / 28
874874
&& !excludedMove
875875
&& pos.non_pawn_material(us)
876876
&& (ss->ply >= thisThread->nmpMinPly || us != thisThread->nmpColor))
877877
{
878878
assert(eval - beta >= 0);
879879

880880
// Null move dynamic reduction based on depth, eval and complexity of position
881-
Depth R = std::min(int(eval - beta) / 184, 4) + depth / 3 + 4 - (complexity > 799);
881+
Depth R = std::min(int(eval - beta) / 147, 5) + depth / 3 + 4 - (complexity > 753);
882882

883883
ss->currentMove = MOVE_NULL;
884884
ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0];
@@ -914,7 +914,7 @@ namespace {
914914
}
915915
}
916916

917-
probCutBeta = beta + 204 - 52 * improving;
917+
probCutBeta = beta + 179 - 46 * improving;
918918

919919
// Step 10. ProbCut (~4 Elo)
920920
// If we have a good enough capture and a reduced search returns a value
@@ -990,7 +990,7 @@ namespace {
990990
moves_loop: // When in check, search starts here
991991

992992
// Step 12. A small Probcut idea, when we are in check (~0 Elo)
993-
probCutBeta = beta + 401;
993+
probCutBeta = beta + 481;
994994
if ( ss->inCheck
995995
&& !PvNode
996996
&& depth >= 2
@@ -1084,14 +1084,14 @@ namespace {
10841084
if ( !pos.empty(to_sq(move))
10851085
&& !givesCheck
10861086
&& !PvNode
1087-
&& lmrDepth < 7
1087+
&& lmrDepth < 6
10881088
&& !ss->inCheck
1089-
&& ss->staticEval + 424 + 138 * lmrDepth + PieceValue[EG][pos.piece_on(to_sq(move))]
1090-
+ captureHistory[movedPiece][to_sq(move)][type_of(pos.piece_on(to_sq(move)))] / 7 < alpha)
1089+
&& ss->staticEval + 281 + 179 * lmrDepth + PieceValue[EG][pos.piece_on(to_sq(move))]
1090+
+ captureHistory[movedPiece][to_sq(move)][type_of(pos.piece_on(to_sq(move)))] / 6 < alpha)
10911091
continue;
10921092

10931093
// SEE based pruning (~9 Elo)
1094-
if (!pos.see_ge(move, Value(-214) * depth))
1094+
if (!pos.see_ge(move, Value(-203) * depth))
10951095
continue;
10961096
}
10971097
else
@@ -1110,11 +1110,11 @@ namespace {
11101110
// Futility pruning: parent node (~9 Elo)
11111111
if ( !ss->inCheck
11121112
&& lmrDepth < 11
1113-
&& ss->staticEval + 147 + 125 * lmrDepth + history / 64 <= alpha)
1113+
&& ss->staticEval + 122 + 138 * lmrDepth + history / 60 <= alpha)
11141114
continue;
11151115

11161116
// Prune moves with negative SEE (~3 Elo)
1117-
if (!pos.see_ge(move, Value(-23 * lmrDepth * lmrDepth - 31 * lmrDepth)))
1117+
if (!pos.see_ge(move, Value(-25 * lmrDepth * lmrDepth - 20 * lmrDepth)))
11181118
continue;
11191119
}
11201120
}
@@ -1129,15 +1129,15 @@ namespace {
11291129
// a reduced search on all the other moves but the ttMove and if the
11301130
// result is lower than ttValue minus a margin, then we will extend the ttMove.
11311131
if ( !rootNode
1132-
&& depth >= 6 + 2 * (PvNode && tte->is_pv())
1132+
&& depth >= 4 + 2 * (PvNode && tte->is_pv())
11331133
&& move == ttMove
11341134
&& !excludedMove // Avoid recursive singular search
11351135
/* && ttValue != VALUE_NONE Already implicit in the next condition */
11361136
&& abs(ttValue) < VALUE_KNOWN_WIN
11371137
&& (tte->bound() & BOUND_LOWER)
11381138
&& tte->depth() >= depth - 3)
11391139
{
1140-
Value singularBeta = ttValue - 4 * depth;
1140+
Value singularBeta = ttValue - 3 * depth;
11411141
Depth singularDepth = (depth - 1) / 2;
11421142

11431143
ss->excludedMove = move;
@@ -1150,7 +1150,7 @@ namespace {
11501150

11511151
// Avoid search explosion by limiting the number of double extensions
11521152
if ( !PvNode
1153-
&& value < singularBeta - 52
1153+
&& value < singularBeta - 26
11541154
&& ss->doubleExtensions <= 8)
11551155
extension = 2;
11561156
}
@@ -1170,15 +1170,15 @@ namespace {
11701170

11711171
// Check extensions (~1 Elo)
11721172
else if ( givesCheck
1173-
&& depth > 8
1174-
&& abs(ss->staticEval) > 81)
1173+
&& depth > 9
1174+
&& abs(ss->staticEval) > 71)
11751175
extension = 1;
11761176

11771177
// Quiet ttMove extensions (~0 Elo)
11781178
else if ( PvNode
11791179
&& move == ttMove
11801180
&& move == ss->killers[0]
1181-
&& (*contHist[0])[movedPiece][to_sq(move)] >= 7546)
1181+
&& (*contHist[0])[movedPiece][to_sq(move)] >= 5491)
11821182
extension = 1;
11831183
}
11841184

@@ -1240,18 +1240,18 @@ namespace {
12401240
+ (*contHist[0])[movedPiece][to_sq(move)]
12411241
+ (*contHist[1])[movedPiece][to_sq(move)]
12421242
+ (*contHist[3])[movedPiece][to_sq(move)]
1243-
- 4123;
1243+
- 4334;
12441244

12451245
// Decrease/increase reduction for moves with a good/bad history (~30 Elo)
1246-
r -= ss->statScore / 17417;
1246+
r -= ss->statScore / 15914;
12471247

12481248
// In general we want to cap the LMR depth search at newDepth. But if reductions
12491249
// are really negative and movecount is low, we allow this move to be searched
12501250
// deeper than the first move (this may lead to hidden double extensions).
12511251
int deeper = r >= -1 ? 0
1252-
: moveCount <= 5 ? 2
1253-
: PvNode && depth > 3 ? 1
1254-
: cutNode && moveCount <= 7 ? 1
1252+
: moveCount <= 4 ? 2
1253+
: PvNode && depth > 4 ? 1
1254+
: cutNode && moveCount <= 8 ? 1
12551255
: 0;
12561256

12571257
Depth d = std::clamp(newDepth - r, 1, newDepth + deeper);
@@ -1260,7 +1260,7 @@ namespace {
12601260

12611261
// If the son is reduced and fails high it will be re-searched at full depth
12621262
doFullDepthSearch = value > alpha && d < newDepth;
1263-
doDeeperSearch = value > (alpha + 76 + 11 * (newDepth - d));
1263+
doDeeperSearch = value > (alpha + 78 + 11 * (newDepth - d));
12641264
didLMR = true;
12651265
}
12661266
else
@@ -1412,7 +1412,7 @@ namespace {
14121412
//or fail low was really bad
14131413
bool extraBonus = PvNode
14141414
|| cutNode
1415-
|| bestValue < alpha - 71 * depth;
1415+
|| bestValue < alpha - 70 * depth;
14161416

14171417
update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth) * (1 + extraBonus));
14181418
}
@@ -1543,7 +1543,7 @@ namespace {
15431543
if (PvNode && bestValue > alpha)
15441544
alpha = bestValue;
15451545

1546-
futilityBase = bestValue + 139;
1546+
futilityBase = bestValue + 118;
15471547
}
15481548

15491549
const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory,

0 commit comments

Comments
 (0)