Reduced more duplication and removed TODOs
authorJustin Worthe <justin@worthe-it.co.za>
Sun, 12 Aug 2018 19:00:52 +0000 (21:00 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Sun, 12 Aug 2018 19:00:52 +0000 (21:00 +0200)
src/engine/geometry.rs
src/input/json.rs
src/strategy/monte_carlo.rs

index bfa59da..090652f 100644 (file)
@@ -1,8 +1,5 @@
 use engine::constants::*;
 
-//TODO: Change Point to be a single number, or stored as a bitfield
-// (bitfield to x and y for writing move might be hard?
-
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 pub struct Point {
     pub index: u8
index 2152fc2..843f228 100644 (file)
@@ -72,28 +72,11 @@ struct MissileState {
 
 impl State {
     fn to_bitwise_engine(&self) -> bitwise_engine::BitwiseGameState {
-        let json_player = self.player();
-        let json_opponent = self.opponent();
         let mut player = bitwise_engine::Player::empty();
         let mut opponent = bitwise_engine::Player::empty();
 
-        // TODO roll the player into the playerbuildings and remove this duplication
-        player.health = json_player.health;
-        player.energy = json_player.energy;
-        player.iron_curtain_available = json_player.iron_curtain_available;
-        player.iron_curtain_remaining = if json_player.active_iron_curtain_lifetime < 0 {
-            0
-        } else {
-            json_player.active_iron_curtain_lifetime as u8
-        };
-        opponent.health = json_opponent.health;
-        opponent.energy = json_opponent.energy;
-        opponent.iron_curtain_available = json_opponent.iron_curtain_available;
-        opponent.iron_curtain_remaining = if json_opponent.active_iron_curtain_lifetime < 0 {
-            0
-        } else {
-            json_opponent.active_iron_curtain_lifetime as u8
-        };
+        self.player().map_onto_engine(&mut player);
+        self.opponent().map_onto_engine(&mut opponent);
         
         for row in &self.game_map {
             for cell in row {
@@ -192,3 +175,17 @@ impl BuildingState {
         }
     }
 }
+
+
+impl Player {
+    fn map_onto_engine(&self, engine_player: &mut bitwise_engine::Player) {
+        engine_player.health = self.health;
+        engine_player.energy = self.energy;
+        engine_player.iron_curtain_available = self.iron_curtain_available;
+        engine_player.iron_curtain_remaining = if self.active_iron_curtain_lifetime < 0 {
+            0
+        } else {
+            self.active_iron_curtain_lifetime as u8
+        };
+    }
+}
index 2c9ff19..866ec0e 100644 (file)
@@ -12,6 +12,7 @@ use time::{Duration, PreciseTime};
 #[cfg(not(feature = "single-threaded"))]
 use rayon::prelude::*;
 
+//TODO Rethink / adjust these?
 #[cfg(feature = "energy-cutoff")] pub const ENERGY_PRODUCTION_CUTOFF: u16 = 100;
 #[cfg(feature = "energy-cutoff")] pub const ENERGY_STORAGE_CUTOFF: u16 = 100;
 
@@ -235,7 +236,6 @@ fn sensible_buildings(player: &Player) -> Vec<BuildingType> {
 
 
 //TODO: Heuristic that avoids building the initial energy towers all in the same row? Max energy in a row?
-//TODO: Update cutoff to maybe build iron curtains
 #[cfg(feature = "energy-cutoff")]
 fn sensible_buildings(player: &Player) -> Vec<BuildingType> {
     let mut result = Vec::with_capacity(4);