summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-08-12 21:00:52 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-08-12 21:00:52 +0200
commitc9f09a22bc54b6275913aa3b900b402c56461c32 (patch)
tree7affa1194f2172d791028890134585e9a5fd176c /src
parent1f555a48c181a6ad274dd10e04d0c9a8460889db (diff)
Reduced more duplication and removed TODOs
Diffstat (limited to 'src')
-rw-r--r--src/engine/geometry.rs3
-rw-r--r--src/input/json.rs35
-rw-r--r--src/strategy/monte_carlo.rs2
3 files changed, 17 insertions, 23 deletions
diff --git a/src/engine/geometry.rs b/src/engine/geometry.rs
index bfa59da..090652f 100644
--- a/src/engine/geometry.rs
+++ b/src/engine/geometry.rs
@@ -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
diff --git a/src/input/json.rs b/src/input/json.rs
index 2152fc2..843f228 100644
--- a/src/input/json.rs
+++ b/src/input/json.rs
@@ -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
+ };
+ }
+}
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index 2c9ff19..866ec0e 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -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);