summaryrefslogtreecommitdiff
path: root/src/bin/perf-test.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-05-14 21:51:36 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-05-14 21:51:36 +0200
commit6c7eac5e5fc166759dbbf22f0ca28fd1b636de52 (patch)
treed892b7a712c7d49d8bb870eeef8eefe672d1795a /src/bin/perf-test.rs
parent91c5c52431c894315d5ef72a7c9480b3b09d1745 (diff)
Added profiling target with perf
Diffstat (limited to 'src/bin/perf-test.rs')
-rw-r--r--src/bin/perf-test.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/bin/perf-test.rs b/src/bin/perf-test.rs
new file mode 100644
index 0000000..1397cc3
--- /dev/null
+++ b/src/bin/perf-test.rs
@@ -0,0 +1,53 @@
+extern crate zombot;
+extern crate time;
+use time::{PreciseTime, Duration};
+
+use zombot::*;
+use zombot::engine::command::Command;
+
+use std::error::Error;
+
+const STATE_PATH: &str = "init_state.json";
+
+const COMMAND_PATH: &str = "command.txt";
+
+use std::fs::File;
+use std::io::prelude::*;
+use std::process;
+
+fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState, start_time: &PreciseTime) -> Command {
+ let max_time = Duration::milliseconds(9950);
+ strategy::monte_carlo::choose_move(settings, state, start_time, max_time)
+}
+
+
+fn write_command(filename: &str, command: Command) -> Result<(), Box<Error> > {
+ let mut file = File::create(filename)?;
+ write!(file, "{}", command)?;
+ Ok(())
+}
+
+
+fn main() {
+ let start_time = PreciseTime::now();
+
+ println!("Reading in state.json file");
+ let (settings, state) = match json::read_state_from_file(STATE_PATH) {
+ Ok(ok) => ok,
+ Err(error) => {
+ println!("Error while parsing JSON file: {}", error);
+ process::exit(1);
+ }
+ };
+ let command = choose_move(&settings, &state, &start_time);
+
+ match write_command(COMMAND_PATH, command) {
+ Ok(()) => {}
+ Err(error) => {
+ println!("Error while writing command file: {}", error);
+ process::exit(1);
+ }
+ }
+
+ println!("Elapsed time: {}", start_time.to(PreciseTime::now()));
+}