summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-07-01 18:06:05 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-07-01 18:06:05 +0200
commit26aefe70fa11f209726e5b8a15bd05303726396e (patch)
treee8ab0ae5fa230e0e1ea6b51b240305d59d59d662 /src
parent1ac0449bd0313ad01da0d253f7b45b45287314b7 (diff)
Set up (failing) property test for working of new game state
Unfortunately, for this test to work, I still need to implement the function that reads the game state and goes from one to the other.
Diffstat (limited to 'src')
-rw-r--r--src/bin/perf-test.rs2
-rw-r--r--src/engine/bitwise_engine.rs28
-rw-r--r--src/input/json.rs51
-rw-r--r--src/main.rs2
-rw-r--r--src/strategy/monte_carlo.rs2
5 files changed, 66 insertions, 19 deletions
diff --git a/src/bin/perf-test.rs b/src/bin/perf-test.rs
index 054258f..42b4def 100644
--- a/src/bin/perf-test.rs
+++ b/src/bin/perf-test.rs
@@ -10,7 +10,7 @@ use std::process;
fn main() {
let start_time = PreciseTime::now();
- let (settings, state) = match input::json::read_state_from_file(STATE_PATH) {
+ let (settings, state) = match input::json::read_expressive_state_from_file(STATE_PATH) {
Ok(ok) => ok,
Err(error) => {
println!("Error while parsing JSON file: {}", error);
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs
index ca9cf00..bb1dd76 100644
--- a/src/engine/bitwise_engine.rs
+++ b/src/engine/bitwise_engine.rs
@@ -14,25 +14,25 @@ const MAX_TESLAS: usize = 2;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BitwiseGameState {
- status: GameStatus,
- player: Player,
- opponent: Player,
- player_buildings: PlayerBuildings,
- opponent_buildings: PlayerBuildings,
+ pub status: GameStatus,
+ pub player: Player,
+ pub opponent: Player,
+ pub player_buildings: PlayerBuildings,
+ pub opponent_buildings: PlayerBuildings,
}
#[derive(Debug, Clone, PartialEq, Eq)]
-struct PlayerBuildings {
- unconstructed: Vec<UnconstructedBuilding>,
- energy_towers: [u8; MAP_HEIGHT],
- missile_towers: [[u8; MAP_HEIGHT]; MISSILE_COOLDOWN],
- defence_towers: [[u8; MAP_HEIGHT]; DEFENCE_HEALTH],
- tesla_towers: [u8; MAP_HEIGHT],
+pub struct PlayerBuildings {
+ pub unconstructed: Vec<UnconstructedBuilding>,
+ pub buildings: [u64; DEFENCE_HEALTH],
- missiles: [[u16; MAP_HEIGHT]; MAP_WIDTH/4],
- tesla_cooldowns: [TeslaCooldown; MAX_TESLAS],
+ pub energy_towers: u64,
+ pub missile_towers: [u64; MISSILE_COOLDOWN],
+
+ pub missiles: [(u64, u64); MAP_WIDTH/4],
+ pub tesla_cooldowns: [TeslaCooldown; MAX_TESLAS],
- unoccupied: Vec<Point>
+ pub unoccupied: Vec<Point>
}
#[derive(Debug, Clone, PartialEq, Eq)]
diff --git a/src/input/json.rs b/src/input/json.rs
index 6f7cda1..fb88bf0 100644
--- a/src/input/json.rs
+++ b/src/input/json.rs
@@ -5,9 +5,9 @@ use std::error::Error;
use engine;
use engine::expressive_engine;
+use engine::bitwise_engine;
-
-pub fn read_state_from_file(filename: &str) -> Result<(engine::settings::GameSettings, expressive_engine::ExpressiveGameState), Box<Error>> {
+pub fn read_expressive_state_from_file(filename: &str) -> Result<(engine::settings::GameSettings, expressive_engine::ExpressiveGameState), Box<Error>> {
let mut file = File::open(filename)?;
let mut content = String::new();
file.read_to_string(&mut content)?;
@@ -18,6 +18,53 @@ pub fn read_state_from_file(filename: &str) -> Result<(engine::settings::GameSet
Ok((engine_settings, engine_state))
}
+pub fn read_bitwise_state_from_file(filename: &str) -> Result<bitwise_engine::BitwiseGameState, Box<Error>> {
+ //TODO
+ Ok(bitwise_engine::BitwiseGameState {
+ status: engine::GameStatus::Continue,
+ player: engine::Player {
+ energy: 0, health: 0, energy_generated: 0
+ },
+ opponent: engine::Player {
+ energy: 0, health: 0, energy_generated: 0
+ },
+ player_buildings: bitwise_engine::PlayerBuildings {
+ unconstructed: Vec::new(),
+ buildings: [0,0,0,0],
+ energy_towers: 0,
+ missile_towers: [0,0,0],
+ missiles: [(0,0),(0,0),(0,0),(0,0)],
+ tesla_cooldowns: [bitwise_engine::TeslaCooldown {
+ active: false,
+ pos: engine::geometry::Point::new(0,0),
+ cooldown: 0
+ }, bitwise_engine::TeslaCooldown {
+ active: false,
+ pos: engine::geometry::Point::new(0,0),
+ cooldown: 0
+ }],
+ unoccupied: Vec::new()
+ },
+ opponent_buildings: bitwise_engine::PlayerBuildings {
+ unconstructed: Vec::new(),
+ buildings: [0,0,0,0],
+ energy_towers: 0,
+ missile_towers: [0,0,0],
+ missiles: [(0,0),(0,0),(0,0),(0,0)],
+ tesla_cooldowns: [bitwise_engine::TeslaCooldown {
+ active: false,
+ pos: engine::geometry::Point::new(0,0),
+ cooldown: 0
+ }, bitwise_engine::TeslaCooldown {
+ active: false,
+ pos: engine::geometry::Point::new(0,0),
+ cooldown: 0
+ }],
+ unoccupied: Vec::new()
+ }
+ })
+}
+
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct State {
diff --git a/src/main.rs b/src/main.rs
index 61e2e55..fa9216e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -40,7 +40,7 @@ fn write_command(filename: &str, command: Command) -> Result<(), Box<Error> > {
fn main() {
let start_time = PreciseTime::now();
- let (settings, state) = match input::json::read_state_from_file(STATE_PATH) {
+ let (settings, state) = match input::json::read_expressive_state_from_file(STATE_PATH) {
Ok(ok) => ok,
Err(error) => {
println!("Error while parsing JSON file: {}", error);
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index dae74bc..19e663d 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -185,7 +185,7 @@ fn sensible_buildings(settings: &GameSettings, player: &Player, has_max_teslas:
for b in BuildingType::all().iter() {
let building_setting = settings.building_settings(*b);
let affordable = building_setting.price <= player.energy;
- let is_tesla = b == BuildingType::Tesla;
+ let is_tesla = *b == BuildingType::Tesla;
if affordable && (!is_tesla || !has_max_teslas) {
result.push(*b);
}