Added a static set of opening moves to get energy up and running
authorJustin Worthe <justin@worthe-it.co.za>
Sat, 8 Sep 2018 07:31:41 +0000 (09:31 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Sat, 8 Sep 2018 07:31:41 +0000 (09:31 +0200)
Cargo.toml
src/main.rs
src/strategy/mod.rs
src/strategy/static_opening.rs [new file with mode: 0644]

index 9ec8947..1602696 100644 (file)
@@ -29,8 +29,9 @@ energy-cutoff = []
 discard-poor-performers = []
 heuristic-random = ["lazy_static"]
 full-monte-carlo-tree = []
+static-opening = []
 
-default = ["energy-cutoff", "discard-poor-performers", "heuristic-random"]
+default = ["energy-cutoff", "discard-poor-performers", "heuristic-random", "static-opening", "debug-decisions"]
 
 [profile.release]
 debug = true
\ No newline at end of file
index 05b9546..4fa0366 100644 (file)
@@ -34,9 +34,13 @@ fn main() {
         }
     };
 
-    // TODO: Opening playbook?
-    #[cfg(feature = "full-monte-carlo-tree")] let command = strategy::monte_carlo_tree::choose_move(&state, start_time, max_time);
-    #[cfg(not(feature = "full-monte-carlo-tree"))] let command = strategy::monte_carlo::choose_move(&state, start_time, max_time);
+    let command = if cfg!(feature = "static-opening") && state.round < strategy::static_opening::STATIC_OPENING_LENGTH {
+        strategy::static_opening::choose_move(&state)
+    } else if cfg!(feature = "full-monte-carlo-tree") {
+        strategy::monte_carlo_tree::choose_move(&state, start_time, max_time)
+    } else {
+        strategy::monte_carlo::choose_move(&state, start_time, max_time)
+    };
 
     match write_command(COMMAND_PATH, command) {
         Ok(()) => {}
@@ -48,3 +52,4 @@ fn main() {
 
     println!("Elapsed time: {}", start_time.to(PreciseTime::now()));
 }
+
index ceb624b..9ec41bb 100644 (file)
@@ -1,2 +1,3 @@
 pub mod monte_carlo;
 pub mod monte_carlo_tree;
+pub mod static_opening;
diff --git a/src/strategy/static_opening.rs b/src/strategy/static_opening.rs
new file mode 100644 (file)
index 0000000..f7e101c
--- /dev/null
@@ -0,0 +1,21 @@
+use engine::geometry::*;
+use engine::command::*;
+use engine::bitwise_engine::*;
+
+pub const STATIC_OPENING_LENGTH: u16 = 12;
+
+pub fn choose_move(state: &BitwiseGameState) -> Command {
+    match state.round {
+        0 => Command::Build(Point::new(0,0), BuildingType::Energy),
+        3 => Command::Build(Point::new(0,1), BuildingType::Energy),
+        5 => Command::Build(Point::new(0,2), BuildingType::Energy),
+        7 => Command::Build(Point::new(0,3), BuildingType::Energy),
+        9 => Command::Build(Point::new(0,4), BuildingType::Energy),
+        10 => Command::Build(Point::new(0,5), BuildingType::Energy),
+        11 => Command::Build(Point::new(0,6), BuildingType::Energy),
+        12 => Command::Build(Point::new(0,7), BuildingType::Energy),
+        13 => Command::Build(Point::new(1,0), BuildingType::Energy),
+        14 => Command::Build(Point::new(1,7), BuildingType::Energy),
+        _ => Command::Nothing
+    }
+}