Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scripts/spsa_out_replace.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
16 changes: 8 additions & 8 deletions src/evaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,13 @@ PScore evaluate_space(const Position& pos) {
}

template<Color color>
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;

Expand All @@ -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<Score>(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<Score>(WINNABLE_PAWNS * pawn_count + symmetry
+ WINNABLE_PAWN_ENDGAME * pawn_endgame + WINNABLE_BIAS);

if (score.eg() < 0) {
winnable = -winnable;
winnable = static_cast<Score>(-winnable);
}

return score.complexity_add(winnable);
Expand Down Expand Up @@ -487,8 +487,8 @@ Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) {
PScore black_king_attack_total = evaluate_king_safety<Color::White>(pos);

// Nonlinear adjustment
eval += king_safety_activation<Color::White>(pos, white_king_attack_total)
- king_safety_activation<Color::Black>(pos, black_king_attack_total);
eval += king_safety_activation<Color::White>(white_king_attack_total)
- king_safety_activation<Color::Black>(black_king_attack_total);

eval += (us == Color::White) ? TEMPO_VAL : -TEMPO_VAL;

Expand Down
10 changes: 7 additions & 3 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 25 additions & 1 deletion src/see.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,37 @@
#include <array>
#include <bit>
#include <cassert>
#include <tuned.hpp>
#include <tuple>

namespace Clockwork::SEE {

inline Value value(PieceType ptype) {
constexpr std::array<Value, 7> TABLE{{0, 100, 300, 300, 500, 900, 10000}};
#if (CLOCKWORK_IS_TUNING == 0)
constexpr std::array<Value, 7> 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<usize>(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) {
Expand Down
123 changes: 66 additions & 57 deletions src/tuned.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "util/types.hpp"
#include <string_view>

#define CLOCKWORK_IS_TUNING 0

#ifndef CLOCKWORK_IS_TUNING
#define CLOCKWORK_IS_TUNING 0
#endif
Expand All @@ -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 */

Expand Down
Loading