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.rs71
1 files changed, 32 insertions, 39 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::<Vec<usize>>()
.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 {