blob: d964fee974c34d0e4c78013eee1ae3fece84deda (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
use std::error::Error;
const STATE_PATH: &str = "state.json";
const COMMAND_PATH: &str = "command.txt";
use std::fs::File;
use std::io::prelude::*;
use std::process;
mod state_json;
mod engine;
use engine::command::Command;
fn choose_move(_state: &state_json::State) -> Option<Command> {
None
}
fn write_command(filename: &str, command: Option<Command>) -> Result<(), Box<Error> > {
let mut file = File::create(filename)?;
if let Some(command) = command {
write!(file, "{}", command)?;
}
Ok(())
}
fn main() {
let state = match state_json::read_state_from_file(STATE_PATH) {
Ok(state) => state,
Err(error) => {
eprintln!("Failed to read the {} file. {}", STATE_PATH, error);
process::exit(1);
}
};
let command = choose_move(&state);
match write_command(COMMAND_PATH, command) {
Ok(()) => {}
Err(error) => {
eprintln!("Failed to write the {} file. {}", COMMAND_PATH, error);
process::exit(1);
}
}
}
|