summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-09-06 21:51:50 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-09-06 21:51:50 +0200
commit90a7c7d34def7e5f92f2cd521fdc014e0cbd9906 (patch)
tree65b45bbf4bc7204b6189d6fb39180a39527b14eb /src
parent4ad0035f4f11b41e400a1f567fdcd3541fa3f21e (diff)
Added benchmarking for number of explored nodes
Diffstat (limited to 'src')
-rw-r--r--src/strategy/monte_carlo_tree.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/strategy/monte_carlo_tree.rs b/src/strategy/monte_carlo_tree.rs
index 4efded8..7d688f2 100644
--- a/src/strategy/monte_carlo_tree.rs
+++ b/src/strategy/monte_carlo_tree.rs
@@ -66,6 +66,7 @@ impl NodeStats {
fn node_with_highest_ucb<'a>(&'a mut self) -> &'a mut (Command, NodeStats) {
debug_assert!(self.unexplored.is_empty());
+ debug_assert!(self.explored.len() > 0);
let total_attempts = self.explored.iter().map(|(_, n)| n.attempts).sum::<f32>();
let mut max_position = 0;
@@ -102,6 +103,10 @@ impl NodeStats {
fn add_draw(&mut self) {
self.attempts += 1.;
}
+
+ fn count_explored(&self) -> usize {
+ 1 + self.explored.iter().map(|(_, n)| n.count_explored()).sum::<usize>()
+ }
}
pub fn choose_move(state: &BitwiseGameState, start_time: PreciseTime, max_time: Duration) -> Command {
@@ -113,6 +118,11 @@ pub fn choose_move(state: &BitwiseGameState, start_time: PreciseTime, max_time:
tree_search(&state, &mut root, &mut rng);
}
+ #[cfg(feature = "benchmarking")]
+ {
+ println!("Explored nodes: {}", root.count_explored());
+ }
+
let (command, _) = root.node_with_highest_ucb();
command.clone()
}