mirror of
https://github.com/sockspls/badfish
synced 2025-07-14 21:19:13 +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:
parent
6c02329860
commit
0fbad56c50
1 changed files with 10 additions and 35 deletions
|
@ -62,8 +62,10 @@ constexpr int futility_move_count(bool improving, Depth depth) {
|
||||||
return improving ? (3 + depth * depth) : (3 + depth * depth) / 2;
|
return improving ? (3 + depth * depth) : (3 + depth * depth) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guarantee evaluation does not hit the tablebase range
|
// Add correctionHistory value to raw staticEval and guarantee evaluation does not hit the tablebase range
|
||||||
constexpr Value to_static_eval(const Value v) {
|
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);
|
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)
|
else if (PvNode)
|
||||||
Eval::NNUE::hint_common_parent_position(pos);
|
Eval::NNUE::hint_common_parent_position(pos);
|
||||||
|
|
||||||
Value newEval =
|
ss->staticEval = eval = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
|
||||||
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);
|
|
||||||
|
|
||||||
// ttValue can be used as a better position evaluation (~7 Elo)
|
// ttValue can be used as a better position evaluation (~7 Elo)
|
||||||
if (ttValue != VALUE_NONE && (tte->bound() & (ttValue > eval ? BOUND_LOWER : BOUND_UPPER)))
|
if (ttValue != VALUE_NONE && (tte->bound() & (ttValue > eval ? BOUND_LOWER : BOUND_UPPER)))
|
||||||
|
@ -762,14 +758,7 @@ Value Search::Worker::search(
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]);
|
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]);
|
||||||
|
ss->staticEval = eval = to_corrected_static_eval(unadjustedStaticEval, *thisThread, 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);
|
|
||||||
|
|
||||||
// Static evaluation is saved as it was before adjustment by correction history
|
// 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(),
|
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)
|
if ((unadjustedStaticEval = ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
|
||||||
unadjustedStaticEval = ss->staticEval = bestValue =
|
unadjustedStaticEval = ss->staticEval = bestValue =
|
||||||
evaluate(pos, thisThread->optimism[us]);
|
evaluate(pos, thisThread->optimism[us]);
|
||||||
|
ss->staticEval = bestValue =
|
||||||
Value newEval =
|
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
|
||||||
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);
|
|
||||||
|
|
||||||
// ttValue can be used as a better position evaluation (~13 Elo)
|
// ttValue can be used as a better position evaluation (~13 Elo)
|
||||||
if (ttValue != VALUE_NONE
|
if (ttValue != VALUE_NONE
|
||||||
|
@ -1534,15 +1516,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
|
||||||
unadjustedStaticEval = ss->staticEval = bestValue =
|
unadjustedStaticEval = ss->staticEval = bestValue =
|
||||||
(ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us])
|
(ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us])
|
||||||
: -(ss - 1)->staticEval;
|
: -(ss - 1)->staticEval;
|
||||||
|
ss->staticEval = bestValue =
|
||||||
Value newEval =
|
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stand pat. Return immediately if static value is at least beta
|
// Stand pat. Return immediately if static value is at least beta
|
||||||
|
|
Loading…
Add table
Reference in a new issue