extern crate json; extern crate rand; mod actions; mod math; 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_json = read_file(&working_dir)?; println!("\n\n{}\n\n", state_json.pretty(2)); 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 { let state = State::new(&state_json)?; shoot_randomly(&state) }; write_action(&working_dir, is_place_phase, action) .map_err(|e| format!("Failed to write action to file. Error: {}", e))?; Ok(()) }