From d6fc8e9f7d39c6b20b506f54c5313bc17cfbab8b Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 18 Aug 2019 09:34:28 +0200 Subject: Printing to stderr is now behind a feature flag --- Cargo.toml | 7 +++++- src/main.rs | 1 + src/strategy/minimax.rs | 60 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 891fcb3..ad22026 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,9 @@ rayon = "1.1.0" [profile.release] debug = true debug-assertions = true -overflow-checks = true \ No newline at end of file +overflow-checks = true + +[features] +logging = [] + +default = [] diff --git a/src/main.rs b/src/main.rs index d2ec145..4f98e75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,7 @@ fn main() { } }, Err(e) => { + #[cfg(feature = "logging")] eprintln!("WARN: State file could not be parsed: {}", e); Command::new(Action::DoNothing) } diff --git a/src/strategy/minimax.rs b/src/strategy/minimax.rs index 5a7bbcd..f65f770 100644 --- a/src/strategy/minimax.rs +++ b/src/strategy/minimax.rs @@ -45,19 +45,38 @@ pub fn choose_move( children: FnvHashMap::default(), }; - while start_time.to(PreciseTime::now()) < max_time { - let _ = expand_tree(&mut root_node, state.clone(), config); - } - - eprintln!("Number of simulations: {}", root_node.score_sum.visit_count); - for (command, score_sum) in &root_node.player_score_sums[0] { + #[cfg(feature = "logging")] + { + let mut max_expand_time = Duration::milliseconds(0); + while start_time.to(PreciseTime::now()) < max_time { + let expand_start_time = PreciseTime::now(); + let _ = expand_tree(&mut root_node, state.clone(), config); + max_expand_time = max_expand_time.max(expand_start_time.to(PreciseTime::now())); + } eprintln!( - "{} = {} ({} visits)", - command, - score_sum.avg().val, - score_sum.visit_count + "Max expand time: {:?} ns", + max_expand_time.num_nanoseconds() ); } + #[cfg(not(feature = "logging"))] + { + while start_time.to(PreciseTime::now()) < max_time { + let _ = expand_tree(&mut root_node, state.clone(), config); + } + } + + #[cfg(feature = "logging")] + { + eprintln!("Number of simulations: {}", root_node.score_sum.visit_count); + for (command, score_sum) in &root_node.player_score_sums[0] { + eprintln!( + "{} = {} ({} visits)", + command, + score_sum.avg().val, + score_sum.visit_count + ); + } + } best_player_move(&root_node, 0) } @@ -79,15 +98,18 @@ pub fn choose_move_with_normalized_perf( let _ = expand_tree(&mut root_node, state.clone(), config); } - // eprintln!("Number of simulations: {}", root_node.score_sum.visit_count); - // for (command, score_sum) in &root_node.player_score_sums[player_index] { - // eprintln!( - // "{} = {} ({} visits)", - // command, - // score_sum.avg().val, - // score_sum.visit_count - // ); - // } + #[cfg(feature = "logging")] + { + eprintln!("Number of simulations: {}", root_node.score_sum.visit_count); + for (command, score_sum) in &root_node.player_score_sums[player_index] { + eprintln!( + "{} = {} ({} visits)", + command, + score_sum.avg().val, + score_sum.visit_count + ); + } + } best_player_move(&root_node, player_index) } -- cgit v1.2.3