//! The WORLD population: synthetic opponents rich enough that an advanced read has something to find. //! //! The old fixed opponents (`reader::Style`, `population`) bet one constant size, have no pace, and //! never show a hand, so a sizing / timing / showdown read measures exactly 0 against them and a //! world-class read is unprovable. A `Persona` is one drawn individual with //! //! - a **sizing tell** (`Tell`): bet size depends on the hand's strength, with noise - it sizes up with //! strength (`Linear`), polarizes (`Polar`), is reversed (`Reverse`: big bluffs, small value), is //! flat, or is strength-independent (`Mixed`, the balanced case); //! - **texture- and position-conditioned** thresholds and bluff rates (`Shift` per `Texture`, per //! `Pos`), so its bet / fold / raise rates differ between a dry and a wet board, in and out of position; //! - **intra-archetype variance**: every seat is drawn from an archetype's distribution (`Persona::draw`), //! so the same archetype yields different individuals; //! - a noisy **timing tell** (`tank_factor`): the pace correlates, with noise, with strength. //! //! Showdown reveals are produced by the table (`sim::table`, `WorldHand`) and fed to //! `sim::memory::SessionMemory::observe_world_hand`. The engine reads none of these dimensions today; //! this population is the measuring gate for the day it does. //! //! `balanciert` is the control arm: sizes independent of strength, no texture or position shifts. //! Exploiting it must win nothing over playing blind (a read that "finds" an edge there is self-exposure). //! Cash only: no ICM terms anywhere. use super::memory::{Pos, Texture}; use super::opponent::{Act, View}; use super::population::{jitter, normal}; use super::reader::{act_with, Reading, Rules}; use crate::exploit::profile::Profile; use crate::game::Street; use crate::rng::Rng; /// Only hands below this strength bluff (as in `reader`). const BLUFF_BELOW: f64 = 0.45; /// How a persona's bet size depends on the strength of its hand. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Tell { /// One size, noise only. Flat, /// Sizes up with strength; bluffs go small. Linear, /// Big with the strong value hands and with bluffs, small with medium value hands. Polar, /// Big bluffs, small value: strong hands size down. Reverse, /// Size drawn from {lo, mid, hi} whatever the hand: no tell (balanced). Mixed, } /// Threshold shifts applied in one context (a texture or a position); `NONE` changes nothing. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Shift { /// Added to `bet_at` (negative: bets more thinly). pub bet_at: f64, /// Added to `raise_at`. pub raise_at: f64, /// Added to `call_margin` (positive: folds more). pub call: f64, /// Multiplies the bluff frequency. pub bluff_mult: f64, } impl Shift { pub const NONE: Shift = Shift { bet_at: 0.0, raise_at: 0.0, call: 0.0, bluff_mult: 1.0 }; } const fn sh(bet_at: f64, raise_at: f64, call: f64, bluff_mult: f64) -> Shift { Shift { bet_at, raise_at, call, bluff_mult } } /// One drawn individual. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Persona { pub label: &'static str, /// Base thresholds (preflop plays these as they are; postflop the shifts are layered on top). pub rules: Rules, pub tell: Tell, /// Small and big end of the size range (pot fractions). pub lo: f64, pub hi: f64, /// Lognormal noise sd on every size: the tell is a tendency, not a rule. pub noise: f64, /// Per `Texture::index()`. pub tex: [Shift; 4], /// Out of position, in position. pub oop: Shift, pub ip: Shift, /// ln pace = `tank_slope` * (strength - 0.5) + `tank_noise` * z. pub tank_slope: f64, pub tank_noise: f64, /// Added to the call margin facing a flop continuation bet (the preflop raiser's first flop bet); /// positive folds more. 0 = treats a c-bet like any bet. pub cbet_call: f64, /// Preflop, after opening and facing a re-raise: continue only from this strength, fold the rest. /// 0 = plays its base thresholds. pub three_bet_continue: f64, /// Check-raise tendency: the chance to check (trap) a hand it would bet when first to act out of /// position before the river, raising a bet after its check from `bet_at` (not `raise_at`), and /// half that chance to check-raise air. 0 = never. pub check_raise: f64, /// The cliche HUD of the archetype (vpip, pfr, fold-to-bet, aggression), measured by `welt_leiter kalib` /// (memory read after 150 deals x 3 individuals): what `ReadMode::Oracle` /// hands the engine. It is the archetype's, not this individual's. pub oracle: [f64; 4], } /// Labels of the archetypes, in `Persona::mean` order. The last three deviate on exactly one HUD axis /// the pooled reads do not see (fold to c-bet, fold to 3-bet, check-raise): the gate for those reads. pub const ARCHETYPES: [&str; 10] = [ "wert-sizer", "polar", "umgekehrt", "textur-cbet", "position", "tanker", "balanciert", "cbet-folder", "3bet-folder", "check-raiser", ]; /// Index of the control archetype. pub const BALANCED: usize = 6; /// Share of the field per archetype (`Persona::sample`). const WEIGHTS: [f64; 10] = [0.18, 0.14, 0.16, 0.14, 0.14, 0.12, 0.12, 0.10, 0.10, 0.10]; const REG: Rules = Rules { call_margin: 0.22, raise_at: 0.82, bet_at: 0.64, open_at: 0.62, bluff: 0.10, size: 2.0 / 3.0 }; impl Persona { /// The mean of archetype `i` (before individual variation). pub fn mean(i: usize) -> Persona { let none = [Shift::NONE; 4]; let base = Persona { label: ARCHETYPES[i], rules: REG, tell: Tell::Flat, lo: 0.33, hi: 1.0, noise: 0.15, tex: none, oop: Shift::NONE, ip: Shift::NONE, tank_slope: 0.0, tank_noise: 0.30, cbet_call: 0.0, three_bet_continue: 0.0, check_raise: 0.0, oracle: [0.31, 0.13, 0.55, 0.30], }; match i { // Sizes up with strength, a little texture awareness. 0 => Persona { tell: Tell::Linear, lo: 0.28, hi: 1.05, noise: 0.26, tex: [Shift::NONE, sh(-0.03, 0.0, -0.02, 1.0), Shift::NONE, sh(0.04, 0.0, 0.03, 0.8)], oracle: [0.45, 0.10, 0.55, 0.33], ..base }, // Polarized: more bluffs, big or small. 1 => Persona { rules: Rules { bet_at: 0.70, bluff: 0.24, call_margin: 0.20, ..REG }, tell: Tell::Polar, lo: 0.33, hi: 1.05, noise: 0.22, oracle: [0.55, 0.11, 0.48, 0.36], ..base }, // Reverse sizing, loose-passive-ish: a fish-like player whose big bets are the weak ones. 2 => Persona { rules: Rules { call_margin: 0.06, raise_at: 0.90, bet_at: 0.70, open_at: 0.72, bluff: 0.14, size: 0.6 }, tell: Tell::Reverse, lo: 0.30, hi: 0.95, noise: 0.28, oracle: [0.93, 0.01, 0.22, 0.27], ..base }, // A c-bot: bets dry/paired boards hard, gives up on wet and monotone ones. Flat size. 3 => Persona { rules: Rules { bet_at: 0.62, bluff: 0.16, ..REG }, tell: Tell::Flat, lo: 0.45, hi: 0.70, noise: 0.12, tex: [sh(-0.14, 0.0, -0.04, 2.2), sh(0.10, 0.04, 0.07, 0.25), sh(-0.06, 0.0, -0.02, 1.8), sh(0.14, 0.05, 0.09, 0.15)], oracle: [0.44, 0.06, 0.58, 0.52], ..base }, // Positional: bets and bluffs in position, shuts down out of it. Flat size. 4 => Persona { rules: Rules { bet_at: 0.64, bluff: 0.12, ..REG }, tell: Tell::Flat, lo: 0.45, hi: 0.65, noise: 0.12, oop: sh(0.10, 0.03, 0.06, 0.35), ip: sh(-0.10, -0.02, -0.04, 1.9), oracle: [0.53, 0.10, 0.49, 0.39], ..base }, // Weak size tell, strong pace tell (tanks with strong hands). 5 => Persona { tell: Tell::Linear, lo: 0.45, hi: 0.75, noise: 0.28, tank_slope: 1.6, tank_noise: 0.35, oracle: [0.45, 0.06, 0.55, 0.37], ..base }, // Control: size independent of strength, no texture or position effect, no pace tell. 6 => Persona { tell: Tell::Mixed, lo: 0.33, hi: 1.0, noise: 0.10, oracle: [0.61, 0.09, 0.42, 0.32], ..base }, // Gives up on the flop to a c-bet, sticky everywhere else (turn/river call down light): a // pooled fold-to-bet averages the two and misprices both. Oracle not calibrated (Memory reads). 7 => Persona { rules: Rules { call_margin: 0.12, ..REG }, tell: Tell::Mixed, noise: 0.10, cbet_call: 0.24, oracle: [0.31, 0.13, 0.50, 0.30], ..base }, // Opens wide, folds to a 3-bet unless strong: a light 3-bet prints against it. 8 => Persona { rules: Rules { open_at: 0.50, ..REG }, tell: Tell::Mixed, noise: 0.10, three_bet_continue: 0.80, oracle: [0.45, 0.30, 0.55, 0.30], ..base }, // Traps out of position and check-raises, strong and air: betting into its check is // riskier than its fold-to-bet says, thin value and stabs lose. _ => Persona { tell: Tell::Mixed, noise: 0.10, check_raise: 0.55, oracle: [0.31, 0.13, 0.50, 0.35], ..base }, } } /// Draw one individual of archetype `i`: every threshold, the size range, the noise, the texture /// and position shifts and the pace tell are perturbed around the archetype mean. The control /// archetype keeps its (absent) texture/position/pace effects and only varies its thresholds. pub fn draw(i: usize, rng: Rng) -> (Persona, Rng) { Persona::draw_around(Persona::mean(i), i == BALANCED, rng) } /// The live micro pool as measured on 14.11. (996 real hands, 0.01/0.02, 6-max): loose and /// sticky, value-heavy when it bets, raises only strong hands and almost never bluffs - the /// river bet is value. NOT one of `ARCHETYPES` (the world field and its draws stay untouched); /// the ladder reaches it as its own row (`ab_zelle` "micro-passiv"). pub fn micro_passiv() -> Persona { let m = Persona::mean(BALANCED); Persona { label: "micro-passiv", rules: Rules { call_margin: 0.08, raise_at: 0.93, bet_at: 0.72, open_at: 0.70, bluff: 0.03, size: 0.6 }, tell: Tell::Flat, lo: 0.35, hi: 0.80, noise: 0.15, oracle: [0.40, 0.12, 0.40, 0.25], ..m } } /// One individual of the micro pool (`micro_passiv`), perturbed like a world archetype. pub fn draw_micro(rng: Rng) -> (Persona, Rng) { Persona::draw_around(Persona::micro_passiv(), false, rng) } fn draw_around(m: Persona, control: bool, rng: Rng) -> (Persona, Rng) { let r = m.rules; let (call_margin, rng) = jitter(r.call_margin, 0.04, 0.0, 0.45, rng); let (raise_at, rng) = jitter(r.raise_at, 0.05, 0.55, 0.97, rng); let (bet_at, rng) = jitter(r.bet_at, 0.05, 0.45, 0.90, rng); let (open_at, rng) = jitter(r.open_at, 0.05, 0.45, 0.85, rng); let (bluff, rng) = jitter(r.bluff, 0.05, 0.0, 0.60, rng); let (lo, rng) = jitter(m.lo, 0.05, 0.20, 0.80, rng); let (hi, rng) = jitter(m.hi, 0.08, lo + 0.10, 1.50, rng); let (noise, rng) = jitter(m.noise, 0.03, 0.05, 0.40, rng); let (tank_slope, rng) = if m.tank_slope > 0.0 { jitter(m.tank_slope, 0.3, 0.3, 3.0, rng) } else { (0.0, rng) }; let (tank_noise, rng) = jitter(m.tank_noise, 0.05, 0.10, 0.60, rng); let mut p = Persona { rules: Rules { call_margin, raise_at, bet_at, open_at, bluff, size: r.size }, lo, hi, noise, tank_slope, tank_noise, ..m }; let mut rng = rng; // The single-axis tendencies (only the archetypes that have one draw them, so every older // archetype's draw sequence is untouched). if p.cbet_call > 0.0 { let (v, r) = jitter(p.cbet_call, 0.04, 0.05, 0.45, rng); (p.cbet_call, rng) = (v, r); } if p.three_bet_continue > 0.0 { let (v, r) = jitter(p.three_bet_continue, 0.04, 0.65, 0.95, rng); (p.three_bet_continue, rng) = (v, r); } if p.check_raise > 0.0 { let (v, r) = jitter(p.check_raise, 0.08, 0.2, 0.9, rng); (p.check_raise, rng) = (v, r); } if !control { for s in p.tex.iter_mut().chain([&mut p.oop, &mut p.ip]) { let (a, r1) = jitter(s.bet_at, 0.025, -0.3, 0.3, rng); let (b, r2) = jitter(s.raise_at, 0.02, -0.2, 0.2, r1); let (c, r3) = jitter(s.call, 0.025, -0.2, 0.2, r2); let (z, r4) = normal(r3); rng = r4; *s = Shift { bet_at: a, raise_at: b, call: c, bluff_mult: (s.bluff_mult * (0.2 * z).exp()).clamp(0.05, 4.0) }; } } (p, rng) } /// Draw an individual from the whole field (archetype by weight). pub fn sample(rng: Rng) -> (Persona, Rng) { let (u, rng) = rng.unit(); let total: f64 = WEIGHTS.iter().sum(); let mut acc = 0.0; let mut pick = WEIGHTS.len() - 1; for (i, w) in WEIGHTS.iter().enumerate() { acc += w / total; if u <= acc { pick = i; break; } } Persona::draw(pick, rng) } /// The cliche HUD read of the archetype (see `oracle`). pub fn oracle_profile(&self) -> Profile { let [vpip, pfr, fold_to_bet, aggression] = self.oracle; Profile { vpip: Some(vpip), pfr: Some(pfr), fold_to_bet: Some(fold_to_bet), aggression: Some(aggression), ..Profile::default() } } /// Bet or raise size as a pot fraction for a hand of `strength`; `bluff` marks a bluff. The tell /// plus lognormal noise, clamped to a playable range. pub fn size_frac(&self, strength: f64, bluff: bool, rng: Rng) -> (f64, Rng) { let x = ((strength - 0.5) / 0.45).clamp(0.0, 1.0); let (base, rng) = match self.tell { Tell::Flat => ((self.lo + self.hi) / 2.0, rng), Tell::Linear => (if bluff { self.lo } else { self.lo + (self.hi - self.lo) * x }, rng), Tell::Polar => (if bluff || strength >= 0.88 { self.hi } else { self.lo }, rng), Tell::Reverse => (if bluff { self.hi } else { self.hi - (self.hi - self.lo) * x }, rng), Tell::Mixed => { let (k, rng) = rng.below(3); ([self.lo, (self.lo + self.hi) / 2.0, self.hi][k as usize], rng) } }; let (z, rng) = normal(rng); ((base * (self.noise * z).exp()).clamp(0.15, 1.8), rng) } /// Pace of one decision relative to the persona's usual (1.0): lognormal around a level that rises /// with strength by `tank_slope`. pub fn tank_factor(&self, strength: f64, rng: Rng) -> (f64, Rng) { let (z, rng) = normal(rng); ((self.tank_slope * (strength - 0.5) + self.tank_noise * z).exp(), rng) } } /// What the table tells a persona about the spot. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Ctx { pub reading: Reading, pub street: Street, pub texture: Texture, pub pos: Pos, /// Facing the preflop raiser's first flop bet (a continuation bet). pub facing_cbet: bool, /// Preflop, it opened and now faces a re-raise. pub facing_three_bet: bool, /// It already checked on this street (a bet now faces it after its check). pub checked_here: bool, } /// The persona's action. Preflop it plays its base thresholds (`reader::act_with`); postflop the /// thresholds are shifted by the board texture and its position, and bets are sized by its tell. pub fn act(p: &Persona, view: View, ctx: &Ctx, rng: Rng) -> (Act, Rng) { if ctx.street == Street::Preflop { if ctx.facing_three_bet && p.three_bet_continue > 0.0 && view.to_call > 0.0 && ctx.reading.strength < p.three_bet_continue { return (Act::Fold, rng); } return act_with(p.rules, view, ctx.reading, rng); } let s = ctx.reading.strength; let to_call = view.to_call; let t = p.tex[ctx.texture.index()]; let ps = if ctx.pos == Pos::Ip { p.ip } else { p.oop }; let bet_at = p.rules.bet_at + t.bet_at + ps.bet_at; let raise_at = p.rules.raise_at + t.raise_at + ps.raise_at; let cbet = if ctx.facing_cbet { p.cbet_call } else { 0.0 }; let margin = (p.rules.call_margin + t.call + ps.call + cbet).max(0.0); let bluff = (p.rules.bluff * t.bluff_mult * ps.bluff_mult).clamp(0.0, 0.9); let can_raise = view.min_raise_to.is_some(); let sized = |bluff_hand: bool, rng: Rng| { let (frac, rng) = p.size_frac(s, bluff_hand, rng); (Act::RaiseTo(ctx.reading.own_bet + to_call + frac * (ctx.reading.pot + to_call)), rng) }; if to_call > 0.0 { if can_raise && s >= raise_at { return sized(false, rng); } let mut rng = rng; if p.check_raise > 0.0 && can_raise && ctx.checked_here { if s >= bet_at { return sized(false, rng); // the trapped hand springs } if s < BLUFF_BELOW { let (u, r) = rng.unit(); rng = r; if u < p.check_raise / 2.0 { return sized(true, rng); } } } let price = to_call / (ctx.reading.pot + to_call); return (if s >= price + margin { Act::Call } else { Act::Fold }, rng); } if can_raise && s >= bet_at { if p.check_raise > 0.0 && ctx.pos == Pos::Oop && ctx.street != Street::River { let (u, rng) = rng.unit(); if u < p.check_raise { return (Act::Check, rng); // trap: check to raise } return sized(false, rng); } return sized(false, rng); } if can_raise && s < BLUFF_BELOW { let (u, rng) = rng.unit(); if u < bluff { return sized(true, rng); } return (Act::Check, rng); } (Act::Check, rng) } #[cfg(test)] mod tests { use super::*; fn pearson(xs: &[f64], ys: &[f64]) -> f64 { let n = xs.len() as f64; let (mx, my) = (xs.iter().sum::() / n, ys.iter().sum::() / n); let cov: f64 = xs.iter().zip(ys).map(|(x, y)| (x - mx) * (y - my)).sum(); let vx: f64 = xs.iter().map(|x| (x - mx).powi(2)).sum(); let vy: f64 = ys.iter().map(|y| (y - my).powi(2)).sum(); cov / (vx * vy).sqrt() } /// Correlation of size with the strength behind it, over uniformly drawn strengths for the value /// hands (>= bet_at) and bluffs (< BLUFF_BELOW), as the persona would bet them. fn size_corr(p: &Persona, n: usize, seed: u64) -> f64 { let mut rng = Rng::seeded(seed); let (mut xs, mut ys) = (vec![], vec![]); while xs.len() < n { let (s, r1) = rng.unit(); let (f, r2) = p.size_frac(s, s < BLUFF_BELOW, r1); rng = r2; if s >= p.rules.bet_at || s < BLUFF_BELOW { xs.push(s); ys.push(f); } } pearson(&xs, &ys) } fn arch(i: usize, seed: u64) -> Persona { Persona::draw(i, Rng::seeded(seed)).0 } #[test] fn draws_are_deterministic_and_individual() { let a = Persona::draw(0, Rng::seeded(5)).0; let b = Persona::draw(0, Rng::seeded(5)).0; assert_eq!(a, b); let c = Persona::draw(0, Rng::seeded(6)).0; assert_ne!(a, c, "same archetype, different seed: a different individual"); // Intra-archetype spread: bet_at across 200 draws of one archetype is not a constant. let v: Vec = (0..200).map(|k| arch(1, k).rules.bet_at).collect(); let mean = v.iter().sum::() / v.len() as f64; let sd = (v.iter().map(|x| (x - mean).powi(2)).sum::() / v.len() as f64).sqrt(); assert!(sd > 0.03, "sd {sd}"); assert_eq!(Persona::draw(2, Rng::seeded(9)).0.label, "umgekehrt"); } #[test] fn draws_stay_playable() { for i in 0..ARCHETYPES.len() { for k in 0..300 { let p = arch(i, 1000 + k); assert!(p.lo >= 0.2 && p.hi > p.lo && p.hi <= 1.5, "{p:?}"); assert!((0.0..=0.45).contains(&p.rules.call_margin)); assert!((0.45..=0.90).contains(&p.rules.bet_at)); assert!(p.tex.iter().chain([&p.oop, &p.ip]).all(|s| s.bluff_mult > 0.0)); } } } #[test] fn sizing_tells_have_the_intended_sign() { // wert-sizer: sizes up with strength; umgekehrt: down; tanker: weak positive; balanced: none. let up = (0..10).map(|k| size_corr(&arch(0, 40 + k), 3000, 1 + k)).sum::() / 10.0; let rev = (0..10).map(|k| size_corr(&arch(2, 60 + k), 3000, 1 + k)).sum::() / 10.0; let bal = (0..10).map(|k| size_corr(&arch(BALANCED, 80 + k), 3000, 1 + k)).sum::() / 10.0; println!("corr(size, strength): wert-sizer {up:+.2}, umgekehrt {rev:+.2}, balanciert {bal:+.2}"); assert!(up > 0.4, "{up}"); assert!(rev < -0.15, "{rev}"); assert!(bal.abs() < 0.08, "{bal}"); } #[test] fn polar_bets_big_with_the_nuts_and_with_air() { let p = arch(1, 3); let mean_size = |s: f64, bluff: bool| { let mut rng = Rng::seeded(17); let mut sum = 0.0; for _ in 0..2000 { let (f, r) = p.size_frac(s, bluff, rng); rng = r; sum += f; } sum / 2000.0 }; let (nuts, mid, air) = (mean_size(0.95, false), mean_size(0.72, false), mean_size(0.2, true)); println!("polar: nuts {nuts:.2} mid {mid:.2} air {air:.2}"); assert!(nuts > mid + 0.25 && air > mid + 0.25); } #[test] fn texture_and_position_move_the_bet_rate() { // textur-cbet: bet rate on a dry board beats the monotone one; position: ip beats oop. let bet_rate = |p: &Persona, texture: Texture, pos: Pos| { let mut rng = Rng::seeded(23); let mut bets = 0; let n = 4000; for _ in 0..n { let (s, r) = rng.unit(); let ctx = Ctx { reading: Reading { strength: s, pot: 4.0, own_bet: 0.0, preflop: false }, street: Street::Flop, texture, pos, facing_cbet: false, facing_three_bet: false, checked_here: false, }; let view = View { to_call: 0.0, min_raise_to: Some(1.0), max_raise_to: Some(100.0) }; let (a, r2) = act(p, view, &ctx, r); rng = r2; bets += matches!(a, Act::RaiseTo(_)) as u32; } bets as f64 / n as f64 }; let tex = arch(3, 7); let (dry, mono) = (bet_rate(&tex, Texture::Dry, Pos::Ip), bet_rate(&tex, Texture::Monotone, Pos::Ip)); println!("textur-cbet: dry {dry:.2} mono {mono:.2}"); assert!(dry > mono + 0.15); let posi = arch(4, 8); let (ip, oop) = (bet_rate(&posi, Texture::Dry, Pos::Ip), bet_rate(&posi, Texture::Dry, Pos::Oop)); println!("position: ip {ip:.2} oop {oop:.2}"); assert!(ip > oop + 0.15); // The control does not care. let bal = arch(BALANCED, 9); let (a, b) = (bet_rate(&bal, Texture::Dry, Pos::Ip), bet_rate(&bal, Texture::Monotone, Pos::Oop)); assert!((a - b).abs() < 0.03, "{a} vs {b}"); } /// The three single-axis archetypes deviate exactly where their HUD stat says. #[test] fn the_line_archetypes_play_their_line() { let ctx = |strength: f64, street: Street, pos: Pos, cbet: bool, three: bool, checked: bool| Ctx { reading: Reading { strength, pot: 4.0, own_bet: 0.0, preflop: street == Street::Preflop }, street, texture: Texture::Dry, pos, facing_cbet: cbet, facing_three_bet: three, checked_here: checked, }; let facing = View { to_call: 2.0, min_raise_to: Some(4.0), max_raise_to: Some(100.0) }; let open = View { to_call: 0.0, min_raise_to: Some(1.0), max_raise_to: Some(100.0) }; let rate = |p: &Persona, view: View, c: &dyn Fn(f64) -> Ctx, pick: fn(&Act) -> bool| { let mut rng = Rng::seeded(31); let mut hits = 0; for _ in 0..3000 { let (s, r) = rng.unit(); let (a, r2) = act(p, view, &c(s), r); rng = r2; hits += pick(&a) as u32; } hits as f64 / 3000.0 }; let fold = |a: &Act| matches!(a, Act::Fold); let raise = |a: &Act| matches!(a, Act::RaiseTo(_)); let check = |a: &Act| matches!(a, Act::Check); let cf = arch(7, 1); let vs_cbet = rate(&cf, facing, &|s| ctx(s, Street::Flop, Pos::Oop, true, false, false), fold); let vs_bet = rate(&cf, facing, &|s| ctx(s, Street::Flop, Pos::Oop, false, false, false), fold); println!("cbet-folder folds c-bet {vs_cbet:.2}, other bet {vs_bet:.2}"); assert!(vs_cbet > vs_bet + 0.15); let tf = arch(8, 2); let vs_three = rate(&tf, facing, &|s| ctx(s, Street::Preflop, Pos::Ip, false, true, false), fold); let vs_open = rate(&tf, facing, &|s| ctx(s, Street::Preflop, Pos::Ip, false, false, false), fold); println!("3bet-folder folds 3-bet {vs_three:.2}, other raise {vs_open:.2}"); assert!(vs_three > vs_open + 0.15); let xr = arch(9, 3); let traps = rate(&xr, open, &|s| ctx(s, Street::Flop, Pos::Oop, false, false, false), check); let reg_checks = rate(&arch(BALANCED, 3), open, &|s| ctx(s, Street::Flop, Pos::Oop, false, false, false), check); let springs = rate(&xr, facing, &|s| ctx(s, Street::Flop, Pos::Oop, false, false, true), raise); let reg_raises = rate(&arch(BALANCED, 3), facing, &|s| ctx(s, Street::Flop, Pos::Oop, false, false, true), raise); println!("check-raiser checks {traps:.2} (control {reg_checks:.2}), raises after check {springs:.2} (control {reg_raises:.2})"); assert!(traps > reg_checks + 0.05 && springs > reg_raises + 0.1); } #[test] fn the_tanker_slows_down_with_strength() { let p = arch(5, 11); let mut rng = Rng::seeded(2); let (mut ss, mut ts) = (vec![], vec![]); for _ in 0..3000 { let (s, r1) = rng.unit(); let (t, r2) = p.tank_factor(s, r1); rng = r2; ss.push(s); ts.push(t.ln()); } let c = pearson(&ss, &ts); println!("tanker corr(ln pace, strength) {c:+.2}"); assert!(c > 0.3); let q = arch(BALANCED, 12); let mut rng = Rng::seeded(3); let (mut ss, mut ts) = (vec![], vec![]); for _ in 0..3000 { let (s, r1) = rng.unit(); let (t, r2) = q.tank_factor(s, r1); rng = r2; ss.push(s); ts.push(t.ln()); } assert!(pearson(&ss, &ts).abs() < 0.08); } #[test] fn the_table_logs_world_events_and_the_memory_learns() { use crate::sim::memory::SessionMemory; use crate::sim::opponent::Opponent; use crate::sim::table::{deal, play_hand_tracked, HandRead, HandSetup, TableCost}; let persona = arch(0, 21); let mut mem = SessionMemory::new(); for d in 0..40u64 { let (cards, _) = deal(2, Rng::seeded(500 + d)); for hero_seat in 1..=2u8 { let hand = HandSetup { deal: &cards, hero_seat, opponent: Opponent::Welt(persona), stack_bb: 100.0, seed: 9000 + d * 3 + hero_seat as u64, read: HandRead::Given(None), }; let r = play_hand_tracked(&hand, TableCost::FREE, Some(&mut mem)); assert_eq!(r.invalid, 0); assert!(r.chips_lost.abs() < 1e-6); } } let w = mem.world(); assert_eq!(w.hands(), 80); let acts: u32 = [Texture::Dry, Texture::Wet, Texture::Paired, Texture::Monotone] .iter() .flat_map(|t| [Pos::Ip, Pos::Oop].map(move |p| (*t, p))) .map(|(t, p)| { let c = w.cell_all_streets(t, p); c.open_spots() + c.facing_spots() }) .sum(); assert!(acts > 5, "postflop events logged: {acts}"); // The classic HUD read is untouched by the world memory. assert!(mem.read().is_some()); } #[test] fn world_play_leaves_other_opponents_unlogged() { use crate::sim::memory::SessionMemory; use crate::sim::opponent::Opponent; use crate::sim::reader::Style; use crate::sim::table::{deal, play_hand_tracked, HandRead, HandSetup, TableCost}; let mut mem = SessionMemory::new(); let (cards, _) = deal(2, Rng::seeded(5)); let hand = HandSetup { deal: &cards, hero_seat: 1, opponent: Opponent::Reader(Style::Reg), stack_bb: 100.0, seed: 1, read: HandRead::Given(None), }; play_hand_tracked(&hand, TableCost::FREE, Some(&mut mem)); assert_eq!(mem.world().hands(), 0); } #[test] fn the_field_draws_every_archetype() { let mut rng = Rng::seeded(77); let mut seen = [0u32; ARCHETYPES.len()]; for _ in 0..3000 { let (p, r) = Persona::sample(rng); rng = r; seen[ARCHETYPES.iter().position(|l| *l == p.label).expect("label")] += 1; } assert!(seen.iter().all(|c| *c > 150), "{seen:?}"); } }