diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 21:29:18 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 21:29:18 +0200 |
commit | 4d1edc899a86791ec57c0d3b2b3d7427f138463f (patch) | |
tree | ed1c7031c54d8f3a3897081c4a1040ace9d8f4ae /2019-worms/src/main.rs | |
parent | 01a849c6b26afd076989f645c6153d8ce1422281 (diff) | |
parent | 3f5492b2bb67326be43cd7c5ba02ccf0ba1ae0e3 (diff) |
Merge branch 'worms-main'
Diffstat (limited to '2019-worms/src/main.rs')
-rw-r--r-- | 2019-worms/src/main.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/2019-worms/src/main.rs b/2019-worms/src/main.rs new file mode 100644 index 0000000..4f98e75 --- /dev/null +++ b/2019-worms/src/main.rs @@ -0,0 +1,46 @@ +use std::io::prelude::*; +use std::io::stdin; +use std::path::Path; + +use time::{Duration, PreciseTime}; + +use steam_powered_wyrm::command::{Action, Command}; +use steam_powered_wyrm::game; +use steam_powered_wyrm::json; +use steam_powered_wyrm::strategy::{choose_move, ScoreConfig}; + +fn main() { + let max_time = Duration::milliseconds(900); + let config = ScoreConfig::default(); + + let mut game_board = None; + for line in stdin().lock().lines() { + let start_time = PreciseTime::now(); + + let round_number = line.expect("Failed to read line from stdin: {}"); + + let command = match json::read_state_from_json_file(&Path::new(&format!( + "./rounds/{}/state.json", + round_number + ))) { + Ok(json_state) => match &mut game_board { + None => { + let new_board = game::GameBoard::new(json_state); + let command = choose_move(&new_board, &config, start_time, max_time); + game_board = Some(new_board); + command + } + Some(game_board) => { + game_board.update(json_state); + choose_move(&game_board, &config, start_time, max_time) + } + }, + Err(e) => { + #[cfg(feature = "logging")] + eprintln!("WARN: State file could not be parsed: {}", e); + Command::new(Action::DoNothing) + } + }; + println!("C;{};{}", round_number, command); + } +} |