From 74f593bb27b19c8d021918a46a6447a80e25f828 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 21 Aug 2019 08:32:35 +0200 Subject: Tweaking config experimentally --- src/bin/explore-config.rs | 71 +++++++++++++++++++++-------------------------- src/json.rs | 2 +- src/strategy/minimax.rs | 12 ++++---- 3 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/bin/explore-config.rs b/src/bin/explore-config.rs index 12d9f86..10f75eb 100644 --- a/src/bin/explore-config.rs +++ b/src/bin/explore-config.rs @@ -1,8 +1,6 @@ use std::path::Path; -use std::sync::Mutex; use rayon::prelude::*; -use time::PreciseTime; use steam_powered_wyrm::game; use steam_powered_wyrm::json; @@ -16,28 +14,27 @@ fn main() { let depth = 100; let configs = ScoreConfigTrials { - max_health_weight: vec![0., 1.], - total_health_weight: vec![0., 1.], + max_health_weight: vec![50., 150.], + total_health_weight: vec![5., 20.], points_weight: vec![0., 1.], victory_weight: vec![3000.], - snowball_weight: vec![0., 100.], - bomb_weight: vec![0., 100.], - explore_exploit_weight: vec![1., 10.], + snowball_weight: vec![10.], + bomb_weight: vec![0., 10., 100., 1000., 10000.], + explore_exploit_weight: vec![5., 100.], } .reify(); eprintln!("{} configs being tested", configs.len()); - let victories = Mutex::new(vec![0; configs.len()]); + let mut victories = vec![0; configs.len()]; for i in 0..configs.len() { eprintln!("Progress: {} of {}", i, configs.len()); - (i + 1..configs.len()) + let outcomes: Vec<(usize, game::SimulationOutcome)> = (i + 1..configs.len()) .collect::>() .par_iter() - .for_each(|j| { - let start_time = PreciseTime::now(); + .map(|j| { let mut state = initial_state.clone(); while state.outcome == game::SimulationOutcome::Continue { @@ -48,37 +45,33 @@ fn main() { state.simulate(commands); } - eprintln!( - "Runtime: {}ms", - start_time.to(PreciseTime::now()).num_milliseconds() - ); - match state.outcome { - game::SimulationOutcome::PlayerWon(0) => victories.lock().unwrap()[i] += 1, - game::SimulationOutcome::PlayerWon(1) => victories.lock().unwrap()[*j] += 1, - _ => {} - }; - }); + (*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"); - victories - .lock() - .map(|victories| { - 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 - ); - } - }) - .unwrap(); + + 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 { diff --git a/src/json.rs b/src/json.rs index fc6ba82..a83f102 100644 --- a/src/json.rs +++ b/src/json.rs @@ -6,7 +6,7 @@ use std::path::Path; use serde::{Deserialize, Serialize}; use serde_json; -pub fn read_state_from_json_file(filename: &Path) -> Result> { +pub fn read_state_from_json_file(filename: &Path) -> Result> { let mut file = File::open(filename)?; let mut content = String::new(); file.read_to_string(&mut content)?; diff --git a/src/strategy/minimax.rs b/src/strategy/minimax.rs index f65f770..5ddd928 100644 --- a/src/strategy/minimax.rs +++ b/src/strategy/minimax.rs @@ -21,13 +21,13 @@ pub struct ScoreConfig { impl Default for ScoreConfig { fn default() -> ScoreConfig { ScoreConfig { - max_health_weight: 1., - total_health_weight: 1., - points_weight: 0., + max_health_weight: 100., + total_health_weight: 10., + points_weight: 1., victory_weight: 3000., - snowball_weight: 100., - bomb_weight: 100., - explore_exploit_weight: 10., + snowball_weight: 10., + bomb_weight: 0., + explore_exploit_weight: 100., } } } -- cgit v1.2.3