summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
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(()) => {}