Feature-flaggified weighting win ratios
authorJustin Worthe <justin@worthe-it.co.za>
Sat, 8 Sep 2018 08:36:09 +0000 (10:36 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Sat, 8 Sep 2018 08:36:09 +0000 (10:36 +0200)
Cargo.toml
src/strategy/monte_carlo.rs
tests/monte_carlo_test.rs

index 1602696..12ffc19 100644 (file)
@@ -30,8 +30,9 @@ discard-poor-performers = []
 heuristic-random = ["lazy_static"]
 full-monte-carlo-tree = []
 static-opening = []
+weighted-win-ratio = []
 
-default = ["energy-cutoff", "discard-poor-performers", "heuristic-random", "static-opening", "debug-decisions"]
+default = ["energy-cutoff", "discard-poor-performers", "heuristic-random", "static-opening", "weighted-win-ratio", "debug-decisions"]
 
 [profile.release]
 debug = true
\ No newline at end of file
index 039c861..978f8f1 100644 (file)
@@ -398,10 +398,16 @@ impl CommandScore {
         self.next_seed = next_seed;
     }
 
+    #[cfg(feature = "weighted-win-ratio")]
     fn win_ratio(&self) -> i32 {
         (self.victory_score - self.defeat_score) * 10000 / (self.attempts as i32)
     }
 
+    #[cfg(not(feature = "weighted-win-ratio"))]
+    fn win_ratio(&self) -> i32 {
+        (self.victories as i32 - self.defeats as i32) * 10000 / (self.attempts as i32)
+    }
+
     fn init_command_scores(state: &BitwiseGameState) -> Vec<CommandScore> {
         let unoccupied_cells_count = state.player.unoccupied_cell_count();
         let unoccupied_cells = (0..unoccupied_cells_count)
index 470c92d..cec3256 100644 (file)
@@ -27,7 +27,7 @@ fn it_does_a_normal_tree_serach_turn_successfully() {
         Ok(ok) => ok,
         Err(error) => panic!("Error while parsing JSON file: {}", error)
     };
-    let max_time = Duration::milliseconds(20000);
+    let max_time = Duration::milliseconds(200);
     strategy::monte_carlo_tree::choose_move(&state, start_time, max_time);
 
     assert!(start_time.to(PreciseTime::now()) < max_time + Duration::milliseconds(50))