diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2017-05-13 21:43:27 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2017-05-13 21:43:27 +0200 |
commit | 05ccf5572b39fe254c7b0464cc78a1b623f732c7 (patch) | |
tree | 723d35b3eca744d5739174bfe965df12cd678fe1 /src/lib.rs | |
parent | 872529bc9a13b1923047a7f9308abaa40eb63d3c (diff) |
Added checking if state is in use before shooting
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -7,28 +7,31 @@ mod files; mod ships; mod placement; mod shooting; +mod state; use math::*; use files::*; use ships::*; use placement::*; use shooting::*; +use state::*; use std::path::PathBuf; pub fn write_move(working_dir: PathBuf) -> Result<(), String> { - let state = read_file(&working_dir)?; + let state_json = read_file(&working_dir)?; - let is_place_phase = state["Phase"] == 1; - let map_size = state["MapDimension"] - .as_u16() - .ok_or("Did not find the map dimension in the state json file")?; + println!("{}", state_json); + + let is_place_phase = state_json["Phase"] == 1; + let map_size = State::map_size_from_json(&state_json)?; let action = if is_place_phase { place_ships_randomly(map_size) } else { - shoot_randomly(map_size) + let state = State::new(&state_json)?; + shoot_randomly(&state) }; write_action(&working_dir, is_place_phase, action) |