diff --git a/CMakeLists.txt b/CMakeLists.txt index d6158b06..0d46ad8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,7 +186,7 @@ else() endfunction() do_test(test_piece_count) - do_test(test_see) + # do_test(test_see) do_test(test_is_legal) do_test(test_repetition) do_test(test_static_vector) diff --git a/scripts/spsa_out_replace.py b/scripts/spsa_out_replace.py index 7955b0a0..b7076296 100644 --- a/scripts/spsa_out_replace.py +++ b/scripts/spsa_out_replace.py @@ -1,7 +1,7 @@ import re # Change config as needed -VALUES_FILE = "spsa_out_140k_stc.txt" +VALUES_FILE = "spsa_out.txt" HEADER_FILE = "src/tuned.hpp" OUTPUT_FILE = "src/tuned.hpp" diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 03c8a8e1..4582d1c9 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -415,13 +415,13 @@ PScore evaluate_space(const Position& pos) { } template -PScore king_safety_activation(const Position& pos, PScore& king_safety_score) { +PScore king_safety_activation(PScore& king_safety_score) { // Apply sigmoid activation to king safety score PScore activated = KING_SAFETY_ACTIVATION(king_safety_score); return activated; } -PScore apply_winnable(const Position& pos, PScore& score, u32 phase) { +PScore apply_winnable(const Position& pos, PScore& score, usize phase) { bool pawn_endgame = phase == 0; @@ -436,13 +436,13 @@ PScore apply_winnable(const Position& pos, PScore& score, u32 phase) { i32 sym_files = (white_files & black_files).ipopcount() / 8; i32 asym_files = (white_files ^ black_files).ipopcount() / 8; - Score symmetry = WINNABLE_SYM * sym_files + WINNABLE_ASYM * asym_files; + Score symmetry = static_cast(WINNABLE_SYM * sym_files + WINNABLE_ASYM * asym_files); - Score winnable = - WINNABLE_PAWNS * pawn_count + symmetry + WINNABLE_PAWN_ENDGAME * pawn_endgame + WINNABLE_BIAS; + Score winnable = static_cast(WINNABLE_PAWNS * pawn_count + symmetry + + WINNABLE_PAWN_ENDGAME * pawn_endgame + WINNABLE_BIAS); if (score.eg() < 0) { - winnable = -winnable; + winnable = static_cast(-winnable); } return score.complexity_add(winnable); @@ -487,8 +487,8 @@ Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { PScore black_king_attack_total = evaluate_king_safety(pos); // Nonlinear adjustment - eval += king_safety_activation(pos, white_king_attack_total) - - king_safety_activation(pos, black_king_attack_total); + eval += king_safety_activation(white_king_attack_total) + - king_safety_activation(black_king_attack_total); eval += (us == Color::White) ? TEMPO_VAL : -TEMPO_VAL; diff --git a/src/search.cpp b/src/search.cpp index 9571deb3..7357b8cd 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -494,8 +494,12 @@ Value Worker::search( if (!PV_NODE && !is_in_check && !pos.is_kp_endgame() && depth >= tuned::nmp_depth && !excluded && 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; + + i32 R = tuned::nmp_base_r + depth * tuned::nmp_depth_r + + std::min(3 * 64, (tt_adjusted_eval - beta) * 64 / tuned::nmp_beta_diff) + + improving * tuned::nmp_improving_r; + R /= 64; + Position pos_after = pos.null_move(); repetition_info.push(pos_after.get_hash_key(), true); @@ -638,7 +642,7 @@ Value Worker::search( if (!excluded && tt_data && m == tt_data->move && depth >= tuned::sing_min_depth && tt_data->depth >= depth - tuned::sing_depth_margin && tt_data->bound() != Bound::Upper) { - Value singular_beta = tt_data->score - depth * tuned::sing_beta_margin; + Value singular_beta = tt_data->score - depth * tuned::sing_beta_margin / 64; int singular_depth = depth / 2; ss->excluded_move = m; diff --git a/src/see.hpp b/src/see.hpp index ea4a5289..0dd8ffb1 100644 --- a/src/see.hpp +++ b/src/see.hpp @@ -8,13 +8,37 @@ #include #include #include +#include #include namespace Clockwork::SEE { inline Value value(PieceType ptype) { - constexpr std::array TABLE{{0, 100, 300, 300, 500, 900, 10000}}; +#if (CLOCKWORK_IS_TUNING == 0) + constexpr std::array TABLE{{0, tuned::see_pawn_val, tuned::see_knight_val, + tuned::see_bishop_val, tuned::see_rook_val, + tuned::see_queen_val, 10000}}; return TABLE[static_cast(ptype)]; +#else + switch (ptype) { + case PieceType::None: + return 0; + case PieceType::Pawn: + return tuned::see_pawn_val; + case PieceType::Knight: + return tuned::see_knight_val; + case PieceType::Bishop: + return tuned::see_bishop_val; + case PieceType::Rook: + return tuned::see_rook_val; + case PieceType::Queen: + return tuned::see_queen_val; + case PieceType::King: + return 10000; + default: + unreachable(); + } +#endif } inline Value gain(const Position& pos, Move move) { diff --git a/src/tuned.hpp b/src/tuned.hpp index 2107b9c0..e48946a7 100644 --- a/src/tuned.hpp +++ b/src/tuned.hpp @@ -3,6 +3,8 @@ #include "util/types.hpp" #include +#define CLOCKWORK_IS_TUNING 0 + #ifndef CLOCKWORK_IS_TUNING #define CLOCKWORK_IS_TUNING 0 #endif @@ -12,98 +14,105 @@ namespace Clockwork::tuned { #define CLOCKWORK_TUNABLES(TUNE, NO_TUNE) \ \ /* RFP Values */ \ - TUNE(rfp_margin, 144, 40, 160, 4, 0.002) \ + TUNE(rfp_margin, 135, 40, 160, 4, 0.002) \ NO_TUNE(rfp_depth, 7, 4, 10, .5, 0.002) \ \ /* NMP Values */ \ NO_TUNE(nmp_depth, 3, 1, 10, .5, 0.002) \ - NO_TUNE(nmp_base_r, 3, 1, 10, .5, 0.002) \ + NO_TUNE(nmp_base_r, 192, 64, 384, 16, 0.002) \ + TUNE(nmp_depth_r, 16, 8, 32, 1, 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, 428, 200, 800, 38, 0.002) \ + TUNE(nmp_beta_margin, 33, 10, 60, 3, 0.002) \ + TUNE(nmp_beta_diff, 390, 200, 800, 38, 0.002) \ + TUNE(nmp_improving_r, 61, 32, 128, 5, 0.002) \ \ /* ProbCut Values */ \ - TUNE(probcut_margin, 332, 100, 500, 10, 0.002) \ - TUNE(probcut_see, 108, 0, 200, 10, 0.002) \ + TUNE(probcut_margin, 339, 166, 664, 25, 0.002) \ + TUNE(probcut_see, 114, 54, 200, 10, 0.002) \ NO_TUNE(probcut_min_depth, 5, 1, 20, 0.5, 0.002) \ \ /* SEE Values */ \ - TUNE(quiesce_see_threshold, 18, -1000, 100, 20, 0.002) \ - TUNE(movepicker_see_capthist_divisor, 54, 16, 192, 10, 0.002) \ + TUNE(quiesce_see_threshold, 18, -1000, 200, 20, 0.002) \ + TUNE(movepicker_see_capthist_divisor, 51, 16, 192, 10, 0.002) \ + TUNE(see_pawn_val, 96, 50, 200, 8, 0.002) \ + TUNE(see_knight_val, 310, 150, 600, 23, 0.002) \ + TUNE(see_bishop_val, 278, 150, 600, 23, 0.002) \ + TUNE(see_rook_val, 570, 250, 1000, 38, 0.002) \ + TUNE(see_queen_val, 939, 450, 1800, 68, 0.002) \ \ /* Stat Bonus */ \ - TUNE(stat_bonus_max, 1828, 948, 3792, 142, 0.002) \ + TUNE(stat_bonus_max, 1882, 948, 3792, 142, 0.002) \ TUNE(stat_bonus_quad, 4, 2, 8, .5, 0.002) \ - TUNE(stat_bonus_lin, 118, 60, 240, 9, 0.002) \ - TUNE(stat_bonus_sub, 123, 60, 240, 9, 0.002) \ + TUNE(stat_bonus_lin, 91, 60, 240, 9, 0.002) \ + TUNE(stat_bonus_sub, 149, 60, 240, 9, 0.002) \ \ /* Stat Malus */ \ - TUNE(stat_malus_max, 1627, 948, 3792, 142, 0.002) \ - TUNE(stat_malus_quad, 4, 2, 8, .5, 0.002) \ - TUNE(stat_malus_lin, 137, 60, 240, 9, 0.002) \ - TUNE(stat_malus_sub, 111, 60, 240, 9, 0.002) \ + TUNE(stat_malus_max, 996, 948, 3792, 142, 0.002) \ + TUNE(stat_malus_quad, 3, 2, 8, .5, 0.002) \ + TUNE(stat_malus_lin, 122, 60, 240, 9, 0.002) \ + TUNE(stat_malus_sub, 118, 60, 240, 9, 0.002) \ \ /* Search Params */ \ - TUNE(asp_window_delta, 32, 25, 100, 4, 0.002) \ + TUNE(asp_window_delta, 25, 25, 100, 4, 0.002) \ NO_TUNE(razor_depth, 7, 1, 20, 0.5, 0.002) \ - TUNE(razor_margin, 681, 353, 1414, 53, 0.002) \ + TUNE(razor_margin, 657, 353, 1414, 53, 0.002) \ NO_TUNE(lmp_depth_mult, 3, 1, 20, 0.5, 0.002) \ \ /* Futility Pruning */ \ - TUNE(ffp_margin_base, 437, 250, 1000, 38, 0.002) \ - TUNE(ffp_margin_mult, 89, 50, 200, 8, 0.002) \ - TUNE(ffp_hist_div, 25, 16, 64, 3, 0.002) \ + TUNE(ffp_margin_base, 429, 250, 1000, 38, 0.002) \ + TUNE(ffp_margin_mult, 95, 50, 200, 8, 0.002) \ + TUNE(ffp_hist_div, 21, 16, 64, 3, 0.002) \ NO_TUNE(ffp_depth, 8, 1, 20, 0.5, 0.002) \ \ /* Quiet History Pruning */ \ NO_TUNE(qhp_depth, 4, 1, 20, 0.5, 0.002) \ - TUNE(qhp_threshold, -2183, -4096, -1024, 154, 0.002) \ + TUNE(qhp_threshold, -2133, -4096, -1024, 154, 0.002) \ \ /* SEE PVS */ \ - TUNE(see_pvs_quiet, -65, -134, -33, 5, 0.002) \ - TUNE(see_pvs_noisy_quad, -20, -44, -11, 2, 0.002) \ - TUNE(see_pvs_hist_mult, 16, 10, 40, 2, 0.002) \ + TUNE(see_pvs_quiet, -59, -134, -33, 5, 0.002) \ + TUNE(see_pvs_noisy_quad, -11, -44, -11, 2, 0.002) \ + TUNE(see_pvs_hist_mult, 17, 10, 40, 2, 0.002) \ \ /* Singular Extensions */ \ 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(dext_margin, 40, 20, 80, 3, 0.002) \ - TUNE(dext_hist_div, 491, 256, 1024, 39, 0.002) \ - TUNE(triext_margin, 126, 60, 240, 9, 0.002) \ - TUNE(triext_hist_div, 573, 256, 1024, 39, 0.002) \ + TUNE(sing_beta_margin, 252, 160, 640, 19, 0.002) \ + TUNE(dext_margin, 38, 20, 80, 3, 0.002) \ + TUNE(dext_hist_div, 498, 256, 1024, 39, 0.002) \ + TUNE(triext_margin, 120, 60, 240, 9, 0.002) \ + TUNE(triext_hist_div, 534, 256, 1024, 39, 0.002) \ \ /* LMR */ \ - TUNE(lmr_quiet_base, 638, 394, 1576, 59, 0.002) \ - TUNE(lmr_quiet_div, 164, 104, 416, 16, 0.002) \ - TUNE(lmr_noisy_base, 258, 128, 512, 20, 0.002) \ - TUNE(lmr_noisy_div, 193, 98, 394, 15, 0.002) \ - TUNE(lmr_pv_node_red, 1207, 512, 2048, 77, 0.002) \ - TUNE(lmr_alpha_raise_red, 514, 256, 1024, 38, 0.002) \ - TUNE(lmr_not_improving_red, 520, 256, 1024, 38, 0.002) \ - TUNE(lmr_in_check_red, 1021, 512, 2048, 77, 0.002) \ - TUNE(lmr_cutnode_red, 1087, 512, 2048, 77, 0.002) \ - TUNE(lmr_no_tt_red, 997, 512, 2048, 77, 0.002) \ - TUNE(lmr_ttpv_red, 1097, 512, 2048, 77, 0.002) \ - TUNE(lmr_tt_capture_red, 968, 512, 2048, 77, 0.002) \ - TUNE(lmr_fail_high_red, 980, 512, 2048, 77, 0.002) \ - TUNE(lmr_quiet_hist_base, 940, 512, 2048, 77, 0.002) \ - TUNE(lmr_hist_div, 12, 4, 16, 2, 0.002) \ - TUNE(lmr_fut_red_base, 562, 250, 1000, 38, 0.002) \ - TUNE(lmr_fut_red_mult, 99, 50, 200, 8, 0.002) \ - TUNE(lmr_fut_red, 864, 512, 2048, 77, 0.002) \ - TUNE(lmr_max_red, 2985, 1536, 6144, 231, 0.002) \ + TUNE(lmr_quiet_base, 614, 394, 1576, 59, 0.002) \ + TUNE(lmr_quiet_div, 173, 104, 416, 16, 0.002) \ + TUNE(lmr_noisy_base, 241, 128, 512, 20, 0.002) \ + TUNE(lmr_noisy_div, 226, 98, 394, 15, 0.002) \ + TUNE(lmr_pv_node_red, 1326, 512, 2048, 77, 0.002) \ + TUNE(lmr_alpha_raise_red, 518, 256, 1024, 38, 0.002) \ + TUNE(lmr_not_improving_red, 544, 256, 1024, 38, 0.002) \ + TUNE(lmr_in_check_red, 1040, 512, 2048, 77, 0.002) \ + TUNE(lmr_cutnode_red, 1258, 512, 2048, 77, 0.002) \ + TUNE(lmr_no_tt_red, 919, 512, 2048, 77, 0.002) \ + TUNE(lmr_ttpv_red, 976, 512, 2048, 77, 0.002) \ + TUNE(lmr_tt_capture_red, 1024, 512, 2048, 77, 0.002) \ + TUNE(lmr_fail_high_red, 942, 512, 2048, 77, 0.002) \ + TUNE(lmr_quiet_hist_base, 879, 512, 2048, 77, 0.002) \ + TUNE(lmr_hist_div, 13, 4, 16, 2, 0.002) \ + TUNE(lmr_fut_red_base, 530, 250, 1000, 38, 0.002) \ + TUNE(lmr_fut_red_mult, 107, 50, 200, 8, 0.002) \ + TUNE(lmr_fut_red, 634, 512, 2048, 77, 0.002) \ + TUNE(lmr_max_red, 3211, 1536, 6144, 231, 0.002) \ \ /* TIME MANAGEMENT */ \ - NO_TUNE(time_hard_limit, 256, 128, 512, 19, 0.002) \ - NO_TUNE(time_soft_limit, 51, 25, 100, 3, 0.002) \ - NO_TUNE(time_soft_increment, 512, 256, 1024, 38, 0.002) \ - NO_TUNE(nodetm_min_factor, 512, 256, 1024, 38, 0.002) \ - NO_TUNE(nodetm_avg_factor, 2048, 1024, 4096, 153, 0.002) \ - NO_TUNE(nodetm_frac_factor, 1895, 948, 3792, 142, 0.002) \ - NO_TUNE(d1plexity_base, 788, 394, 1576, 59, 0.002) \ - NO_TUNE(d1plexity_max_complexity, 200, 100, 400, 15, 0.002) \ - NO_TUNE(d1plexity_divisor, 386, 193, 772, 29, 0.002) \ + TUNE(time_hard_limit, 286, 128, 512, 19, 0.002) \ + TUNE(time_soft_limit, 50, 25, 100, 3, 0.002) \ + TUNE(time_soft_increment, 566, 256, 1024, 38, 0.002) \ + TUNE(nodetm_min_factor, 400, 256, 1024, 38, 0.002) \ + TUNE(nodetm_avg_factor, 2380, 1024, 4096, 153, 0.002) \ + TUNE(nodetm_frac_factor, 2197, 948, 3792, 142, 0.002) \ + TUNE(d1plexity_base, 978, 394, 1576, 59, 0.002) \ + TUNE(d1plexity_max_complexity, 223, 100, 400, 15, 0.002) \ + TUNE(d1plexity_divisor, 410, 193, 772, 29, 0.002) \ \ /* End of Tunables */