//! Spec: `PREFLOP_VOLL` answers preflop from solutions where only the range rules answered before. //! //! Live 14.11. (2776 real preflop requests): the frozen tables answered 63.6 %, the rest fell on //! range rules (deep stacks > 100 bb, heads-up, limp pots, squeeze / overcall, cold vs 3-bet, 4-bet). //! The switch adds the deep multi tables, the heads-up blind game, and solved Teilspiele with a //! pseudo-harmonic size translation. `tests/live_fixture/preflop_voll_2026-11-14.jsonl` holds two //! real requests per (line class, depth band, CFR yes/no) with the answer of the live core (off). //! //! The switch is process-global: everything that toggles it runs in ONE test, in order. use rechner::cfr::hand_class::{class_combos, class_parse, CLASS_COUNT}; use rechner::cfr::defenders::Place; use rechner::cfr::teilspiel_plan::{loese_zelle, plan, umgebung, Art, Zelle, ITERATIONEN}; use rechner::guard::validate::check; use rechner::json::{parse, render, Value}; use rechner::preflop::teilspiel_lookup::{familie, mische, pseudo_harmonisch}; use rechner::preflop::voll::set_voll; use rechner::wire::decode::decode; use rechner::wire::respond::respond; const FIXTURE: &str = include_str!("live_fixture/preflop_voll_2026-11-14.jsonl"); fn field<'a>(v: &'a Value, key: &str) -> &'a Value { match v { Value::Object(fields) => &fields.iter().find(|(k, _)| k == key).unwrap_or_else(|| panic!("no {key}")).1, _ => panic!("not an object"), } } fn text(v: &Value, key: &str) -> String { match field(v, key) { Value::String(s) => s.clone(), other => panic!("{key}: {other:?}"), } } fn cases() -> Vec { FIXTURE.lines().filter(|l| !l.trim().is_empty()).map(|l| parse(l).expect("fixture json")).collect() } fn reason(answer: &str) -> String { text(&parse(answer).expect("answer json"), "reason") } #[test] fn pseudo_harmonic_map() { let (a, b) = (0.4, 1.2); assert!((pseudo_harmonisch(a, b, a) - 1.0).abs() < 1e-12, "x = A maps to A"); assert!(pseudo_harmonisch(a, b, b).abs() < 1e-12, "x = B maps to B"); let mut last = 1.0; for k in 1..20 { let x = a + (b - a) * k as f64 / 20.0; let f = pseudo_harmonisch(a, b, x); assert!(f < last && f > 0.0, "strictly falling inside (A, B)"); last = f; } // Ganzfried & Sandholm: f(x) = (B - x)(1 + A) / ((B - A)(1 + x)). let x = 0.7; let want = (b - x) * (1.0 + a) / ((b - a) * (1.0 + x)); assert!((pseudo_harmonisch(a, b, x) - want).abs() < 1e-12); // Outside the interval: clamped. assert_eq!(pseudo_harmonisch(a, b, 0.0), 1.0); assert_eq!(pseudo_harmonisch(a, b, 9.0), 0.0); } /// A converged Teilspiel: exact exploitability tiny, and falling over the iterations. #[test] fn teilspiel_converges() { let env = umgebung(); let z = Zelle { art: Art::VsRaise, villain: Place::Button, hero: Place::BigBlind, opener: Place::Early, n: 0, tiefe: 100, groesse: 2.5 }; let e = loese_zelle(&env, &z, ITERATIONEN).expect("solvable"); assert!(e.expl_micro_bb < 100, "exploitability {} micro-bb", e.expl_micro_bb); assert!(e.expl_micro_bb <= e.expl_fuenftel_micro_bb, "{} > {}", e.expl_micro_bb, e.expl_fuenftel_micro_bb); // AA never folds, 72o folds against the button open. let row = |name: &str| e.zeilen[class_parse(name).unwrap()]; assert!(row("AA")[0] + row("AA")[1] >= 990); assert!(row("72o")[0] + row("72o")[1] <= 100); } /// The frozen Teilspiele: every planned cell is there, converged, and the big blind defends less /// against a bigger open. #[test] fn frozen_teilspiele_cover_the_plan() { use rechner::preflop::generated_teilspiel::TEILSPIEL; let p = plan(); assert_eq!(TEILSPIEL.len(), p.len(), "regenerate: chartgen teilspiel"); for c in TEILSPIEL.iter() { assert!(c.expl_micro_bb <= 2_000, "{:?} {:?} {} bb: {} micro-bb", c.art, c.hero, c.tiefe, c.expl_micro_bb); } let z = Zelle { art: Art::VsRaise, villain: Place::Button, hero: Place::BigBlind, opener: Place::Early, n: 0, tiefe: 0, groesse: 0.0 }; let defend = |open: f64| { let a = mische(&z, 100.0, open).expect("cell"); let (mut d, mut w) = (0.0, 0.0); for c in 0..CLASS_COUNT { let n = class_combos(c).len() as f64; d += n * (a.zeilen[c].call + a.zeilen[c].raise); w += n; } d / w }; let (d2, d25, d4, d6) = (defend(2.0), defend(2.5), defend(4.0), defend(6.0)); assert!(d2 > d25 && d25 > d4 && d4 > d6, "{d2} {d25} {d4} {d6}"); // Live environment (no antes): the big blind defends well under the ante tables' ~57 %, and // never collapses (2.5-bb button open, 100 bb). assert!((0.25..0.57).contains(&d25), "{d25}"); } /// The cell families of the real spots follow their line class. #[test] fn families_of_real_spots() { let (mut geprueft, mut abweichend) = (0, Vec::new()); for c in cases() { let klasse = text(&c, "klasse"); let s = check(decode(field(&c, "spot")).expect("decode")).expect("valid"); let f = familie(&s).map(|(z, _)| z.art); let want = if klasse.starts_with("vs open + caller") || klasse.starts_with("vs open HU-linie") { Some(Art::VsRaise) } else if klasse.starts_with("opener vs 3-bet") { Some(Art::Vs3Bet) } else if klasse.starts_with("kalt vs 3-bet") { Some(Art::Kalt3Bet) } else if klasse.starts_with("Limp-Pot: BB") || klasse.starts_with("Limp-Pot: iso") { Some(Art::Limp) } else { continue; }; geprueft += 1; if f != want { abweichend.push(format!("hand {} ({klasse}): {f:?}", text(&c, "hand"))); } } // Live histories have gaps (e.g. hand 177599600036: hero raises, the big blind calls, then a // preflop check), where the line classifier and the family read differ; at most 1 in 20. assert!(geprueft >= 40, "{geprueft}"); assert!(abweichend.len() * 20 <= geprueft, "{abweichend:#?}"); } /// Off: answer for answer what the live core said. On: more answers from solutions, all of them /// complete answers. #[test] fn switch_off_is_identical_and_on_covers_more() { let all = cases(); set_voll(false); let mut cfr_off = 0; for c in &all { let got = respond(&render(field(c, "spot"))); assert_eq!(got, text(c, "vorher"), "hand {} changed with the switch off", text(c, "hand")); cfr_off += reason(&got).contains("CFR") as usize; } set_voll(true); let mut cfr_on = 0; for c in &all { let got = respond(&render(field(c, "spot"))); let v = parse(&got).expect("answer json"); assert!(matches!(text(&v, "action").as_str(), "FOLD" | "CHECK" | "CALL" | "RAISE" | "ALL_IN"), "{got}"); cfr_on += reason(&got).contains("CFR") as usize; } set_voll(false); assert!(cfr_on > cfr_off, "{cfr_on} <= {cfr_off}"); // The fixture is stratified (two requests per class, the rule classes included), so its share // is not the live coverage (`preflop_abdeckung` over all 2776 real spots: 63.5 % -> 94.5 % with // every part). The default leaves the limp and vs-3-bet Teilspiele out (`voll::VORGABE_TEILE`, // measured losers vs nemesis-1): two thirds of the fixture, all parts 70 %. assert!(cfr_on * 3 >= all.len() * 2, "on: {cfr_on} / {}", all.len()); }