summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-05-09 22:51:38 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-05-09 22:51:38 +0200
commit11c791a59ac60241f253cdfb4e8765039d15edff (patch)
tree71d4df1b7dad0dfe03e25d3ef128a61927e65522 /src/main.rs
parent057a4fe886848322adf4e48ad9709a289434dc1b (diff)
Added converting from JSON code to game engine representation
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 9 insertions, 10 deletions
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<Command> {
- 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<Command>) -> Result<(), Box<Error> > {
+fn write_command(filename: &str, command: Command) -> Result<(), Box<Error> > {
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(()) => {}