Files
pokerfreak/src/sim/welt.rs
T

1086 lines
48 KiB
Rust

//! 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],
/// Real-pool lines (plan §8, `pool-nl2-echt`, all 0 = off, every other persona unchanged):
/// per postflop street (flop, turn, river) the share of bets and raises in the four size classes of
/// `lesen/linien.py` (<= 0.4, <= 0.8, <= 1.2, above, pot fractions), strength-independent. All zero
/// for a street: the tell sizes as before.
pub size_mix: [[f64; 4]; 3],
/// Price sensitivity of the call: the call margin is scaled by (bet / pot / 0.6)^`call_size_exp`
/// (bet = what it faces, pot before that bet), so a small bet is called much wider than a big one.
/// 0 = a flat margin.
pub call_size_exp: f64,
/// Facing a bet with air (below `BLUFF_BELOW`): the chance to raise anyway. 0 = never.
pub raise_bluff: f64,
/// Facing a raise over its own bet/raise on this street: from this strength it goes all-in (instead of
/// a sized re-raise). 0 = off (sized as before).
pub raise_shove_at: f64,
/// Same spot, a medium hand (`BLUFF_BELOW` .. `raise_shove_at`, draws and pairs): the chance to go
/// all-in anyway (semi-bluff stack-off). 0 = never.
pub raise_shove_semi: f64,
/// Same spot: added to the call margin (positive folds more against a raise). 0 = as a bet.
pub raise_call_margin: f64,
/// Bluff rate per postflop street (flop, turn, river) in place of `rules.bluff` (texture and position
/// still multiply it), from real showdowns per line (`lesen/phh_linien.py`, PHH prior + NL2). Negative =
/// off, the street bluffs at `rules.bluff` as before.
pub bluff_street: [f64; 3],
}
/// Representative pot fraction of each `size_mix` class (inside its class even with the noise).
const MIX_FRAC: [f64; 4] = [0.30, 0.60, 1.00, 1.60];
/// 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],
size_mix: [[0.0; 4]; 3],
call_size_exp: 0.0,
raise_bluff: 0.0,
raise_shove_at: 0.0,
raise_shove_semi: 0.0,
raise_call_margin: 0.0,
bluff_street: [-1.0; 3],
};
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)
}
/// The persona of a calibrated real pool (plan D2 Eichschleife, `lesen/pool.py persona`): the micro
/// pool as base, every field the JSON names replaced (`call_margin raise_at bet_at open_at bluff size
/// lo hi noise cbet_call three_bet_continue check_raise`, `oracle` as [vpip, pfr, foldToBet,
/// aggression], `label`). Unknown keys are an error, so a typo never silently plays the base.
pub fn from_pool_json(text: &str) -> Result<Persona, String> {
use crate::json::value::Value;
let v = crate::json::parse::parse(text).map_err(|e| format!("{e:?}"))?;
let Value::Object(felder) = v else { return Err("pool persona: object expected".into()) };
let mut p = Persona::micro_passiv();
for (k, x) in felder {
let zahl = || match x {
Value::Number(n) if n.is_finite() => Ok(n),
_ => Err(format!("pool persona: {k} must be a number")),
};
match k.as_str() {
"call_margin" => p.rules.call_margin = zahl()?,
"raise_at" => p.rules.raise_at = zahl()?,
"bet_at" => p.rules.bet_at = zahl()?,
"open_at" => p.rules.open_at = zahl()?,
"bluff" => p.rules.bluff = zahl()?,
"size" => p.rules.size = zahl()?,
"lo" => p.lo = zahl()?,
"hi" => p.hi = zahl()?,
"noise" => p.noise = zahl()?,
"cbet_call" => p.cbet_call = zahl()?,
"three_bet_continue" => p.three_bet_continue = zahl()?,
"check_raise" => p.check_raise = zahl()?,
"call_size_exp" => p.call_size_exp = zahl()?,
"raise_bluff" => p.raise_bluff = zahl()?,
"raise_shove_at" => p.raise_shove_at = zahl()?,
"raise_shove_semi" => p.raise_shove_semi = zahl()?,
"raise_call_margin" => p.raise_call_margin = zahl()?,
"bluff_flop" => p.bluff_street[0] = zahl()?,
"bluff_turn" => p.bluff_street[1] = zahl()?,
"bluff_river" => p.bluff_street[2] = zahl()?,
"size_mix_flop" | "size_mix_turn" | "size_mix_river" => {
let i = match k.as_str() {
"size_mix_flop" => 0,
"size_mix_turn" => 1,
_ => 2,
};
match &x {
Value::Array(a) if a.len() == 4 => {
for (j, e) in a.iter().enumerate() {
let Value::Number(n) = e else { return Err(format!("pool persona: {k} numbers")) };
p.size_mix[i][j] = *n;
}
}
_ => return Err(format!("pool persona: {k} = [klein, mittel, gross, ueber]")),
}
}
"oracle" => match &x {
Value::Array(a) if a.len() == 4 => {
for (i, e) in a.iter().enumerate() {
let Value::Number(n) = e else { return Err("pool persona: oracle numbers".into()) };
p.oracle[i] = *n;
}
}
_ => return Err("pool persona: oracle = [vpip, pfr, foldToBet, aggression]".into()),
},
"label" => match &x {
Value::String(s) => p.label = Box::leak(s.clone().into_boxed_str()),
_ => return Err("pool persona: label must be a string".into()),
},
// informational fields of lesen/pool.py (version, targets) are allowed
_ if k.starts_with('_') => {}
other => return Err(format!("pool persona: unknown field {other}")),
}
}
Ok(p)
}
/// One individual of a calibrated pool persona (`from_pool_json`), perturbed like a world archetype,
/// but the three fitted axes keep their own wide bounds: the archetype clamps (call_margin <= 0.45,
/// cbet_call >= 0.05, check_raise >= 0.2 once non-zero) would make a fitted value unreachable
/// (the real NL2 field folds more than any archetype).
pub fn draw_pool(m: Persona, rng: Rng) -> (Persona, Rng) {
let basis = Persona { cbet_call: 0.0, check_raise: 0.0, ..m };
let (mut p, rng) = Persona::draw_around(basis, false, rng);
let (cm, rng) = jitter(m.rules.call_margin, 0.04, 0.0, 0.95, rng);
let (cc, rng) = if m.cbet_call > 0.0 { jitter(m.cbet_call, 0.04, 0.0, 0.9, rng) } else { (0.0, rng) };
let (xr, rng) = if m.check_raise > 0.0 { jitter(m.check_raise, 0.02, 0.0, 0.9, rng) } else { (0.0, rng) };
p.rules.call_margin = cm;
p.cbet_call = cc;
p.check_raise = xr;
(p, 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) {
self.size_frac_on(None, strength, bluff, rng)
}
/// `size_frac` on a postflop street: with a `size_mix` for that street the class is drawn from the
/// mix (strength-independent), the size is its representative fraction with the noise.
pub fn size_frac_on(&self, street: Option<Street>, strength: f64, bluff: bool, rng: Rng) -> (f64, Rng) {
let mix = match street {
Some(Street::Flop) => Some(self.size_mix[0]),
Some(Street::Turn) => Some(self.size_mix[1]),
Some(Street::River) => Some(self.size_mix[2]),
_ => None,
};
if let Some(m) = mix.filter(|m| m.iter().sum::<f64>() > 0.0) {
let (u, rng) = rng.unit();
let total: f64 = m.iter().sum();
let mut acc = 0.0;
let mut pick = 3;
for (i, w) in m.iter().enumerate() {
acc += w / total;
if u <= acc {
pick = i;
break;
}
}
let (z, rng) = normal(rng);
return ((MIX_FRAC[pick] * (0.10 * z).exp()).clamp(0.15, 1.8), 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 basis = match ctx.street {
Street::Flop if p.bluff_street[0] >= 0.0 => p.bluff_street[0],
Street::Turn if p.bluff_street[1] >= 0.0 => p.bluff_street[1],
Street::River if p.bluff_street[2] >= 0.0 => p.bluff_street[2],
_ => p.rules.bluff,
};
let bluff = (basis * 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_on(Some(ctx.street), s, bluff_hand, rng);
(Act::RaiseTo(ctx.reading.own_bet + to_call + frac * (ctx.reading.pot + to_call)), rng)
};
// Facing a raise over its own bet or raise on this street (postflop: own_bet > 0 and more to call).
let facing_raise = to_call > 0.0 && ctx.reading.own_bet > 0.0;
let mut rng = rng;
if facing_raise && can_raise && p.raise_shove_at > 0.0 {
let shove = Act::RaiseTo(view.max_raise_to.unwrap_or(f64::MAX));
if s >= p.raise_shove_at {
return (shove, rng);
}
if s >= BLUFF_BELOW && p.raise_shove_semi > 0.0 {
let (u, r) = rng.unit();
rng = r;
if u < p.raise_shove_semi {
return (shove, rng);
}
}
}
let margin = if facing_raise { margin + p.raise_call_margin } else { margin };
if to_call > 0.0 {
if can_raise && s >= raise_at {
return sized(false, 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);
}
}
}
if p.raise_bluff > 0.0 && can_raise && s < BLUFF_BELOW {
let (u, r) = rng.unit();
rng = r;
if u < p.raise_bluff {
return sized(true, rng);
}
}
let price = to_call / (ctx.reading.pot + to_call);
let margin = if p.call_size_exp != 0.0 {
// the bet it faces against the pot before that bet (pot here already holds the bet)
let frac = to_call / (ctx.reading.pot - to_call).max(1e-9);
margin * (frac.max(0.05) / 0.6).powf(p.call_size_exp)
} else {
margin
};
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)
}
/// Which pool-persona file a run measures against, pinned per output folder (plan §8, Nachfuehrung).
///
/// `wert` is `POOL_PERSONA`: a file (as before), or `<ordner>/<name>@aktuell`. That second form is the
/// version the pointer `<ordner>/<name>-aktuell.txt` names (`lesen/pool_nachfuehren.py` writes it).
/// The first run in `out` writes `out/pool.version` ("<file> <fnv64 of the text>"). A resumed run measures
/// against exactly that file again: with `@aktuell` it keeps the pinned version after a promotion, and
/// with a file that changed in the meantime it refuses (`Err`). Comparisons do not wander.
/// -> (the file to read, the version line).
pub fn pool_version(wert: &str, out: &std::path::Path) -> Result<(std::path::PathBuf, String), String> {
use std::path::{Path, PathBuf};
let pin = out.join("pool.version");
let gepinnt = std::fs::read_to_string(&pin).ok().map(|z| z.trim().to_string()).filter(|z| !z.is_empty());
let pfad: PathBuf = match wert.strip_suffix("@aktuell") {
Some(stamm) => {
let p = Path::new(stamm);
let ordner = p.parent().unwrap_or(Path::new("."));
let name = p.file_name().and_then(|n| n.to_str()).ok_or_else(|| format!("POOL_PERSONA {wert}: kein Name"))?;
let datei = match &gepinnt {
Some(z) => z.split_whitespace().next().unwrap_or("").to_string(),
None => {
let zeiger = ordner.join(format!("{name}-aktuell.txt"));
std::fs::read_to_string(&zeiger).map_err(|e| format!("{}: {e}", zeiger.display()))?.trim().to_string()
}
};
ordner.join(datei)
}
None => PathBuf::from(wert),
};
let text = std::fs::read_to_string(&pfad).map_err(|e| format!("POOL_PERSONA {}: {e}", pfad.display()))?;
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
for b in text.replace("\r\n", "\n").bytes() {
h = (h ^ b as u64).wrapping_mul(0x0100_0000_01b3);
}
let datei = pfad.file_name().and_then(|n| n.to_str()).unwrap_or("?");
let zeile = format!("{datei} {h:016x}");
match gepinnt {
Some(z) if z != zeile => Err(format!("{}: gemessen gegen {z}, jetzt {zeile}; neuer Ordner fuer eine neue Version", pin.display())),
Some(_) => Ok((pfad, zeile)),
None => {
std::fs::create_dir_all(out).map_err(|e| e.to_string())?;
std::fs::write(&pin, format!("{zeile}
")).map_err(|e| e.to_string())?;
Ok((pfad, zeile))
}
}
}
#[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::<f64>() / n, ys.iter().sum::<f64>() / 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 size_mix_draws_the_classes_of_the_mix() {
let mut p = Persona::micro_passiv();
p.size_mix[2] = [0.2, 0.5, 0.2, 0.1];
let mut rng = Rng::seeded(11);
let mut n = [0usize; 4];
for _ in 0..20_000 {
let (f, r) = p.size_frac_on(Some(Street::River), 0.5, false, rng);
rng = r;
n[if f <= 0.40 { 0 } else if f <= 0.80 { 1 } else if f <= 1.20 { 2 } else { 3 }] += 1;
}
for (k, w) in [0.2, 0.5, 0.2, 0.1].iter().enumerate() {
assert!((n[k] as f64 / 20_000.0 - w).abs() < 0.02, "{k}: {n:?}");
}
// flop without a mix: the tell as before, bit for bit
let (a, _) = p.size_frac_on(Some(Street::Flop), 0.7, false, Rng::seeded(3));
let (b, _) = p.size_frac(0.7, false, Rng::seeded(3));
assert_eq!(a, b);
}
#[test]
fn pool_json_reads_the_line_fields() {
let p = Persona::from_pool_json(
r#"{"label":"pool-nl2-echt","size_mix_turn":[0.3,0.5,0.1,0.1],"call_size_exp":1.2,"raise_bluff":0.05}"#,
)
.unwrap();
assert_eq!(p.size_mix[1], [0.3, 0.5, 0.1, 0.1]);
assert_eq!(p.size_mix[0], [0.0; 4]);
assert_eq!((p.call_size_exp, p.raise_bluff), (1.2, 0.05));
assert!(Persona::from_pool_json(r#"{"size_mix_flop":[1,2]}"#).is_err());
assert_eq!(Persona::micro_passiv().size_mix, [[0.0; 4]; 3]);
let q = Persona::from_pool_json(r#"{"raise_shove_at":0.8,"raise_shove_semi":0.2,"raise_call_margin":0.1}"#).unwrap();
assert_eq!((q.raise_shove_at, q.raise_shove_semi, q.raise_call_margin), (0.8, 0.2, 0.1));
assert_eq!(q.bluff_street, [-1.0; 3], "without the keys every street bluffs at rules.bluff");
let b = Persona::from_pool_json(r#"{"bluff_river":0.12,"bluff_flop":0}"#).unwrap();
assert_eq!(b.bluff_street, [0.0, -1.0, 0.12]);
assert_eq!(Persona::micro_passiv().raise_shove_at, 0.0);
}
#[test]
fn pool_version_pins_the_file_per_run() {
let d = std::env::temp_dir().join(format!("pool_version_{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
let pool = d.join("pool");
std::fs::create_dir_all(&pool).unwrap();
std::fs::write(pool.join("nl2-echt-a.json"), r#"{"call_margin":0.2}"#).unwrap();
std::fs::write(pool.join("nl2-echt-b.json"), r#"{"call_margin":0.3}"#).unwrap();
std::fs::write(pool.join("nl2-echt-aktuell.txt"), "nl2-echt-a.json
").unwrap();
let wert = format!("{}/nl2-echt@aktuell", pool.display());
let lauf = d.join("tor");
let (p, z) = pool_version(&wert, &lauf).unwrap();
assert!(p.ends_with("nl2-echt-a.json") && z.starts_with("nl2-echt-a.json "), "{z}");
// promoted meanwhile: the running gate keeps a, a new gate gets b
std::fs::write(pool.join("nl2-echt-aktuell.txt"), "nl2-echt-b.json").unwrap();
assert!(pool_version(&wert, &lauf).unwrap().0.ends_with("nl2-echt-a.json"));
assert!(pool_version(&wert, &d.join("tor2")).unwrap().0.ends_with("nl2-echt-b.json"));
// a plain file as before; changed under a running gate -> refused
let f = pool.join("nl2-echt-b.json");
let lauf3 = d.join("tor3");
pool_version(f.to_str().unwrap(), &lauf3).unwrap();
std::fs::write(&f, r#"{"call_margin":0.4}"#).unwrap();
assert!(pool_version(f.to_str().unwrap(), &lauf3).is_err());
let _ = std::fs::remove_dir_all(&d);
}
#[test]
fn raised_over_its_bet_it_shoves_strong_and_some_draws() {
let mut p = Persona::micro_passiv();
let ctx = |strength: f64, own_bet: f64| Ctx {
reading: Reading { strength, pot: 20.0, own_bet, preflop: false },
street: Street::Turn,
texture: Texture::Dry,
pos: Pos::Oop,
facing_cbet: false,
facing_three_bet: false,
checked_here: false,
};
let raised = View { to_call: 6.0, min_raise_to: Some(14.0), max_raise_to: Some(90.0) };
// off (0): the sized raise as before, never the whole stack
let (a, _) = act(&p, raised, &ctx(0.97, 4.0), Rng::seeded(3));
assert!(matches!(a, Act::RaiseTo(x) if x < 90.0), "{a:?}");
p.raise_shove_at = 0.85;
p.raise_shove_semi = 0.5;
assert_eq!(act(&p, raised, &ctx(0.90, 4.0), Rng::seeded(3)).0, Act::RaiseTo(90.0));
// a first bet against it (own_bet 0) is not a raise over its bet: no shove
assert!(!matches!(act(&p, raised, &ctx(0.90, 0.0), Rng::seeded(3)).0, Act::RaiseTo(x) if x >= 90.0));
// medium hands: about half of them
let mut rng = Rng::seeded(11);
let mut n = 0;
for _ in 0..2000 {
let (a, r) = act(&p, raised, &ctx(0.60, 4.0), rng);
rng = r;
n += (a == Act::RaiseTo(90.0)) as u32;
}
assert!((800..1200).contains(&n), "{n}");
}
#[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<f64> = (0..200).map(|k| arch(1, k).rules.bet_at).collect();
let mean = v.iter().sum::<f64>() / v.len() as f64;
let sd = (v.iter().map(|x| (x - mean).powi(2)).sum::<f64>() / 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::<f64>() / 10.0;
let rev = (0..10).map(|k| size_corr(&arch(2, 60 + k), 3000, 1 + k)).sum::<f64>() / 10.0;
let bal = (0..10).map(|k| size_corr(&arch(BALANCED, 80 + k), 3000, 1 + k)).sum::<f64>() / 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:?}");
}
#[test]
fn pool_persona_overrides_and_rejects_typos() {
let p = Persona::from_pool_json(r#"{"call_margin":0.2,"cbet_call":0.1,"oracle":[0.3,0.2,0.55,0.3],"label":"pool-x","_version":"v1"}"#).unwrap();
assert_eq!(p.rules.call_margin, 0.2);
assert_eq!(p.cbet_call, 0.1);
assert_eq!(p.oracle, [0.3, 0.2, 0.55, 0.3]);
assert_eq!(p.label, "pool-x");
assert_eq!(p.rules.bet_at, Persona::micro_passiv().rules.bet_at, "unnamed fields keep the micro base");
assert!(Persona::from_pool_json(r#"{"call_margn":0.2}"#).is_err());
let a = Persona::draw_pool(p, Rng::seeded(3)).0;
let b = Persona::draw_pool(p, Rng::seeded(3)).0;
assert_eq!(a.rules.call_margin, b.rules.call_margin, "deterministic per seed");
let q = Persona::from_pool_json(r#"{"call_margin":0.7,"cbet_call":0.6,"check_raise":0.05}"#).unwrap();
let d = Persona::draw_pool(q, Rng::seeded(4)).0;
assert!(d.rules.call_margin > 0.55, "no archetype cap at 0.45: {}", d.rules.call_margin);
assert!(d.cbet_call > 0.45 && d.check_raise < 0.15, "own bounds: {} {}", d.cbet_call, d.check_raise);
}
}