Skip to content

Commit 726c3d7

Browse files
authored
Merge pull request #1540 from IIvec/master-1
Big search tuning
2 parents 8b86e31 + ac80938 commit 726c3d7

File tree

1 file changed

+45
-46
lines changed

1 file changed

+45
-46
lines changed

src/search.cpp

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace {
6363

6464
// Futility margin
6565
Value futility_margin(Depth d, bool improving) {
66-
return Value(214 * (d - improving));
66+
return Value(171 * (d - improving));
6767
}
6868

6969
// Reductions lookup table, initialized at startup
@@ -72,7 +72,7 @@ namespace {
7272

7373
Depth reduction(bool i, Depth d, int mn, Value delta, Value rootDelta) {
7474
int r = DReductions[d] * MReductions[mn];
75-
return (r + 1358 - int(delta) * 1024 / int(rootDelta)) / 1024 + (!i && r > 904);
75+
return (r + 1575 - int(delta) * 1024 / int(rootDelta)) / 1024 + (!i && r > 1011);
7676
}
7777

7878
constexpr int futility_move_count(bool improving, Depth depth) {
@@ -81,7 +81,7 @@ namespace {
8181

8282
// History and stats update bonus, based on depth
8383
int stat_bonus(Depth d) {
84-
return std::min((d + 100) * d - 81 , 2000);
84+
return std::min((d + 100) * d - 46 , 1990);
8585
}
8686

8787
// Add a small random component to draw evaluations to avoid 3-fold blindness
@@ -308,10 +308,10 @@ void Thread::search() {
308308

309309
multiPV = std::min(multiPV, rootMoves.size());
310310

311-
complexityAverage.set(232, 1);
311+
complexityAverage.set(190, 1);
312312

313313
trend = SCORE_ZERO;
314-
optimism[ us] = Value(25);
314+
optimism[ us] = Value(34);
315315
optimism[~us] = -optimism[us];
316316

317317
int searchAgainCounter = 0;
@@ -360,11 +360,11 @@ void Thread::search() {
360360
beta = std::min(prev + delta2, VALUE_INFINITE);
361361

362362
// Adjust trend and optimism based on root move's previousScore
363-
int tr = sigmoid(prev, 0, 0, 147, 113, 1);
363+
int tr = sigmoid(prev, 6, 13, 96, 110, 1);
364364
trend = (us == WHITE ? make_score(tr, tr / 2)
365365
: -make_score(tr, tr / 2));
366366

367-
int opt = sigmoid(prev, 0, 25, 147, 14464, 256);
367+
int opt = sigmoid(prev, 7, 21, 94, 14786, 221);
368368
optimism[ us] = Value(opt);
369369
optimism[~us] = -optimism[us];
370370
}
@@ -419,8 +419,8 @@ void Thread::search() {
419419
else
420420
break;
421421

422-
delta1 += delta1 / 2;
423-
delta2 += delta2 / 2;
422+
delta1 += delta1 / 4 + 3;
423+
delta2 += delta2 / 4 + 3;
424424

425425
assert(alpha >= -VALUE_INFINITE && beta <= VALUE_INFINITE);
426426
}
@@ -466,17 +466,17 @@ void Thread::search() {
466466
&& !Threads.stop
467467
&& !mainThread->stopOnPonderhit)
468468
{
469-
double fallingEval = (142 + 12 * (mainThread->bestPreviousAverageScore - bestValue)
470-
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 825.0;
469+
double fallingEval = (87 + 12 * (mainThread->bestPreviousAverageScore - bestValue)
470+
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 777.20;
471471
fallingEval = std::clamp(fallingEval, 0.5, 1.5);
472472

473473
// If the bestMove is stable over several iterations, reduce time accordingly
474-
timeReduction = lastBestMoveDepth + 9 < completedDepth ? 1.92 : 0.95;
475-
double reduction = (1.47 + mainThread->previousTimeReduction) / (2.32 * timeReduction);
474+
timeReduction = lastBestMoveDepth + 8 < completedDepth ? 1.70 : 0.91;
475+
double reduction = (1.59 + mainThread->previousTimeReduction) / (2.33 * timeReduction);
476476
double bestMoveInstability = 1.073 + std::max(1.0, 2.25 - 9.9 / rootDepth)
477477
* totBestMoveChanges / Threads.size();
478478
int complexity = mainThread->complexityAverage.value();
479-
double complexPosition = std::clamp(1.0 + (complexity - 232) / 1750.0, 0.5, 1.5);
479+
double complexPosition = std::clamp(1.0 + (complexity - 312) / 1750.0, 0.5, 1.5);
480480

481481
double totalTime = Time.optimum() * fallingEval * reduction * bestMoveInstability * complexPosition;
482482

@@ -497,7 +497,7 @@ void Thread::search() {
497497
}
498498
else if ( Threads.increaseDepth
499499
&& !mainThread->ponder
500-
&& Time.elapsed() > totalTime * 0.58)
500+
&& Time.elapsed() > totalTime * 0.55)
501501
Threads.increaseDepth = false;
502502
else
503503
Threads.increaseDepth = true;
@@ -795,19 +795,19 @@ namespace {
795795
// Step 8. Futility pruning: child node (~25 Elo).
796796
// The depth condition is important for mate finding.
797797
if ( !ss->ttPv
798-
&& depth < 9
798+
&& depth < 8
799799
&& eval - futility_margin(depth, improving) - (ss-1)->statScore / 256 >= beta
800800
&& eval >= beta
801-
&& eval < 15000) // 50% larger than VALUE_KNOWN_WIN, but smaller than TB wins.
801+
&& eval < 17548) // 50% larger than VALUE_KNOWN_WIN, but smaller than TB wins.
802802
return eval;
803803

804804
// Step 9. Null move search with verification search (~22 Elo)
805805
if ( !PvNode
806806
&& (ss-1)->currentMove != MOVE_NULL
807-
&& (ss-1)->statScore < 23767
807+
&& (ss-1)->statScore < 13706
808808
&& eval >= beta
809809
&& eval >= ss->staticEval
810-
&& ss->staticEval >= beta - 20 * depth - improvement / 15 + 204 + complexity / 25
810+
&& ss->staticEval >= beta - 19 * depth - improvement / 15 + 200 + complexity / 25
811811
&& !excludedMove
812812
&& thisThread->selDepth + 5 > thisThread->rootDepth
813813
&& pos.non_pawn_material(us) > BishopValueMg
@@ -852,13 +852,13 @@ namespace {
852852
}
853853
}
854854

855-
probCutBeta = beta + 209 - 44 * improving;
855+
probCutBeta = beta + 229 - 47 * improving;
856856

857857
// Step 10. ProbCut (~4 Elo)
858858
// If we have a good enough capture and a reduced search returns a value
859859
// much above beta, we can (almost) safely prune the previous move.
860860
if ( !PvNode
861-
&& depth > 4
861+
&& depth > 3
862862
&& abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
863863
// if value from transposition table is lower than probCutBeta, don't attempt probCut
864864
// there and in further interactions with transposition table cutoff depth is set to depth - 3
@@ -879,7 +879,6 @@ namespace {
879879
if (move != excludedMove && pos.legal(move))
880880
{
881881
assert(pos.capture_or_promotion(move));
882-
assert(depth >= 5);
883882

884883
captureOrPromotion = true;
885884

@@ -917,19 +916,19 @@ namespace {
917916

918917
// Step 11. If the position is not in TT, decrease depth by 2 or 1 depending on node type (~3 Elo)
919918
if ( PvNode
920-
&& depth >= 6
919+
&& depth >= 4
921920
&& !ttMove)
922921
depth -= 2;
923922

924923
if ( cutNode
925-
&& depth >= 9
924+
&& depth >= 7
926925
&& !ttMove)
927926
depth--;
928927

929928
moves_loop: // When in check, search starts here
930929

931930
// Step 12. A small Probcut idea, when we are in check (~0 Elo)
932-
probCutBeta = beta + 409;
931+
probCutBeta = beta + 401;
933932
if ( ss->inCheck
934933
&& !PvNode
935934
&& depth >= 4
@@ -1025,12 +1024,12 @@ namespace {
10251024
&& !PvNode
10261025
&& lmrDepth < 6
10271026
&& !ss->inCheck
1028-
&& ss->staticEval + 342 + 238 * lmrDepth + PieceValue[EG][pos.piece_on(to_sq(move))]
1027+
&& ss->staticEval + 392 + 207 * lmrDepth + PieceValue[EG][pos.piece_on(to_sq(move))]
10291028
+ captureHistory[movedPiece][to_sq(move)][type_of(pos.piece_on(to_sq(move)))] / 8 < alpha)
10301029
continue;
10311030

10321031
// SEE based pruning (~9 Elo)
1033-
if (!pos.see_ge(move, Value(-217) * depth))
1032+
if (!pos.see_ge(move, Value(-200) * depth))
10341033
continue;
10351034
}
10361035
else
@@ -1048,12 +1047,12 @@ namespace {
10481047

10491048
// Futility pruning: parent node (~9 Elo)
10501049
if ( !ss->inCheck
1051-
&& lmrDepth < 8
1052-
&& ss->staticEval + 138 + 137 * lmrDepth + history / 64 <= alpha)
1050+
&& lmrDepth < 11
1051+
&& ss->staticEval + 131 + 137 * lmrDepth + history / 64 <= alpha)
10531052
continue;
10541053

10551054
// Prune moves with negative SEE (~3 Elo)
1056-
if (!pos.see_ge(move, Value(-21 * lmrDepth * lmrDepth - 21 * lmrDepth)))
1055+
if (!pos.see_ge(move, Value(-25 * lmrDepth * lmrDepth - 29 * lmrDepth)))
10571056
continue;
10581057
}
10591058
}
@@ -1089,7 +1088,7 @@ namespace {
10891088

10901089
// Avoid search explosion by limiting the number of double extensions
10911090
if ( !PvNode
1092-
&& value < singularBeta - 75
1091+
&& value < singularBeta - 71
10931092
&& ss->doubleExtensions <= 6)
10941093
extension = 2;
10951094
}
@@ -1109,15 +1108,15 @@ namespace {
11091108

11101109
// Check extensions (~1 Elo)
11111110
else if ( givesCheck
1112-
&& depth > 6
1113-
&& abs(ss->staticEval) > 100)
1111+
&& depth > 7
1112+
&& abs(ss->staticEval) > 128)
11141113
extension = 1;
11151114

11161115
// Quiet ttMove extensions (~0 Elo)
11171116
else if ( PvNode
11181117
&& move == ttMove
11191118
&& move == ss->killers[0]
1120-
&& (*contHist[0])[movedPiece][to_sq(move)] >= 10000)
1119+
&& (*contHist[0])[movedPiece][to_sq(move)] >= 8932)
11211120
extension = 1;
11221121
}
11231122

@@ -1144,8 +1143,8 @@ namespace {
11441143
// We use various heuristics for the sons of a node after the first son has
11451144
// been searched. In general we would like to reduce them, but there are many
11461145
// cases where we extend a son if it has good chances to be "interesting".
1147-
if ( depth >= 3
1148-
&& moveCount > 1 + 2 * rootNode
1146+
if ( depth >= 2
1147+
&& moveCount > 1 + rootNode
11491148
&& ( !ss->ttPv
11501149
|| !captureOrPromotion
11511150
|| (cutNode && (ss-1)->moveCount > 1)))
@@ -1154,7 +1153,7 @@ namespace {
11541153

11551154
// Decrease reduction at some PvNodes (~2 Elo)
11561155
if ( PvNode
1157-
&& bestMoveCount <= 3)
1156+
&& bestMoveCount <= 4)
11581157
r--;
11591158

11601159
// Decrease reduction if position is or has been on the PV
@@ -1164,7 +1163,7 @@ namespace {
11641163
r -= 2;
11651164

11661165
// Decrease reduction if opponent's move count is high (~1 Elo)
1167-
if ((ss-1)->moveCount > 13)
1166+
if ((ss-1)->moveCount > 7)
11681167
r--;
11691168

11701169
// Increase reduction for cut nodes (~3 Elo)
@@ -1179,18 +1178,18 @@ namespace {
11791178
+ (*contHist[0])[movedPiece][to_sq(move)]
11801179
+ (*contHist[1])[movedPiece][to_sq(move)]
11811180
+ (*contHist[3])[movedPiece][to_sq(move)]
1182-
- 4923;
1181+
- 4142;
11831182

11841183
// Decrease/increase reduction for moves with a good/bad history (~30 Elo)
1185-
r -= ss->statScore / 14721;
1184+
r -= ss->statScore / 15328;
11861185

11871186
// In general we want to cap the LMR depth search at newDepth. But if reductions
11881187
// are really negative and movecount is low, we allow this move to be searched
11891188
// deeper than the first move (this may lead to hidden double extensions).
11901189
int deeper = r >= -1 ? 0
11911190
: moveCount <= 5 ? 2
1192-
: PvNode && depth > 6 ? 1
1193-
: cutNode && moveCount <= 7 ? 1
1191+
: PvNode && depth > 4 ? 1
1192+
: cutNode && moveCount <= 5 ? 1
11941193
: 0;
11951194

11961195
Depth d = std::clamp(newDepth - r, 1, newDepth + deeper);
@@ -1199,7 +1198,7 @@ namespace {
11991198

12001199
// If the son is reduced and fails high it will be re-searched at full depth
12011200
doFullDepthSearch = value > alpha && d < newDepth;
1202-
doDeeperSearch = value > (alpha + 62 + 20 * (newDepth - d));
1201+
doDeeperSearch = value > (alpha + 80 + 20 * (newDepth - d));
12031202
didLMR = true;
12041203
}
12051204
else
@@ -1220,7 +1219,7 @@ namespace {
12201219
: -stat_bonus(newDepth);
12211220

12221221
if (captureOrPromotion)
1223-
bonus /= 4;
1222+
bonus /= 5;
12241223

12251224
update_continuation_histories(ss, movedPiece, to_sq(move), bonus);
12261225
}
@@ -1351,7 +1350,7 @@ namespace {
13511350
//or fail low was really bad
13521351
bool extraBonus = PvNode
13531352
|| cutNode
1354-
|| bestValue < alpha - 94 * depth;
1353+
|| bestValue < alpha - 99 * depth;
13551354

13561355
update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth) * (1 + extraBonus));
13571356
}
@@ -1482,7 +1481,7 @@ namespace {
14821481
if (PvNode && bestValue > alpha)
14831482
alpha = bestValue;
14841483

1485-
futilityBase = bestValue + 155;
1484+
futilityBase = bestValue + 127;
14861485
}
14871486

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

0 commit comments

Comments
 (0)