Printed debug for different tower building
authorJustin Worthe <justin@worthe-it.co.za>
Thu, 16 Aug 2018 20:58:07 +0000 (22:58 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Thu, 16 Aug 2018 20:58:07 +0000 (22:58 +0200)
src/engine/command.rs
src/strategy/monte_carlo.rs

index e6dbedf..c4268c5 100644 (file)
@@ -1,7 +1,7 @@
 use std::fmt;
 use super::geometry::Point;
 
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
 pub enum Command {
     Nothing,
     Build(Point, BuildingType),
index a2b5a4b..f937ea1 100644 (file)
@@ -1,6 +1,7 @@
 use engine::command::*;
 use engine::status::GameStatus;
 use engine::bitwise_engine::{Player, BitwiseGameState};
+use engine::geometry::*;
 use engine::constants::*;
 
 use std::fmt;
@@ -37,14 +38,52 @@ pub fn choose_move(state: &BitwiseGameState, start_time: PreciseTime, max_time:
     }
     #[cfg(feature = "debug-decisions")]
     {
-        for score in command_scores {
-            println!("{}", score);
-        }
+        debug_print_choices("ENERGY", &command_scores, |score| match score.command {
+            Command::Build(p, BuildingType::Energy) => Some((p, score.win_ratio())),
+            _ => None
+        });
+        debug_print_choices("ATTACK", &command_scores, |score| match score.command {
+            Command::Build(p, BuildingType::Attack) => Some((p, score.win_ratio())),
+            _ => None
+        });
+        debug_print_choices("DEFENCE", &command_scores, |score| match score.command {
+            Command::Build(p, BuildingType::Defence) => Some((p, score.win_ratio())),
+            _ => None
+        });
+        debug_print_choices("TESLA", &command_scores, |score| match score.command {
+            Command::Build(p, BuildingType::Tesla) => Some((p, score.win_ratio())),
+            _ => None
+        });
+        
+        println!("NOTHING");
+        println!("{}", command_scores.iter().find(|c| c.command == Command::Nothing).map(|s| s.win_ratio()).unwrap_or(0));
+        println!("");
+
+        println!("IRON CURTAIN");
+        println!("{}", command_scores.iter().find(|c| c.command == Command::IronCurtain).map(|s| s.win_ratio()).unwrap_or(0));
+        println!("");
     }
 
     command
 }
 
+#[cfg(feature = "debug-decisions")]
+fn debug_print_choices<F: FnMut(&CommandScore) -> Option<(Point, i32)>>(label: &str, command_scores: &[CommandScore], extractor: F) {
+    println!("{}", label);
+    let relevant_moves: Vec<(Point, i32)>  = command_scores.iter()
+        .filter_map(extractor)
+        .collect();
+    for y in 0..MAP_HEIGHT {
+        for x in 0..SINGLE_MAP_WIDTH {
+            let point = Point::new(x, y);
+            let score = relevant_moves.iter().find(|(p, _)| *p == point);
+            print!(" | {}", score.map(|(_,s)| s).cloned().unwrap_or(0));
+        }
+        println!(" |");
+    }
+    println!("");
+}
+
 #[cfg(not(feature = "discard-poor-performers"))]
 fn simulate_options_to_timeout(command_scores: &'a mut Vec<CommandScore>, settings: &GameSettings, state: &BitwiseGameState, start_time: PreciseTime, max_time: Duration) -> Option<&'a CommandScore> {
     loop {