Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time management tune and improvements #27

Merged
merged 5 commits into from
Aug 1, 2024
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
26 changes: 17 additions & 9 deletions src/mcts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'a> Searcher<'a> {

nodes += 1;

if nodes % 256 == 0 {
if nodes % 128 == 0 {
if self.abort.load(Ordering::Relaxed) {
break;
}
Expand All @@ -116,7 +116,7 @@ impl<'a> Searcher<'a> {
}
}

if nodes % 16384 == 0 {
if nodes % 4096 == 0 {
// Time management
if let Some(time) = limits.opt_time {
let elapsed = timer.elapsed().as_millis();
Expand All @@ -129,16 +129,22 @@ impl<'a> Searcher<'a> {
} else {
previous_score - score
};
let falling_eval = (1.0 + eval_diff * 0.05).clamp(0.60, 1.80);
let falling_eval = (1.0 + eval_diff * self.params.tm_falling_eval1()).clamp(
self.params.tm_falling_eval2(),
self.params.tm_falling_eval3(),
);

// Use more time if our best move is changing frequently
let best_move_instability =
(1.0 + (best_move_changes as f32 * 0.3).ln_1p()).clamp(1.0, 3.2);
let best_move_instability = (1.0
+ (best_move_changes as f32 * self.params.tm_bmi1()).ln_1p())
.clamp(self.params.tm_bmi2(), self.params.tm_bmi3());

// Use less time if our best move has a large percentage of visits, and vice versa
let nodes_effort = self.get_best_action().visits() as f32 / nodes as f32;
let best_move_visits =
(2.5 - ((nodes_effort + 0.3) * 0.55).ln_1p() * 4.0).clamp(0.55, 1.50);
let best_move_visits = (self.params.tm_bmv1()
- ((nodes_effort + self.params.tm_bmv2()) * self.params.tm_bmv3()).ln_1p()
* self.params.tm_bmv4())
.clamp(self.params.tm_bmv5(), self.params.tm_bmv6());

let total_time =
(time as f32 * falling_eval * best_move_instability * best_move_visits)
Expand All @@ -147,11 +153,13 @@ impl<'a> Searcher<'a> {
break;
}

best_move_changes = 0;
if nodes % 16384 == 0 {
best_move_changes = 0;
}
previous_score = if previous_score == f32::NEG_INFINITY {
score
} else {
(score + previous_score) / 2.0
(score + 2.0 * previous_score) / 3.0
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mcts/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl SearchHelpers {
} else {
// Increment time control (x seconds + y increment)
let inc = increment.unwrap_or(0);
let mtg = 30;
let mtg = params.tm_mtg() as u64;

let time_left = (time + inc * (mtg - 1) - 10 * (2 + mtg)).max(1) as f64;
let log_time = (time_left / 1000.0).log10();
Expand Down
43 changes: 28 additions & 15 deletions src/mcts/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,32 @@ make_mcts_params! {
material_offset: i32 = 700, 400, 1200, 40, 0.002;
material_div1: i32 = 32, 16, 64, 3, 0.002;
material_div2: i32 = 1024, 512, 1536, 64, 0.002;
tm_opt_value1: f64 = 0.48, 0.1, 1.0, 0.05, 0.002;
tm_opt_value2: f64 = 0.32, 0.1, 1.0, 0.03, 0.002;
tm_opt_value3: f64 = 0.60, 0.1, 1.0, 0.06, 0.002;
tm_optscale_value1: f64 = 1.25, 0.1, 2.0, 0.1, 0.002;
tm_optscale_value2: f64 = 2.5, 0.1, 5.0, 0.15, 0.002;
tm_optscale_value3: f64 = 0.50, 0.1, 1.0, 0.05, 0.002;
tm_optscale_value4: f64 = 0.25, 0.1, 1.0, 0.02, 0.002;
tm_max_value1: f64 = 3.39, 1.0, 10.0, 0.4, 0.002;
tm_max_value2: f64 = 3.01, 1.0, 10.0, 0.4, 0.002;
tm_max_value3: f64 = 2.93, 1.0, 10.0, 0.4, 0.002;
tm_maxscale_value1: f64 = 12.0, 1.0, 24.0, 1.2, 0.002;
tm_maxscale_value2: f64 = 4.00, 1.0, 12.0, 0.6, 0.002;
tm_bonus_ply: f64 = 11.0, 1.0, 30.0, 1.5, 0.002;
tm_bonus_value1: f64 = 0.5, 0.1, 2.0, 0.05, 0.002;
tm_max_time: f64 = 0.850, 0.400, 0.990, 0.085, 0.002;
tm_opt_value1: f64 = 0.686, 0.1, 1.2, 0.072, 0.002;
tm_opt_value2: f64 = 0.392, 0.1, 1.0, 0.045, 0.002;
tm_opt_value3: f64 = 0.822, 0.1, 1.2, 0.08, 0.002;
tm_optscale_value1: f64 = 1.271, 0.1, 2.0, 0.15, 0.002;
tm_optscale_value2: f64 = 2.510, 0.1, 5.0, 0.3, 0.002;
tm_optscale_value3: f64 = 0.499, 0.1, 1.0, 0.05, 0.002;
tm_optscale_value4: f64 = 0.240, 0.1, 1.0, 0.025, 0.002;
tm_max_value1: f64 = 3.072, 1.0, 10.0, 0.4, 0.002;
tm_max_value2: f64 = 2.928, 1.0, 10.0, 0.4, 0.002;
tm_max_value3: f64 = 2.843, 1.0, 10.0, 0.4, 0.002;
tm_maxscale_value1: f64 = 11.357, 1.0, 24.0, 1.2, 0.002;
tm_maxscale_value2: f64 = 3.691, 1.0, 12.0, 0.6, 0.002;
tm_bonus_ply: f64 = 10.72, 1.0, 30.0, 1.5, 0.002;
tm_bonus_value1: f64 = 0.488, 0.1, 2.0, 0.05, 0.002;
tm_max_time: f64 = 0.837, 0.400, 0.990, 0.085, 0.002;
tm_mtg: i32 = 30, 10, 60, 3, 0.002;
tm_falling_eval1: f32 = 0.055, 0.0, 0.2, 0.007, 0.002;
tm_falling_eval2: f32 = 0.648, 0.1, 1.0, 0.06, 0.002;
tm_falling_eval3: f32 = 1.644, 0.1, 3.0, 0.18, 0.002;
tm_bmi1: f32 = 0.305, 0.1, 1.0, 0.04, 0.002;
tm_bmi2: f32 = 0.948, 0.1, 2.0, 0.1, 0.002;
tm_bmi3: f32 = 3.121, 0.1, 6.4, 0.32, 0.002;
tm_bmv1: f32 = 2.696, 0.1, 5.0, 0.25, 0.002;
tm_bmv2: f32 = 0.309, 0.1, 1.0, 0.035, 0.002;
tm_bmv3: f32 = 0.519, 0.1, 1.0, 0.06, 0.002;
tm_bmv4: f32 = 3.946, 0.1, 8.0, 0.4, 0.002;
tm_bmv5: f32 = 0.523, 0.1, 1.0, 0.055, 0.002;
tm_bmv6: f32 = 1.560, 0.1, 3.0, 0.15, 0.002;
}
Loading