summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-07-24 22:21:29 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-07-24 22:21:29 +0200
commit4b64d36d14785c8ab1bc72368bae3fcb3543bb27 (patch)
tree0e691726ba3b20926965124d3e9302d67f28000f
parent5a2a493cd299705105a14fe1dfcd7bd1ddd104d7 (diff)
Fixed min and benchmark logging in discarding search
-rw-r--r--src/strategy/monte_carlo.rs23
1 files 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<GS: GameState>(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<Co
break;
}
}
+
+ #[cfg(feature = "benchmarking")]
+ {
+ let total_iterations: u32 = command_scores.iter().map(|c| c.attempts).sum();
+ println!("Iterations: {}", total_iterations);
+ }
+
command_scores.iter().max_by_key(|&c| c.win_ratio())
}
#[cfg(feature = "discard-poor-performers")]
fn simulate_options_to_timeout<'a, GS: GameState>(command_scores: &'a mut Vec<CommandScore>, 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<Co
}
active_scores.sort_unstable_by_key(|c| -c.win_ratio());
}
+
+ #[cfg(feature = "benchmarking")]
+ {
+ let total_iterations: u32 = command_scores.iter().map(|c| c.attempts).sum();
+ println!("Iterations: {}", total_iterations);
+ }
+
command_scores.first()
}