diff options
Diffstat (limited to 'src/strategy/minimax.rs')
-rw-r--r-- | src/strategy/minimax.rs | 60 |
1 files changed, 41 insertions, 19 deletions
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) } |