Clean up corrhist

Passed Non-regression STC:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 89056 W: 23225 L: 23067 D: 42764
Ptnml(0-2): 292, 9688, 24470, 9726, 352
https://tests.stockfishchess.org/tests/view/679816b2ae346be6da0ee8e7

closes https://github.com/official-stockfish/Stockfish/pull/5830

Bench: 1767398
This commit is contained in:
Shawn Xu
2025-01-27 15:24:37 -08:00
committed by Disservin
parent f50d52aa7f
commit 4a77fb213f
2 changed files with 28 additions and 24 deletions
+2 -7
View File
@@ -133,20 +133,15 @@ using PawnHistory = Stats<std::int16_t, 8192, PAWN_HISTORY_SIZE, PIECE_NB, SQUAR
enum CorrHistType { enum CorrHistType {
Pawn, // By color and pawn structure Pawn, // By color and pawn structure
Minor, // By color and positions of minor pieces (Knight, Bishop) and King Minor, // By color and positions of minor pieces (Knight, Bishop) and King
NonPawn, // By Non-pawn material positions and color NonPawn, // By non-pawn material positions and color
PieceTo, // By [piece][to] move PieceTo, // By [piece][to] move
Continuation, // Combined history of move pairs Continuation, // Combined history of move pairs
}; };
namespace Detail { namespace Detail {
template<CorrHistType _> template<CorrHistType>
struct CorrHistTypedef { struct CorrHistTypedef {
using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;
};
template<>
struct CorrHistTypedef<NonPawn> {
using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, CORRECTION_HISTORY_SIZE, COLOR_NB>; using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, CORRECTION_HISTORY_SIZE, COLOR_NB>;
}; };
+26 -17
View File
@@ -83,11 +83,11 @@ constexpr int futility_move_count(bool improving, Depth depth) {
return (3 + depth * depth) / (2 - improving); return (3 + depth * depth) / (2 - improving);
} }
int correction_value(const Worker& w, const Position& pos, const Stack* ss) { int correction_value(const Worker& w, const Position& pos, const Stack* const ss) {
const Color us = pos.side_to_move(); const Color us = pos.side_to_move();
const auto m = (ss - 1)->currentMove; const auto m = (ss - 1)->currentMove;
const auto pcv = w.pawnCorrectionHistory[us][pawn_structure_index<Correction>(pos)]; const auto pcv = w.pawnCorrectionHistory[pawn_structure_index<Correction>(pos)][us];
const auto micv = w.minorPieceCorrectionHistory[us][minor_piece_index(pos)]; const auto micv = w.minorPieceCorrectionHistory[minor_piece_index(pos)][us];
const auto wnpcv = w.nonPawnCorrectionHistory[WHITE][non_pawn_index<WHITE>(pos)][us]; const auto wnpcv = w.nonPawnCorrectionHistory[WHITE][non_pawn_index<WHITE>(pos)][us];
const auto bnpcv = w.nonPawnCorrectionHistory[BLACK][non_pawn_index<BLACK>(pos)][us]; const auto bnpcv = w.nonPawnCorrectionHistory[BLACK][non_pawn_index<BLACK>(pos)][us];
const auto cntcv = const auto cntcv =
@@ -99,10 +99,31 @@ int correction_value(const Worker& w, const Position& pos, const Stack* ss) {
// Add correctionHistory value to raw staticEval and guarantee evaluation // Add correctionHistory value to raw staticEval and guarantee evaluation
// does not hit the tablebase range. // does not hit the tablebase range.
Value to_corrected_static_eval(Value v, const int cv) { Value to_corrected_static_eval(const Value v, const int cv) {
return std::clamp(v + cv / 131072, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1); return std::clamp(v + cv / 131072, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);
} }
void update_correction_history(const Position& pos,
Stack* const ss,
Search::Worker& workerThread,
const int bonus) {
const Move m = (ss - 1)->currentMove;
const Color us = pos.side_to_move();
static constexpr int nonPawnWeight = 165;
workerThread.pawnCorrectionHistory[pawn_structure_index<Correction>(pos)][us]
<< bonus * 114 / 128;
workerThread.minorPieceCorrectionHistory[minor_piece_index(pos)][us] << bonus * 146 / 128;
workerThread.nonPawnCorrectionHistory[WHITE][non_pawn_index<WHITE>(pos)][us]
<< bonus * nonPawnWeight / 128;
workerThread.nonPawnCorrectionHistory[BLACK][non_pawn_index<BLACK>(pos)][us]
<< bonus * nonPawnWeight / 128;
if (m.is_ok())
(*(ss - 2)->continuationCorrectionHistory)[pos.piece_on(m.to_sq())][m.to_sq()] << bonus;
}
// History and stats update bonus, based on depth // History and stats update bonus, based on depth
int stat_bonus(Depth d) { return std::min(154 * d - 102, 1661); } int stat_bonus(Depth d) { return std::min(154 * d - 102, 1661); }
@@ -1429,21 +1450,9 @@ moves_loop: // When in check, search starts here
&& ((bestValue < ss->staticEval && bestValue < beta) // negative correction & no fail high && ((bestValue < ss->staticEval && bestValue < beta) // negative correction & no fail high
|| (bestValue > ss->staticEval && bestMove))) // positive correction & no fail low || (bestValue > ss->staticEval && bestMove))) // positive correction & no fail low
{ {
const auto m = (ss - 1)->currentMove;
constexpr int nonPawnWeight = 165;
auto bonus = std::clamp(int(bestValue - ss->staticEval) * depth / 8, auto bonus = std::clamp(int(bestValue - ss->staticEval) * depth / 8,
-CORRECTION_HISTORY_LIMIT / 4, CORRECTION_HISTORY_LIMIT / 4); -CORRECTION_HISTORY_LIMIT / 4, CORRECTION_HISTORY_LIMIT / 4);
thisThread->pawnCorrectionHistory[us][pawn_structure_index<Correction>(pos)] update_correction_history(pos, ss, *thisThread, bonus);
<< bonus * 114 / 128;
thisThread->minorPieceCorrectionHistory[us][minor_piece_index(pos)] << bonus * 146 / 128;
thisThread->nonPawnCorrectionHistory[WHITE][non_pawn_index<WHITE>(pos)][us]
<< bonus * nonPawnWeight / 128;
thisThread->nonPawnCorrectionHistory[BLACK][non_pawn_index<BLACK>(pos)][us]
<< bonus * nonPawnWeight / 128;
if (m.is_ok())
(*(ss - 2)->continuationCorrectionHistory)[pos.piece_on(m.to_sq())][m.to_sq()] << bonus;
} }
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);