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 {
for color in gen_possible_color_weights().into_iter() { map_mods: MapMods {
let mut file = OpenOptions::new() pack_size: 1.0,
.create(true) no_wilt_chance: 0.6
.append(true) },
.open(format!("data/{}", color)) color_values: ColorValues {
.unwrap(); yellow: 1.0 / 2500.0,
blue: 1.0 / 10000.0,
for res in run_sim(10000, &config, &color).iter() { red: 1.0 / 9000.0
writeln!(file, "{res}"); },
} 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 i in 0..10 { // let y = Field{color: Color::Yellow, wilted: false, upgrades: 0};
// let res = lifeforce_after_upgrades(i, 1000000, &config); // let b = Field{color: Color::Blue, wilted: false, upgrades: 0};
// let r = Field{color: Color::Red, wilted: false, upgrades: 0};
// println!("{i}: {res}"); get_color_combos()
// }
}
fn parse_config(path: &str) -> Result<Config, Box<dyn std::error::Error>> {
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> {
(0..n)
.into_par_iter() .into_par_iter()
.map(|_| Harvest::<Field>::new(color_weight, config).recursive_harvest(config)) .for_each(|colors| {
.collect() let val = Grove::setup(colors.clone()).expected_value(&config);
println!("{} - {:?}", val, colors);
});
} }
fn gen_possible_color_weights() -> Vec<ColorWeights> { fn get_color_combos() -> Vec<Vec<Color>> {
let allowed = [0.55, 0.65, 0.75, 0.80, 0.90, 1.00]; 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 all: Vec<ColorWeights> = Vec::new(); let mut results: Vec<Vec<Color>> = Vec::new();
for &yellow in &allowed { for yy in 0..=5 {
for &blue in &allowed { for yb in 0..=5-yy {
for &red in &allowed { for yr in 0..=5-yy-yb {
if yellow == 0.55 || blue == 0.55 || red == 0.55 { for bb in 0..=5-yy-yb-yr {
all.push(ColorWeights { yellow, blue, red }); 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()
)
}
}
}
} }
} }
} }
} }
all results
} }
fn lifeforce_after_upgrades(n: usize, tries: usize, config: &Config) -> f64 { // fn parse_config(path: &str) -> Result<weights::Config, Box<dyn std::error::Error>> {
(0..tries) // let file = fs::read_to_string(path)?;
.into_par_iter() // let config: weights::Config = toml::from_str(&file)?;
.map(|_| { // Ok(config)
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); // fn run_sim(n: usize, config: &weights::Config, color_weight: &ColorWeights) -> Vec<f64> {
} // (0..n)
field.harvest(config).unwrap() // .into_par_iter()
}).sum::<f64>() / (tries as f64) // .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];
// let mut all: Vec<ColorWeights> = Vec::new();
// for &yellow in &allowed {
// for &blue in &allowed {
// for &red in &allowed {
// if yellow == 0.55 || blue == 0.55 || red == 0.55 {
// all.push(ColorWeights { yellow, blue, red });
// }
// }
// }
// }
// all
// }
// fn lifeforce_after_upgrades(n: usize, tries: usize, config: &weights::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,