From 11c791a59ac60241f253cdfb4e8765039d15edff Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 9 May 2018 22:51:38 +0200 Subject: Added converting from JSON code to game engine representation --- src/main.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d964fee..4e18c48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,34 +14,33 @@ use std::fs::File; use std::io::prelude::*; use std::process; -mod state_json; +mod json; mod engine; use engine::command::Command; -fn choose_move(_state: &state_json::State) -> Option { - None +fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState) -> Command { + state.simulate(&settings, Command::Nothing, Command::Nothing); + Command::Nothing } -fn write_command(filename: &str, command: Option) -> Result<(), Box > { +fn write_command(filename: &str, command: Command) -> Result<(), Box > { let mut file = File::create(filename)?; - if let Some(command) = command { - write!(file, "{}", command)?; - } + write!(file, "{}", command)?; Ok(()) } fn main() { - let state = match state_json::read_state_from_file(STATE_PATH) { - Ok(state) => state, + let (settings, state) = match json::read_state_from_file(STATE_PATH) { + Ok(ok) => ok, Err(error) => { eprintln!("Failed to read the {} file. {}", STATE_PATH, error); process::exit(1); } }; - let command = choose_move(&state); + let command = choose_move(&settings, &state); match write_command(COMMAND_PATH, command) { Ok(()) => {} -- cgit v1.2.3