diff --git a/include/search/eval_correction_history.h b/include/search/eval_correction_history.h index 5491664..fb9ca82 100644 --- a/include/search/eval_correction_history.h +++ b/include/search/eval_correction_history.h @@ -40,12 +40,12 @@ struct eval_correction_history { return raw_correction / eval_correction_scale; } - constexpr void update(const zobrist::quarter_hash_type& feature_hash, const score_type& error) noexcept { + constexpr void update(const zobrist::quarter_hash_type& feature_hash, const score_type& error, const score_type& alpha) noexcept { constexpr score_type score_correction_limit = 65536; + constexpr score_type filter_divisor = 256; - constexpr score_type filter_alpha = 1; - constexpr score_type filter_c_alpha = 255; - constexpr score_type filter_divisor = filter_alpha + filter_c_alpha; + const score_type filter_alpha = alpha; + const score_type filter_c_alpha = filter_divisor - alpha; auto& correction = data[hash_function(feature_hash)]; @@ -71,6 +71,18 @@ template template struct composite_eval_correction_history { + static constexpr depth_type lookup_table_size = 32; + + static constexpr std::array alpha_lookup_table = [] { + std::array result{}; + for (depth_type depth{1}; depth < lookup_table_size; ++depth) { + const double alpha_value = 1.0 - 1.0 / (1.0 + static_cast(depth) / 8.0); + result[depth] = static_cast(16.0 * alpha_value); + } + + return result; + }(); + std::array histories_{}; [[nodiscard]] constexpr score_type correction_for(const composite_feature_hash& composite_hash) const noexcept { @@ -84,13 +96,16 @@ struct composite_eval_correction_history { return result; } - constexpr void update(const composite_feature_hash& composite_hash, const bound_type& bound, const score_type& error) noexcept { + constexpr void update(const composite_feature_hash& composite_hash, const bound_type& bound, const score_type& error, const depth_type& depth) noexcept { if (bound == bound_type::upper && error >= 0) { return; } if (bound == bound_type::lower && error <= 0) { return; } + constexpr depth_type last_idx = lookup_table_size - 1; + const score_type alpha = alpha_lookup_table[std::min(last_idx, depth)]; + for (std::size_t i(0); i < N; ++i) { const zobrist::quarter_hash_type hash = composite_hash.hash(i); - histories_[i].update(hash, error); + histories_[i].update(hash, error, alpha); } } diff --git a/src/search/search_worker.cc b/src/search/search_worker.cc index b9c706d..b4823ff 100644 --- a/src/search/search_worker.cc +++ b/src/search/search_worker.cc @@ -477,7 +477,7 @@ pv_search_result_t search_worker::pv_search( if (!is_check && best_move.is_quiet()) { const score_type error = best_score - static_value; - internal.correction.us(bd.turn()).update(feature_hash, bound, error); + internal.correction.us(bd.turn()).update(feature_hash, bound, error, depth); } const transposition_table_entry entry(bd.hash(), bound, best_score, best_move, depth, tt_pv);