Split to library. Reimplemented sample strategy in new state.
[entelect-challenge-tower-defence.git] / src / main.rs
1 extern crate zombot;
2 use zombot::*;
3 use zombot::engine::command::Command;
4
5 use std::error::Error;
6
7 const STATE_PATH: &str = "state.json";
8
9 const COMMAND_PATH: &str = "command.txt";
10
11 use std::fs::File;
12 use std::io::prelude::*;
13 use std::process;
14
15 fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState) -> Command {
16     strategy::sample::choose_move(settings, state)
17 }
18
19
20 fn write_command(filename: &str, command: Command) -> Result<(), Box<Error> > {
21     let mut file = File::create(filename)?;
22     write!(file, "{}", command)?;
23     Ok(())
24 }
25
26
27 fn main() {
28     let (settings, state) = match json::read_state_from_file(STATE_PATH) {
29         Ok(ok) => ok,
30         Err(error) => {
31             process::exit(1);
32         }
33     };
34     let command = choose_move(&settings, &state);
35
36     match write_command(COMMAND_PATH, command) {
37         Ok(()) => {}
38         Err(error) => {
39             process::exit(1);
40         }
41     }
42 }