diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-08-18 09:34:28 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-08-18 09:34:28 +0200 |
commit | d6fc8e9f7d39c6b20b506f54c5313bc17cfbab8b (patch) | |
tree | 354b14116c2c2d816f98fa97be43d4e67048bd0b | |
parent | f4c27b7a834538bc75dd6f986c05635e6c58956c (diff) |
Printing to stderr is now behind a feature flag
-rw-r--r-- | Cargo.toml | 7 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/strategy/minimax.rs | 60 |
3 files changed, 48 insertions, 20 deletions
@@ -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) } |