diff --git a/src/history.h b/src/history.h index 654ee19f..bec055d5 100644 --- a/src/history.h +++ b/src/history.h @@ -133,20 +133,15 @@ using PawnHistory = Stats +template struct CorrHistTypedef { - using type = Stats; -}; - -template<> -struct CorrHistTypedef { using type = Stats; }; diff --git a/src/search.cpp b/src/search.cpp index 9a5425fc..89233e85 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -83,11 +83,11 @@ constexpr int futility_move_count(bool improving, Depth depth) { 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 auto m = (ss - 1)->currentMove; - const auto pcv = w.pawnCorrectionHistory[us][pawn_structure_index(pos)]; - const auto micv = w.minorPieceCorrectionHistory[us][minor_piece_index(pos)]; + const auto pcv = w.pawnCorrectionHistory[pawn_structure_index(pos)][us]; + const auto micv = w.minorPieceCorrectionHistory[minor_piece_index(pos)][us]; const auto wnpcv = w.nonPawnCorrectionHistory[WHITE][non_pawn_index(pos)][us]; const auto bnpcv = w.nonPawnCorrectionHistory[BLACK][non_pawn_index(pos)][us]; 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 // 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); } +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(pos)][us] + << bonus * 114 / 128; + workerThread.minorPieceCorrectionHistory[minor_piece_index(pos)][us] << bonus * 146 / 128; + workerThread.nonPawnCorrectionHistory[WHITE][non_pawn_index(pos)][us] + << bonus * nonPawnWeight / 128; + workerThread.nonPawnCorrectionHistory[BLACK][non_pawn_index(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 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 && 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, -CORRECTION_HISTORY_LIMIT / 4, CORRECTION_HISTORY_LIMIT / 4); - thisThread->pawnCorrectionHistory[us][pawn_structure_index(pos)] - << bonus * 114 / 128; - thisThread->minorPieceCorrectionHistory[us][minor_piece_index(pos)] << bonus * 146 / 128; - thisThread->nonPawnCorrectionHistory[WHITE][non_pawn_index(pos)][us] - << bonus * nonPawnWeight / 128; - thisThread->nonPawnCorrectionHistory[BLACK][non_pawn_index(pos)][us] - << bonus * nonPawnWeight / 128; - - if (m.is_ok()) - (*(ss - 2)->continuationCorrectionHistory)[pos.piece_on(m.to_sq())][m.to_sq()] << bonus; + update_correction_history(pos, ss, *thisThread, bonus); } assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);