summaryrefslogtreecommitdiff
path: root/src/bin/explore-config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/explore-config.rs')
-rw-r--r--src/bin/explore-config.rs132
1 files changed, 104 insertions, 28 deletions
diff --git a/src/bin/explore-config.rs b/src/bin/explore-config.rs
index 33ff82b..12d9f86 100644
--- a/src/bin/explore-config.rs
+++ b/src/bin/explore-config.rs
@@ -1,5 +1,7 @@
use std::path::Path;
+use std::sync::Mutex;
+use rayon::prelude::*;
use time::PreciseTime;
use steam_powered_wyrm::game;
@@ -13,35 +15,109 @@ fn main() {
);
let depth = 100;
- {
- // TODO: Player 0 seems to be winning here consistently. I
- // probably have a bug. Also, I expected this to give the same
- // result each time and it doesn't.
-
- let start_time = PreciseTime::now();
- let config1 = ScoreConfig::default();
- let config2 = ScoreConfig::default();
- let mut state = initial_state.clone();
-
- while state.outcome == game::SimulationOutcome::Continue {
- let commands = [
- choose_move_with_normalized_perf(&state, &config1, 0, depth),
- choose_move_with_normalized_perf(&state, &config2, 1, depth),
- ];
- state.simulate(commands);
- println!("Commands: {:?}", commands);
+ let configs = ScoreConfigTrials {
+ max_health_weight: vec![0., 1.],
+ total_health_weight: vec![0., 1.],
+ 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.],
+ }
+ .reify();
+
+ eprintln!("{} configs being tested", configs.len());
+
+ let victories = Mutex::new(vec![0; configs.len()]);
+
+ for i in 0..configs.len() {
+ eprintln!("Progress: {} of {}", i, configs.len());
+
+ (i + 1..configs.len())
+ .collect::<Vec<usize>>()
+ .par_iter()
+ .for_each(|j| {
+ let start_time = PreciseTime::now();
+ 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);
+ }
+
+ 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,
+ _ => {}
+ };
+ });
+ }
+
+ 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();
+}
+
+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,
+ });
+ }
+ }
+ }
+ }
+ }
+ }
}
- println!("{:?}", state.outcome);
- println!(
- "Runtime: {}ms",
- start_time.to(PreciseTime::now()).num_milliseconds()
- );
- println!(
- "Health: {} - {}",
- state.players[0].health(),
- state.players[1].health()
- );
- println!("Round: {}", state.round);
+ result
}
}