1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Refactor code for correcting unadjustedStaticEval

Passed non-regression STC:
https://tests.stockfishchess.org/tests/live_elo/65a4df6a79aa8af82b970ca0
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 43328 W: 11103 L: 10892 D: 21333
Ptnml(0-2): 120, 4920, 11407, 5063, 154

https://github.com/official-stockfish/Stockfish/pull/4992

No functional change
This commit is contained in:
pb00067 2024-01-15 15:32:06 +01:00 committed by Disservin
parent 6c02329860
commit 0fbad56c50

View file

@ -62,8 +62,10 @@ constexpr int futility_move_count(bool improving, Depth depth) {
return improving ? (3 + depth * depth) : (3 + depth * depth) / 2;
}
// Guarantee evaluation does not hit the tablebase range
constexpr Value to_static_eval(const Value v) {
// Add correctionHistory value to raw staticEval and guarantee evaluation does not hit the tablebase range
Value to_corrected_static_eval(Value v, const Worker& w, const Position& pos) {
auto cv = w.correctionHistory[pos.side_to_move()][pawn_structure_index<Correction>(pos)];
v += cv * std::abs(cv) / 16384;
return std::clamp(int(v), VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);
}
@ -747,13 +749,7 @@ Value Search::Worker::search(
else if (PvNode)
Eval::NNUE::hint_common_parent_position(pos);
Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;
ss->staticEval = eval = to_static_eval(newEval);
ss->staticEval = eval = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
// ttValue can be used as a better position evaluation (~7 Elo)
if (ttValue != VALUE_NONE && (tte->bound() & (ttValue > eval ? BOUND_LOWER : BOUND_UPPER)))
@ -762,14 +758,7 @@ Value Search::Worker::search(
else
{
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]);
Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;
ss->staticEval = eval = to_static_eval(newEval);
ss->staticEval = eval = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
// Static evaluation is saved as it was before adjustment by correction history
tte->save(posKey, VALUE_NONE, ss->ttPv, BOUND_NONE, DEPTH_NONE, Move::none(),
@ -1513,15 +1502,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
if ((unadjustedStaticEval = ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
unadjustedStaticEval = ss->staticEval = bestValue =
evaluate(pos, thisThread->optimism[us]);
Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(
thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;
ss->staticEval = bestValue = to_static_eval(newEval);
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
// ttValue can be used as a better position evaluation (~13 Elo)
if (ttValue != VALUE_NONE
@ -1534,15 +1516,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
unadjustedStaticEval = ss->staticEval = bestValue =
(ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us])
: -(ss - 1)->staticEval;
Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(
thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;
ss->staticEval = bestValue = to_static_eval(newEval);
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
}
// Stand pat. Return immediately if static value is at least beta