diff options
Diffstat (limited to '2019-worms/src/bin')
-rw-r--r-- | 2019-worms/src/bin/benchmark.rs | 22 | ||||
-rw-r--r-- | 2019-worms/src/bin/explore-config.rs | 116 |
2 files changed, 138 insertions, 0 deletions
diff --git a/2019-worms/src/bin/benchmark.rs b/2019-worms/src/bin/benchmark.rs new file mode 100644 index 0000000..84e869e --- /dev/null +++ b/2019-worms/src/bin/benchmark.rs @@ -0,0 +1,22 @@ +use std::path::Path; + +use time::{Duration, PreciseTime}; + +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(19950); + let start_time = PreciseTime::now(); + + match json::read_state_from_json_file(&Path::new(&format!("./tests/example-state.json"))) { + Ok(json_state) => { + let new_board = game::GameBoard::new(json_state); + let _ = choose_move(&new_board, &ScoreConfig::default(), start_time, max_time); + } + Err(e) => { + eprintln!("WARN: State file could not be parsed: {}", e); + } + }; +} diff --git a/2019-worms/src/bin/explore-config.rs b/2019-worms/src/bin/explore-config.rs new file mode 100644 index 0000000..5fb599a --- /dev/null +++ b/2019-worms/src/bin/explore-config.rs @@ -0,0 +1,116 @@ +use std::path::Path; + +use rayon::prelude::*; + +use steam_powered_wyrm::game; +use steam_powered_wyrm::json; +use steam_powered_wyrm::strategy::{choose_move_with_normalized_perf, ScoreConfig}; + +fn main() { + let initial_state = game::GameBoard::new( + json::read_state_from_json_file(&Path::new(&format!("./tests/example-state.json"))) + .unwrap(), + ); + let depth = 1000; + + let configs = ScoreConfigTrials { + max_health_weight: vec![50., 150.], + total_health_weight: vec![5., 20.], + points_weight: vec![1.], + victory_weight: vec![3000., 3500., 4000., 4500., 5000., 5500., 6000., 7000.], + snowball_weight: vec![10.], + bomb_weight: vec![0.], + explore_exploit_weight: vec![10., 500.], + } + .reify(); + + eprintln!("{} configs being tested", configs.len()); + + let mut victories = vec![0; configs.len()]; + + for i in 0..configs.len() { + eprintln!("Progress: {} of {}", i, configs.len()); + + let outcomes: Vec<(usize, game::SimulationOutcome)> = (i + 1..configs.len()) + .collect::<Vec<usize>>() + .par_iter() + .map(|j| { + let mut state = initial_state.clone(); + + while state.outcome == game::SimulationOutcome::Continue { + let commands = [ + choose_move_with_normalized_perf(&state, &configs[i], 0, depth), + choose_move_with_normalized_perf(&state, &configs[*j], 1, depth), + ]; + state.simulate(commands); + } + + (*j, state.outcome) + }) + .collect(); + for (j, outcome) in outcomes { + match outcome { + game::SimulationOutcome::PlayerWon(0) => victories[i] += 1, + game::SimulationOutcome::PlayerWon(1) => victories[j] += 1, + _ => {} + }; + } + } + + println!("victories, max_health_weight, total_health_weight, points_weight, victory_weight, snowball_weight, bomb_weight, explore_exploit_weight"); + + for (config, victories) in configs.into_iter().zip(victories.iter()) { + println!( + "{}, {}, {}, {}, {}, {}, {}, {}", + victories, + config.max_health_weight, + config.total_health_weight, + config.points_weight, + config.victory_weight, + config.snowball_weight, + config.bomb_weight, + config.explore_exploit_weight + ); + } +} + +pub struct ScoreConfigTrials { + pub max_health_weight: Vec<f32>, + pub total_health_weight: Vec<f32>, + pub points_weight: Vec<f32>, + pub victory_weight: Vec<f32>, + pub snowball_weight: Vec<f32>, + pub bomb_weight: Vec<f32>, + pub explore_exploit_weight: Vec<f32>, +} + +impl ScoreConfigTrials { + fn reify(self) -> Vec<ScoreConfig> { + let mut result = Vec::new(); + for max_health_weight in &self.max_health_weight { + for total_health_weight in &self.total_health_weight { + for points_weight in &self.points_weight { + for victory_weight in &self.victory_weight { + for snowball_weight in &self.snowball_weight { + for bomb_weight in &self.bomb_weight { + for explore_exploit_weight in &self.explore_exploit_weight { + result.push(ScoreConfig { + max_health_weight: *max_health_weight, + total_health_weight: *total_health_weight, + points_weight: *points_weight, + victory_weight: *victory_weight, + snowball_weight: *snowball_weight, + bomb_weight: *bomb_weight, + explore_exploit_weight: *explore_exploit_weight, + }); + } + } + } + } + } + } + } + + result + } +} |