From 688bb1379a3005bc33e57924b01d3d1a53f39192 Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Thu, 25 Dec 2025 02:46:26 +0100 Subject: [PATCH 1/2] Fix merge of eren patch and more tunables Bench: 13074664 --- src/search.cpp | 17 +++++++++-------- src/tm.cpp | 22 ++++++++++++++++------ src/tuned.hpp | 20 +++++++++++++++++--- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 05be3580..f03bda9d 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -472,9 +472,10 @@ Value Worker::search( } if (!PV_NODE && !is_in_check && !pos.is_kp_endgame() && depth >= tuned::nmp_depth && !excluded - && tt_adjusted_eval >= beta + 30 && !is_being_mated_score(beta) && !m_in_nmp_verification) { - int R = - tuned::nmp_base_r + depth / 4 + std::min(3, (tt_adjusted_eval - beta) / 400) + improving; + && tt_adjusted_eval >= beta + tuned::nmp_beta_margin && !is_being_mated_score(beta) + && !m_in_nmp_verification) { + int R = tuned::nmp_base_r + depth / 4 + + std::min(3, (tt_adjusted_eval - beta) / tuned::nmp_beta_diff) + improving; Position pos_after = pos.null_move(); repetition_info.push(pos_after.get_hash_key(), true); @@ -629,16 +630,16 @@ Value Worker::search( extension = 1; // Double Extension - int double_margin = - tuned::sing_double_margin - (move_history / tuned::sing_hist_div * quiet); + Value double_margin = + tuned::dext_margin - (move_history / tuned::dext_hist_div * quiet); if (!PV_NODE && singular_value <= singular_beta - double_margin) { extension = 2; } // Triple Extension - int triple_margin = tuned::sing_triple_margin - (move_history / 512 * quiet); - if (!PV_NODE && quiet - && singular_value <= singular_beta - tuned::sing_triple_margin) { + Value triple_margin = + tuned::triext_margin - (move_history / tuned::triext_hist_div * quiet); + if (!PV_NODE && quiet && singular_value <= singular_beta - triple_margin) { extension = 3; } } diff --git a/src/tm.cpp b/src/tm.cpp index f7730805..593cc478 100644 --- a/src/tm.cpp +++ b/src/tm.cpp @@ -1,6 +1,7 @@ #include "tm.hpp" #include "uci.hpp" #include "util/types.hpp" +#include "tuned.hpp" #include namespace Clockwork::TM { @@ -15,9 +16,9 @@ time::TimePoint compute_hard_limit(time::TimePoint search_start, if (settings.w_time >= 0) { const auto compute_buffer_time = [&]() -> i64 { if (stm == Color::White) { - return settings.w_time / 4; + return settings.w_time * tuned::time_hard_limit / 1024; } else { - return settings.b_time / 4; + return settings.b_time * tuned::time_hard_limit / 1024; } }; hard_limit = min(hard_limit, search_start + Milliseconds(compute_buffer_time())); @@ -46,9 +47,11 @@ time::TimePoint compute_soft_limit(time::TimePoint search_start, // Base time calculation const auto compute_buffer_time = [&]() -> f64 { if (stm == Color::White) { - return static_cast(settings.w_time / 20 + settings.w_inc / 2); + return static_cast(settings.w_time * tuned::time_soft_limit / 1024 + + settings.w_inc * tuned::time_soft_increment / 1024); } else { - return static_cast(settings.b_time / 20 + settings.b_inc / 2); + return static_cast(settings.b_time * tuned::time_soft_limit / 1024 + + settings.b_inc * tuned::time_soft_increment / 1024); } }; @@ -57,13 +60,20 @@ time::TimePoint compute_soft_limit(time::TimePoint search_start, if constexpr (!ADJUST_FOR_NODES_TM) { return 1.0; } - return std::max(0.5, 2.0 - nodes_tm_fraction * (100.0 / 54.038)); + return std::max(tuned::nodetm_min_factor / 1024.0, + tuned::nodetm_avg_factor / 1024.0 + - nodes_tm_fraction * (tuned::nodetm_frac_factor / 1024.0)); }; // Adjustment based on difference between depth 1 search score and current score // This essentially estimates the complexity of a position const auto compute_complexitytm_factor = [&]() -> f64 { - return std::max(0.77 + std::clamp(complexity, 0.0, 200.0) / 386.0, 1.0); + return std::max( + tuned::d1plexity_base / 1024.0 + + std::clamp(complexity, 0.0, + static_cast(tuned::d1plexity_max_complexity)) + / static_cast(tuned::d1plexity_divisor), + 1.0); }; soft_limit = diff --git a/src/tuned.hpp b/src/tuned.hpp index 33d24ec1..4fc6358d 100644 --- a/src/tuned.hpp +++ b/src/tuned.hpp @@ -19,6 +19,8 @@ namespace Clockwork::tuned { NO_TUNE(nmp_depth, 3, 1, 10, .5, 0.002) \ NO_TUNE(nmp_base_r, 3, 1, 10, .5, 0.002) \ NO_TUNE(nmp_verif_min_depth, 14, 1, 40, .5, 0.002) \ + TUNE(nmp_beta_margin, 30, 10, 60, 3, 0.002) \ + TUNE(nmp_beta_diff, 400, 200, 800, 38, 0.002) \ \ /* ProbCut Values */ \ TUNE(probcut_margin, 300, 100, 500, 10, 0.002) \ @@ -60,9 +62,10 @@ namespace Clockwork::tuned { NO_TUNE(sing_min_depth, 6, 1, 20, 0.5, 0.002) \ NO_TUNE(sing_depth_margin, 3, 1, 20, 0.5, 0.002) \ TUNE(sing_beta_margin, 5, 2, 10, 1, 0.002) \ - TUNE(sing_double_margin, 40, 20, 80, 3, 0.002) \ - TUNE(sing_hist_div, 512, 256, 1024, 39, 0.002) \ - TUNE(sing_triple_margin, 120, 60, 240, 9, 0.002) \ + TUNE(dext_margin, 40, 20, 80, 3, 0.002) \ + TUNE(dext_hist_div, 512, 256, 1024, 39, 0.002) \ + TUNE(triext_margin, 120, 60, 240, 9, 0.002) \ + TUNE(triext_hist_div, 512, 256, 1024, 39, 0.002) \ \ /* LMR */ \ TUNE(lmr_quiet_base, 788, 394, 1576, 59, 0.002) \ @@ -85,6 +88,17 @@ namespace Clockwork::tuned { TUNE(lmr_fut_red, 1024, 512, 2048, 77, 0.002) \ TUNE(lmr_max_red, 3072, 1536, 6144, 231, 0.002) \ \ + /* TIME MANAGEMENT */ \ + TUNE(time_hard_limit, 256, 128, 512, 19, 0.002) \ + TUNE(time_soft_limit, 51, 25, 100, 3, 0.002) \ + TUNE(time_soft_increment, 512, 256, 1024, 38, 0.002) \ + TUNE(nodetm_min_factor, 512, 256, 1024, 38, 0.002) \ + TUNE(nodetm_avg_factor, 2048, 1024, 4096, 153, 0.002) \ + TUNE(nodetm_frac_factor, 1895, 948, 3792, 142, 0.002) \ + TUNE(d1plexity_base, 788, 394, 1576, 59, 0.002) \ + TUNE(d1plexity_max_complexity, 200, 100, 400, 15, 0.002) \ + TUNE(d1plexity_divisor, 386, 193, 772, 29, 0.002) \ + \ /* End of Tunables */ #define DEFINE_VARIABLE(NAME, DEFAULT, ...) inline i32 NAME = DEFAULT; From c31db7b3b1464ff17ff1750bf3526db03b6338a2 Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Thu, 25 Dec 2025 02:47:42 +0100 Subject: [PATCH 2/2] format Bench: 13074664 --- src/tm.cpp | 2 +- src/tuned.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tm.cpp b/src/tm.cpp index 593cc478..036ee618 100644 --- a/src/tm.cpp +++ b/src/tm.cpp @@ -1,7 +1,7 @@ #include "tm.hpp" +#include "tuned.hpp" #include "uci.hpp" #include "util/types.hpp" -#include "tuned.hpp" #include namespace Clockwork::TM { diff --git a/src/tuned.hpp b/src/tuned.hpp index 4fc6358d..bc4d70ab 100644 --- a/src/tuned.hpp +++ b/src/tuned.hpp @@ -93,11 +93,11 @@ namespace Clockwork::tuned { TUNE(time_soft_limit, 51, 25, 100, 3, 0.002) \ TUNE(time_soft_increment, 512, 256, 1024, 38, 0.002) \ TUNE(nodetm_min_factor, 512, 256, 1024, 38, 0.002) \ - TUNE(nodetm_avg_factor, 2048, 1024, 4096, 153, 0.002) \ + TUNE(nodetm_avg_factor, 2048, 1024, 4096, 153, 0.002) \ TUNE(nodetm_frac_factor, 1895, 948, 3792, 142, 0.002) \ TUNE(d1plexity_base, 788, 394, 1576, 59, 0.002) \ TUNE(d1plexity_max_complexity, 200, 100, 400, 15, 0.002) \ - TUNE(d1plexity_divisor, 386, 193, 772, 29, 0.002) \ + TUNE(d1plexity_divisor, 386, 193, 772, 29, 0.002) \ \ /* End of Tunables */