summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-08-16 22:58:07 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-08-16 22:58:07 +0200
commitc36278ec2593ff9b25bf3f5bad22ab547cca5447 (patch)
tree83f760d13fd6f4273cf7a5ff6a7486ff3920b8ea /src
parentc2795dd5bd74f9bdc1c77ae5a07b2b416a71d714 (diff)
Printed debug for different tower building
Diffstat (limited to 'src')
-rw-r--r--src/engine/command.rs2
-rw-r--r--src/strategy/monte_carlo.rs45
2 files changed, 43 insertions, 4 deletions
diff --git a/src/engine/command.rs b/src/engine/command.rs
index e6dbedf..c4268c5 100644
--- a/src/engine/command.rs
+++ b/src/engine/command.rs
@@ -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),
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index a2b5a4b..f937ea1 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -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 {