Skip to content

Commit 16b4578

Browse files
locutus2vondele
authored andcommitted
Tweak hybrid treshold.
Increase the first hybrid threshold with more material. Rewrite the hybrid rules for clarity. STC: LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 24416 W: 3039 L: 2848 D: 18529 Ptnml(0-2): 135, 2136, 7503, 2271, 163 https://tests.stockfishchess.org/tests/view/5f6451efbb0cae038ca8f4dc LTC; LLR: 2.95 (-2.94,2.94) {0.25,1.25} Total: 65016 W: 3702 L: 3455 D: 57859 Ptnml(0-2): 66, 2991, 26157, 3218, 76 https://tests.stockfishchess.org/tests/view/5f64b143bb0cae038ca8f51f closes #3140 Bench: 3973739
1 parent 8559c43 commit 16b4578

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/evaluate.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,20 +1015,28 @@ namespace {
10151015

10161016
Value Eval::evaluate(const Position& pos) {
10171017

1018-
// Use classical eval if there is a large imbalance
1019-
// If there is a moderate imbalance, use classical eval with probability (1/8),
1020-
// as derived from the node counter.
1021-
bool useClassical = abs(eg_value(pos.psq_score())) * 16 > NNUEThreshold1 * (16 + pos.rule50_count());
1022-
bool classical = !Eval::useNNUE
1023-
|| useClassical
1024-
|| (abs(eg_value(pos.psq_score())) > PawnValueMg / 4 && !(pos.this_thread()->nodes & 0xB));
1025-
Value v = classical ? Evaluation<NO_TRACE>(pos).value()
1026-
: NNUE::evaluate(pos) * 5 / 4 + Tempo;
1027-
1028-
if ( useClassical
1029-
&& Eval::useNNUE
1030-
&& abs(v) * 16 < NNUEThreshold2 * (16 + pos.rule50_count()))
1031-
v = NNUE::evaluate(pos) * 5 / 4 + Tempo;
1018+
Value v;
1019+
1020+
if (!Eval::useNNUE)
1021+
v = Evaluation<NO_TRACE>(pos).value();
1022+
else
1023+
{
1024+
// scale and shift NNUE for compatibility with search and classical evaluation
1025+
auto adjusted_NNUE = [&](){ return NNUE::evaluate(pos) * 5 / 4 + Tempo; };
1026+
1027+
// if there is PSQ imbalance use classical eval, with small probability if it is small
1028+
Value psq = Value(abs(eg_value(pos.psq_score())));
1029+
int r50 = 16 + pos.rule50_count();
1030+
bool largePsq = psq * 16 > (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50;
1031+
bool classical = largePsq || (psq > PawnValueMg / 4 && !(pos.this_thread()->nodes & 0xB));
1032+
1033+
v = classical ? Evaluation<NO_TRACE>(pos).value() : adjusted_NNUE();
1034+
1035+
// if the classical eval is small and imbalance large, use NNUE nevertheless.
1036+
if ( largePsq
1037+
&& abs(v) * 16 < NNUEThreshold2 * r50)
1038+
v = adjusted_NNUE();
1039+
}
10321040

10331041
// Damp down the evaluation linearly when shuffling
10341042
v = v * (100 - pos.rule50_count()) / 100;

0 commit comments

Comments
 (0)