logic error, wasn't propagating potential loss through neigbor wilt

This commit is contained in:
Spectre 2024-10-10 18:32:21 +02:00
parent 04e94c297f
commit a18e4c2d8d
2 changed files with 115 additions and 59 deletions

View file

@ -1,79 +1,135 @@
// mod harvest; // mod harvest;
pub mod model; pub mod model;
pub mod weights; pub mod weights;
pub mod exact;
pub mod config;
use model::*; use config::{ColorValues, Config, MapMods, SeedValues, UpgradeChances, Color};
use weights::{ColorWeights, Config}; use exact::{Field, Grove};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use std::fs::{self, OpenOptions};
use std::io::prelude::*;
use rayon::prelude::*;
fn main() { fn main() {
let config = parse_config("config.toml").unwrap();
let config = Config {
map_mods: MapMods {
pack_size: 1.0,
no_wilt_chance: 0.6
},
color_values: ColorValues {
yellow: 1.0 / 2500.0,
blue: 1.0 / 10000.0,
red: 1.0 / 9000.0
},
seed_values: SeedValues {
t1: 7.0,
t2: 18.0,
t3: 47.0,
t4: 230.0,
t1_drop_chance: 0.02,
t2_drop_chance: 0.09
},
upgrade_chances: UpgradeChances {
t1_to_t2: 0.25,
t2_to_t3: 0.20,
t3_to_t4: 0.03,
}
};
for color in gen_possible_color_weights().into_iter() { // let y = Field{color: Color::Yellow, wilted: false, upgrades: 0};
let mut file = OpenOptions::new() // let b = Field{color: Color::Blue, wilted: false, upgrades: 0};
.create(true) // let r = Field{color: Color::Red, wilted: false, upgrades: 0};
.append(true)
.open(format!("data/{}", color))
.unwrap();
for res in run_sim(10000, &config, &color).iter() { get_color_combos()
writeln!(file, "{res}"); .into_par_iter()
.for_each(|colors| {
let val = Grove::setup(colors.clone()).expected_value(&config);
println!("{} - {:?}", val, colors);
});
}
fn get_color_combos() -> Vec<Vec<Color>> {
let valid_primitives = [
[Color::Yellow, Color::Yellow],
[Color::Yellow, Color::Blue],
[Color::Yellow, Color::Red],
[Color::Blue, Color::Blue],
[Color::Blue, Color::Red],
[Color::Red, Color::Red],
[Color::NotGrown, Color::NotGrown],
];
let mut results: Vec<Vec<Color>> = Vec::new();
for yy in 0..=5 {
for yb in 0..=5-yy {
for yr in 0..=5-yy-yb {
for bb in 0..=5-yy-yb-yr {
for br in 0..=5-yy-yb-yr-bb {
for rr in 0..=5-yy-yb-yr-bb-br {
let nn = 5 - yy-yb-yr-bb-br-rr;
if nn <= 2 {
results.push(
[
valid_primitives[0].repeat(yy),
valid_primitives[1].repeat(yb),
valid_primitives[2].repeat(yr),
valid_primitives[3].repeat(bb),
valid_primitives[4].repeat(br),
valid_primitives[5].repeat(rr),
valid_primitives[6].repeat(nn),
].concat()
)
}
}
}
}
}
} }
} }
// for i in 0..10 { results
// let res = lifeforce_after_upgrades(i, 1000000, &config); }
// println!("{i}: {res}"); // fn parse_config(path: &str) -> Result<weights::Config, Box<dyn std::error::Error>> {
// let file = fs::read_to_string(path)?;
// let config: weights::Config = toml::from_str(&file)?;
// Ok(config)
// } // }
// fn run_sim(n: usize, config: &weights::Config, color_weight: &ColorWeights) -> Vec<f64> {
// (0..n)
// .into_par_iter()
// .map(|_| Harvest::<Field>::new(color_weight, config).recursive_harvest(config))
// .collect()
// }
} // fn gen_possible_color_weights() -> Vec<ColorWeights> {
// let allowed = [0.55, 0.65, 0.75, 0.80, 0.90, 1.00];
fn parse_config(path: &str) -> Result<Config, Box<dyn std::error::Error>> { // let mut all: Vec<ColorWeights> = Vec::new();
let file = fs::read_to_string(path)?;
let config: Config = toml::from_str(&file)?;
Ok(config)
}
fn run_sim(n: usize, config: &Config, color_weight: &ColorWeights) -> Vec<f64> { // for &yellow in &allowed {
(0..n) // for &blue in &allowed {
.into_par_iter() // for &red in &allowed {
.map(|_| Harvest::<Field>::new(color_weight, config).recursive_harvest(config)) // if yellow == 0.55 || blue == 0.55 || red == 0.55 {
.collect() // all.push(ColorWeights { yellow, blue, red });
} // }
// }
// }
// }
fn gen_possible_color_weights() -> Vec<ColorWeights> { // all
let allowed = [0.55, 0.65, 0.75, 0.80, 0.90, 1.00]; // }
let mut all: Vec<ColorWeights> = Vec::new(); // fn lifeforce_after_upgrades(n: usize, tries: usize, config: &weights::Config) -> f64 {
// (0..tries)
for &yellow in &allowed { // .into_par_iter()
for &blue in &allowed { // .map(|_| {
for &red in &allowed { // let mut field: Field = Field { color: weights::Color::Yellow, wilted: false, t1_seeds: 23, t2_seeds: 0, t3_seeds: 0, t4_seeds: 0};
if yellow == 0.55 || blue == 0.55 || red == 0.55 { // for i in 0..n {
all.push(ColorWeights { yellow, blue, red }); // field.upgrade(config);
} // }
} // field.harvest(config).unwrap()
} // }).sum::<f64>() / (tries as f64)
} // }
all
}
fn lifeforce_after_upgrades(n: usize, tries: usize, config: &Config) -> f64 {
(0..tries)
.into_par_iter()
.map(|_| {
let mut field: Field = Field { color: weights::Color::Yellow, wilted: false, t1_seeds: 23, t2_seeds: 0, t3_seeds: 0, t4_seeds: 0};
for i in 0..n {
field.upgrade(config);
}
field.harvest(config).unwrap()
}).sum::<f64>() / (tries as f64)
}

View file

@ -67,7 +67,7 @@ pub struct Config {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Copy)]
pub enum Color { pub enum Color {
Yellow, Yellow,
Blue, Blue,