diff options
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) |