From 4b64d36d14785c8ab1bc72368bae3fcb3543bb27 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Tue, 24 Jul 2018 22:21:29 +0200 Subject: Fixed min and benchmark logging in discarding search --- src/strategy/monte_carlo.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs index 0a51b39..127e690 100644 --- a/src/strategy/monte_carlo.rs +++ b/src/strategy/monte_carlo.rs @@ -18,12 +18,6 @@ use rayon::prelude::*; pub fn choose_move(settings: &GameSettings, state: &GS, start_time: &PreciseTime, max_time: Duration) -> Command { let mut command_scores = CommandScore::init_command_scores(settings, state); let command = simulate_options_to_timeout(&mut command_scores, settings, state, start_time, max_time); - - #[cfg(feature = "benchmarking")] - { - let total_iterations: u32 = command_scores.iter().map(|c| c.attempts).sum(); - println!("Iterations: {}", total_iterations); - } match command { Some(command) => command.command, @@ -39,16 +33,24 @@ fn simulate_options_to_timeout<'a, GS: GameState>(command_scores: &'a mut Vec(command_scores: &'a mut Vec, settings: &GameSettings, state: &GS, start_time: &PreciseTime, max_time: Duration) -> Option<&'a CommandScore> { use std::cmp; + let min_options = cmp::min(command_scores.len(), 5); let maxes = [max_time / 4, max_time / 2, max_time * 3 / 4, max_time]; for (i, &max) in maxes.iter().enumerate() { - let new_length = cmp::max(20, command_scores.len() / (2usize.pow(i as u32))); + let new_length = cmp::max(min_options, command_scores.len() / (2usize.pow(i as u32))); let active_scores = &mut command_scores[0..new_length]; loop { simulate_all_options_once(active_scores, settings, state); @@ -58,6 +60,13 @@ fn simulate_options_to_timeout<'a, GS: GameState>(command_scores: &'a mut Vec