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;
pub mod model;
pub mod weights;
pub mod exact;
pub mod config;
use model::*;
use weights::{ColorWeights, Config};
use std::fs::{self, OpenOptions};
use std::io::prelude::*;
use rayon::prelude::*;
use config::{ColorValues, Config, MapMods, SeedValues, UpgradeChances, Color};
use exact::{Field, Grove};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
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 mut file = OpenOptions::new()
.create(true)
.append(true)
.open(format!("data/{}", color))
.unwrap();
// let y = Field{color: Color::Yellow, wilted: false, upgrades: 0};
// let b = Field{color: Color::Blue, wilted: false, upgrades: 0};
// let r = Field{color: Color::Red, wilted: false, upgrades: 0};
for res in run_sim(10000, &config, &color).iter() {
writeln!(file, "{res}");
}
}
// for i in 0..10 {
// let res = lifeforce_after_upgrades(i, 1000000, &config);
// println!("{i}: {res}");
// }
}
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)
get_color_combos()
.into_par_iter()
.map(|_| Harvest::<Field>::new(color_weight, config).recursive_harvest(config))
.collect()
.for_each(|colors| {
let val = Grove::setup(colors.clone()).expected_value(&config);
println!("{} - {:?}", val, colors);
});
}
fn gen_possible_color_weights() -> Vec<ColorWeights> {
let allowed = [0.55, 0.65, 0.75, 0.80, 0.90, 1.00];
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 all: Vec<ColorWeights> = Vec::new();
let mut results: Vec<Vec<Color>> = 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 });
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()
)
}
}
}
}
}
}
}
all
results
}
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)
}
// 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];
// 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 {
Yellow,
Blue,