From ddf0ba02a98d074d81cc30b32562ec59fd5c9e2a Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 17 Nov 2026 13:28:50 +0100 Subject: [PATCH] ZEIGT_KIPP (Plan D3) aus pool-nl2-echt 3cd9fc9c uebernommen: gezeigte River-Haende kippen die River-Range je Preflop-Klasse; aus = bitgleich Co-Authored-By: Claude Opus 5.5 --- entscheiden/decide.py | 2 +- lesen/uebergabe.py | 7 +++- src/engine/range_filter.rs | 47 ++++++++++++++++++++-- src/exploit/mark.rs | 2 + src/exploit/profile.rs | 6 +++ src/exploit/range_model.rs | 26 +++++++++++- src/exploit/range_spec.rs | 73 +++++++++++++++++++++++++++++++++- src/exploit/sample.rs | 2 + src/sim/memory.rs | 9 +++++ src/sim/welt_memory.rs | 76 ++++++++++++++++++++++++++++++++++++ src/wire/decode_villain.rs | 38 ++++++++++++++++++ tests/bluff_range.rs | 2 +- tests/called_range_share.rs | 2 +- tests/engine_range_filter.rs | 4 +- tests/reraise_narrowing.rs | 2 +- tests/shown_tilt.rs | 62 +++++++++++++++++++++++++++++ tests/uebergabe_spec.py | 3 +- tests/wire_decode.rs | 12 ++++++ 18 files changed, 361 insertions(+), 14 deletions(-) create mode 100644 tests/shown_tilt.rs diff --git a/entscheiden/decide.py b/entscheiden/decide.py index 69ba86e3..33712ec4 100644 --- a/entscheiden/decide.py +++ b/entscheiden/decide.py @@ -45,7 +45,7 @@ BEKANNTE_SCHALTER = ("MDF_UNREAD", "RAISE_DRAWS", "RAISE_PRIOR", "TURN_SPIEL", " "REST_STACK", "FORTSETZUNG", "POOL_PRIOR", "POSTERIOR", "GEGNER_LINIEN", "PREFLOP_VOLL", "PREFLOP_OHNE_ANTE", "PREFLOP_MIKRO", "PREFLOP_VOLL_TEILE", "WERT_BRETT", "FLUSS_WERT", "PAAR_RAISE", "BRETT_PAAR", "CALLED_JAM", "ALLIN_TIEFE", "CBET_LUFT", "POOL_STUFE", - "TISCHWAHL", "TISCHWAHL_AB", "SITZWAHL", "GEGNER_GEDAECHTNIS") + "TISCHWAHL", "TISCHWAHL_AB", "SITZWAHL", "GEGNER_GEDAECHTNIS", "ZEIGT_KIPP") # Schalter des LAEUFERS (betrieb/runner.py liest sie aus seiner eigenen Umgebung, nicht der Kern): aus der # Datei auch in os.environ, sonst schaltete ein Eintrag hier nichts. Eine ausdrueckliche Umgebung geht vor. # GEGNER_GEDAECHTNIS (die Uebergabe hier in `_gedaechtnis`) liest os.environ: ohne diesen Eintrag diff --git a/lesen/uebergabe.py b/lesen/uebergabe.py index b91eec0c..d7b7dc6c 100644 --- a/lesen/uebergabe.py +++ b/lesen/uebergabe.py @@ -234,7 +234,9 @@ def _klassen_feld(beob, pop_linien, kappa): return [round(x / s, 4) for x in q] linien = {} - for lin in sorted({l for _, l in beob}): + # Die River-Linien immer (hierarchisch, ZEIGT_KIPP im Kern): ohne eigene gezeigte Haende ist es die + # Linien-Population, mit ihnen zieht der Spieler nach seiner Stichprobe (kappa), keine harte Schwelle. + for lin in sorted({l for _, l in beob} | (set(FLUSS_LINIEN) if pop_linien else set())): zl = pop_linien.get(lin) or [0] * k n = sum(zl) basis = [(zl[c] + LAMBDA_LINIE * pop[c]) / (n + LAMBDA_LINIE) for c in range(k)] @@ -242,6 +244,7 @@ def _klassen_feld(beob, pop_linien, kappa): return {"n": n_sp, "klassen": kippen(pop), "linien": linien} +FLUSS_LINIEN = ("river-aggr", "river-passiv") D3_KAPPA = 50.0 # Prior-Staerke der Spielerkippung (zeigt_eval --kipp waehlt am Spielgeld 50) @@ -297,7 +300,7 @@ def draht_profil(g): "gedaechtnis": {"v": g["v"], "stufe": g["stufe"], "haende": g["haende"], "tor": g["tor"]}} if tells: out["tells"] = tells - if g["gezeigt"]["n"]: + if g["gezeigt"]["n"] or g["gezeigt"]["linien"]: out["shown"] = g["gezeigt"] return out diff --git a/src/engine/range_filter.rs b/src/engine/range_filter.rs index 57030ecc..efec23cf 100644 --- a/src/engine/range_filter.rs +++ b/src/engine/range_filter.rs @@ -2,7 +2,7 @@ use crate::card::{deck, Card}; use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; -use crate::exploit::range_spec::{Continuation, RangeSpec}; +use crate::exploit::range_spec::{chen_class, Continuation, RangeSpec, CLASSES}; use crate::preflop::hand_percentile::percentile; use crate::read::draw::Draw; use crate::read::glance::glance; @@ -198,11 +198,45 @@ thread_local! { static FILTERS: RefCell>> = RefCell::new(HashMap::new()); } +/// Salt of the class-thinning ticket, apart from the bluff and tie-break tickets. +const CLASS_SALT: usize = 0x6_0000; + +/// Keep chance per class so the kept range has the class shares of `target`: the I-projection of the +/// untilted range onto that class marginal is a per-class factor target_c / r_c (r = class shares of the +/// untilted range), scaled so the largest factor keeps all. A class the range lacks stays out; `None` +/// for Omaha, an empty range, or a target without mass. +fn class_keep(target: &[f64; CLASSES], kept: &Kept) -> Option<[f64; CLASSES]> { + if kept.rules.hole_cards != 2 { + return None; + } + let mut r = [0.0; CLASSES]; + for h in population(&kept.rules, &kept.board) { + if kept.judge_untilted(&h) { + r[chen_class(&h)] += 1.0; + } + } + let n: f64 = r.iter().sum(); + let t: f64 = target.iter().filter(|x| x.is_finite() && **x > 0.0).sum(); + if n <= 0.0 || t <= 0.0 { + return None; + } + let mut f = [0.0; CLASSES]; + for c in 0..CLASSES { + if r[c] > 0.0 && target[c].is_finite() && target[c] > 0.0 { + f[c] = (target[c] / t) / (r[c] / n); + } + } + let top = f.iter().cloned().fold(0.0, f64::max); + (top > 0.0).then(|| f.map(|x| x / top)) +} + /// One built range: the (possibly relaxed) spec, its ticket thresholds and strength cuts, and the /// verdict per ordered two-card hand once asked (0 = not yet, 1 = out, 2 = in). struct Kept { spec: RangeSpec, qs: Vec<(f64, Option)>, + /// Keep chance per preflop class (`RangeSpec::class_target`), `None` = no tilt. + keep: Option<[f64; CLASSES]>, rules: Rules, variant: Variant, board: Vec, @@ -214,16 +248,23 @@ impl Kept { let board = board.to_vec(); let (first, starved) = acceptances(spec, &rules, variant, &board); let (spec, qs) = if starved { - let relaxed = RangeSpec { lo: 0.0, hi: spec.hi.max(RELAXED_HI), continues: spec.continues.clone() }; + let relaxed = RangeSpec { lo: 0.0, hi: spec.hi.max(RELAXED_HI), continues: spec.continues.clone(), class_target: spec.class_target }; let (qs, _) = acceptances(&relaxed, &rules, variant, &board); (relaxed, qs) } else { (spec.clone(), first) }; - Kept { spec, qs, rules, variant, board, verdict: RefCell::new(vec![0; 52 * 52]) } + let mut kept = Kept { spec, qs, rules, variant, board, keep: None, verdict: RefCell::new(vec![0; 52 * 52]) }; + kept.keep = kept.spec.class_target.and_then(|t| class_keep(&t, &kept)); + kept } fn judge(&self, hand: &[Card]) -> bool { + self.judge_untilted(hand) + && self.keep.is_none_or(|k| hand.len() != 2 || ticket(hand, CLASS_SALT) < k[chen_class(hand)]) + } + + fn judge_untilted(&self, hand: &[Card]) -> bool { let p = percentile(self.variant, hand); p >= self.spec.lo && p <= self.spec.hi diff --git a/src/exploit/mark.rs b/src/exploit/mark.rs index 42dd292a..69f37e91 100644 --- a/src/exploit/mark.rs +++ b/src/exploit/mark.rs @@ -29,6 +29,7 @@ const WEAK_PLAYER: Profile = Profile { river_bluff_share: None, river_bluff_shown: None, flop_aggression: None, + shown_river: None, fold_to_steal: None, fold_to_raise: None, raise_to_bet: None, @@ -70,6 +71,7 @@ pub fn with_mark(measured: Option, mark: &str) -> Option { river_bluff_share: known.river_bluff_share, river_bluff_shown: known.river_bluff_shown, flop_aggression: known.flop_aggression, + shown_river: known.shown_river, fold_to_steal: known.fold_to_steal, fold_to_raise: known.fold_to_raise, raise_to_bet: known.raise_to_bet, diff --git a/src/exploit/profile.rs b/src/exploit/profile.rs index 84f5e102..c93b2c3c 100644 --- a/src/exploit/profile.rs +++ b/src/exploit/profile.rs @@ -70,6 +70,12 @@ pub struct Profile { pub river_bluff_shown: Option, /// Aggression frequency on the FLOP only (memory handover `reads.flopAggression`). `None` without it. pub flop_aggression: Option, + /// Shown hands on the river (plan D3, `profile.shown.linien` of the memory handover): the + /// preflop-class distribution (`range_spec::chen_class`) of what this player holds when he reaches + /// showdown after betting/raising the river (`[0]`, "river-aggr") or after checking/calling it + /// (`[1]`, "river-passiv"). Hierarchical: the line population is the prior, the player's own shown + /// hands pull it by their sample (`lesen/uebergabe._klassen_feld`). Used by `ZEIGT_KIPP=1` only. + pub shown_river: Option<[[f64; crate::exploit::range_spec::CLASSES]; 2]>, /// How often the player, in a blind, folds to a steal raise (`reads.foldToSteal`). pub fold_to_steal: Option, /// How often the player folds after betting/raising a postflop street and being raised (`reads.foldToRaise`). diff --git a/src/exploit/range_model.rs b/src/exploit/range_model.rs index 46f73eec..03e220e6 100644 --- a/src/exploit/range_model.rs +++ b/src/exploit/range_model.rs @@ -68,9 +68,33 @@ pub fn range_spec(spot: &Spot, villain: &Villain) -> RangeSpec { if spot.history.iter().any(|r| r.seat == villain.seat) { let (raw_lo, raw_hi) = preflop_band(spot, villain); let (lo, hi) = bounded(raw_lo, raw_hi); - RangeSpec { lo, hi, continues: continuations(spot, villain) } + RangeSpec { lo, hi, continues: continuations(spot, villain), class_target: shown_tilt(spot, villain) } } else { RangeSpec::top(top_fraction(spot, villain)) } } +/// Messschalter (einmal gelesen) `ZEIGT_KIPP=1`: thin the villain's river range per preflop class toward +/// what he showed on his river line (`Profile::shown_river`). Off = no tilt, bit-identical. +pub fn shown_tilt_on() -> bool { + use std::sync::OnceLock; + static ON: OnceLock = OnceLock::new(); + *ON.get_or_init(|| std::env::var("ZEIGT_KIPP").as_deref() == Ok("1")) +} + +/// The class target of the villain's range (`RangeSpec::class_target`): on the river, once he acted +/// there, the shown-hand distribution of his line (aggressive = he bet/raised the river, else passive). +fn shown_tilt(spot: &Spot, villain: &Villain) -> Option<[f64; super::range_spec::CLASSES]> { + use crate::game::SeenAction as A; + if !shown_tilt_on() || spot.street != crate::game::Street::River { + return None; + } + let shown = villain.profile.as_ref()?.shown_river?; + let mut acted = false; + let mut aggr = false; + for r in spot.history.iter().filter(|r| r.seat == villain.seat && r.street == crate::game::Street::River) { + acted = true; + aggr |= matches!(r.action, A::Bet | A::Raise | A::AllIn); + } + acted.then(|| shown[if aggr { 0 } else { 1 }]) +} diff --git a/src/exploit/range_spec.rs b/src/exploit/range_spec.rs index 19c21495..894f1d53 100644 --- a/src/exploit/range_spec.rs +++ b/src/exploit/range_spec.rs @@ -10,6 +10,64 @@ pub struct RangeSpec { pub lo: f64, pub hi: f64, pub continues: Vec, + /// Shown-hand tilt (`ZEIGT_KIPP`, plan D3): the preflop-class distribution (`chen_class`, 0 premium + /// .. 4 weak) the hands of this range have in what the villain showed on this line. The range is + /// thinned per class toward it (`engine::range_filter`); `None` = no tilt (as before). + pub class_target: Option<[f64; CLASSES]>, +} + +/// Preflop classes of `chen_class` (= `lesen/zeigt_eval.py` KLASSEN). +pub const CLASSES: usize = 5; + +/// Chen number of a two-card hand (= `lesen/zeigt_eval.chen`). +pub fn chen(hand: &[crate::card::Card]) -> f64 { + let (mut a, mut b) = (hand[0], hand[1]); + if b.rank.value() > a.rank.value() { + std::mem::swap(&mut a, &mut b); + } + let (ra, rb) = (a.rank.value() as i32, b.rank.value() as i32); + let points = |r: i32| match r { + 14 => 10.0, + 13 => 8.0, + 12 => 7.0, + 11 => 6.0, + _ => r as f64 / 2.0, + }; + let mut p = points(ra); + if ra == rb { + return (2.0 * p).max(5.0); + } + if a.suit == b.suit { + p += 2.0; + } + let gap = ra - rb - 1; + p -= match gap { + 0 => 0.0, + 1 => 1.0, + 2 => 2.0, + 3 => 4.0, + _ => 5.0, + }; + if gap <= 1 && ra < 12 { + p += 1.0; + } + p +} + +/// 0 premium, 1 strong, 2 medium, 3 speculative, 4 weak (= `lesen/zeigt_eval.klasse`). +pub fn chen_class(hand: &[crate::card::Card]) -> usize { + let c = chen(hand); + if c >= 12.0 { + 0 + } else if c >= 9.0 { + 1 + } else if c >= 7.0 { + 2 + } else if c >= 5.0 { + 3 + } else { + 4 + } } /// "Villain bet or raised when the board had `board_len` cards": only hands at least @@ -42,6 +100,19 @@ pub struct Continuation { impl RangeSpec { /// The best `top` fraction of starting hands, no postflop filter. pub fn top(top: f64) -> RangeSpec { - RangeSpec { lo: 0.0, hi: top, continues: Vec::new() } + RangeSpec { lo: 0.0, hi: top, continues: Vec::new(), class_target: None } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::card::Card; + + #[test] + fn chen_classes_match_zeigt_eval() { + let k = |s: &str| chen_class(&Card::parse_list(s).unwrap()); + // lesen/zeigt_eval.klasse: AA 0, AKs 0, 72o 4, T9s 2, KJo 2 + assert_eq!([k("Ah Ad"), k("Ah Kh"), k("7h 2d"), k("Th 9h"), k("Kd Jc")], [0, 0, 4, 2, 2]); } } diff --git a/src/exploit/sample.rs b/src/exploit/sample.rs index 7bc47d89..dad94440 100644 --- a/src/exploit/sample.rs +++ b/src/exploit/sample.rs @@ -40,6 +40,7 @@ pub const PRIOR: Profile = Profile { river_bluff_share: None, river_bluff_shown: None, flop_aggression: None, + shown_river: None, fold_to_steal: None, fold_to_raise: None, raise_to_bet: None, @@ -97,6 +98,7 @@ pub fn shrink(profile: &Profile, hands: f64) -> Profile { river_bluff_share: profile.river_bluff_share, river_bluff_shown: profile.river_bluff_shown, flop_aggression: profile.flop_aggression, + shown_river: profile.shown_river, fold_to_steal: profile.fold_to_steal, fold_to_raise: profile.fold_to_raise, raise_to_bet: profile.raise_to_bet, diff --git a/src/sim/memory.rs b/src/sim/memory.rs index 2703ea2b..18c037da 100644 --- a/src/sim/memory.rs +++ b/src/sim/memory.rs @@ -407,6 +407,7 @@ impl SessionMemory { check_raise, river_bluff_share: river_bluff.map(|(s, _)| s), river_bluff_shown: river_bluff.map(|(_, n)| n as f64), + shown_river: self.shown_river(), flop_aggression: None, fold_to_steal: None, fold_to_raise: None, @@ -491,6 +492,13 @@ pub fn size_gain(corr: Option, n: u32) -> Option { impl SessionMemory { /// The raw rates counted so far (no warmup, no shrinking): the "truth" a long pre-session measures, /// from which the HUD mode draws its noisy PokerIntel numbers (`sim::hud`). + /// The hierarchical shown-hand read for `ZEIGT_KIPP` (NL2 line prior, the opponent's own reveals); + /// `None` with the switch off (the profile stays bit-identical). + fn shown_river(&self) -> Option<[[f64; crate::exploit::range_spec::CLASSES]; 2]> { + crate::exploit::range_model::shown_tilt_on() + .then(|| super::welt_memory::shown_river_read(&super::welt_memory::NL2_LINES, &self.world.shown_classes())) + } + pub fn raw_profile(&self) -> Profile { let ratio = |num: u32, den: u32| (den > 0).then(|| num as f64 / den as f64); Profile { @@ -543,6 +551,7 @@ impl SessionMemory { street_fold_to_bet, river_bluff_share: river_bluff.map(|(s, _)| s), river_bluff_shown: river_bluff.map(|(_, n)| n as f64), + shown_river: self.shown_river(), // The counted line reads (`RERAISE_TIEFE`/`RERAISE_BLUFF`), as `read` gives them. raise_to_bet: counted.then(|| (self.c.raised_vs_bet as f64 + 10.0 * crate::exploit::pool_stufe::rtb_anchor_sim()) / ((self.c.folded_to_bet + self.c.passive_call + self.c.raised_vs_bet) as f64 + 10.0)), reraise_to_raise: counted.then(|| (self.c.reraise_made as f64 + 10.0 * crate::exploit::pool_stufe::rtb_anchor_sim()) / (self.c.reraise_seen as f64 + 10.0)), diff --git a/src/sim/welt_memory.rs b/src/sim/welt_memory.rs index 28f79204..ef42b8dc 100644 --- a/src/sim/welt_memory.rs +++ b/src/sim/welt_memory.rs @@ -334,6 +334,59 @@ pub struct WorldMemory { /// River bets/raises of revealed hands, and how many of them were air (`profile::AIR_STRENGTH`). river_bets_shown: u32, river_air_shown: u32, + /// Preflop classes (`range_spec::chen_class`) of the revealed hands, all lines (plan D3). + shown_class: [u32; CLASSES], +} + +use crate::exploit::range_spec::{chen_class, CLASSES}; + +/// Shown-hand classes of the real NL0.01-0.02 pool per line (`lesen/uebergabe.Quelle.linien_population`, +/// 16.11., aggregate counts only): the line prior of the hierarchical shown-hand read. Order: the +/// river lines first ("river-aggr", "river-passiv"), then every other line, which only feed the pooled +/// class distribution. +pub const NL2_LINES: [[u32; CLASSES]; 9] = [ + [5, 10, 34, 31, 13], // river-aggr + [14, 41, 69, 82, 52], // river-passiv + [13, 17, 13, 9, 4], // preflop-aggr + [7, 10, 3, 12, 8], // turn-aggr + [3, 10, 8, 8, 3], // flop-aggr + [0, 1, 2, 1, 6], // ohne + [0, 0, 1, 1, 0], // preflop-passiv + [0, 0, 1, 1, 0], // turn-passiv + [0, 1, 0, 0, 0], // flop-passiv +]; +/// Pseudo-count of the pooled distribution in a line's prior (= `lesen/zeigt_eval.LAMBDA_KONTEXT`). +pub const SHOWN_LAMBDA: f64 = 5.0; +/// Prior strength of the player's own shown hands (= `lesen/uebergabe.D3_KAPPA`). +pub const SHOWN_KAPPA: f64 = 50.0; + +/// The hierarchical shown-hand read on the two river lines (= `lesen/uebergabe._klassen_feld`): the +/// line distribution, shrunk toward the pooled one by `SHOWN_LAMBDA`, tilted by the player's own shown +/// classes `own` (all lines), which pull with weight n / (n + `SHOWN_KAPPA`). No shown hands = the line +/// prior itself. -> [river-aggr, river-passiv]. +pub fn shown_river_read(lines: &[[u32; CLASSES]], own: &[u32; CLASSES]) -> [[f64; CLASSES]; 2] { + let mut all = [0.0; CLASSES]; + for l in lines { + for c in 0..CLASSES { + all[c] += l[c] as f64; + } + } + let n_all: f64 = all.iter().sum(); + let pop: Vec = (0..CLASSES).map(|c| (all[c] + 1.0) / (n_all + CLASSES as f64)).collect(); + let n_own: f64 = own.iter().map(|x| *x as f64).sum(); + let mut out = [[0.0; CLASSES]; 2]; + for (i, o) in out.iter_mut().enumerate() { + let zl = lines.get(i).copied().unwrap_or([0; CLASSES]); + let n: f64 = zl.iter().map(|x| *x as f64).sum(); + let mut q = [0.0; CLASSES]; + for c in 0..CLASSES { + let base = (zl[c] as f64 + SHOWN_LAMBDA * pop[c]) / (n + SHOWN_LAMBDA); + q[c] = if n_own > 0.0 { base * ((own[c] as f64 + SHOWN_KAPPA * pop[c]) / (n_own + SHOWN_KAPPA)) / pop[c] } else { base }; + } + let s: f64 = q.iter().sum(); + *o = q.map(|x| x / s); + } + out } fn street_ix(street: Street) -> Option { @@ -422,6 +475,7 @@ impl WorldMemory { } } self.observe_showdown(rv.hole, &rv.board, aggressive); + self.shown_class[chen_class(&rv.hole)] += 1; } } @@ -463,6 +517,14 @@ impl WorldMemory { self.revealed_hands += other.revealed_hands; self.river_bets_shown += other.river_bets_shown; self.river_air_shown += other.river_air_shown; + for c in 0..CLASSES { + self.shown_class[c] += other.shown_class[c]; + } + } + + /// Preflop classes of all revealed hands (plan D3). + pub fn shown_classes(&self) -> [u32; CLASSES] { + self.shown_class } // ---- queries ---- @@ -571,6 +633,20 @@ impl WorldMemory { mod tests { use super::*; + #[test] + fn shown_river_read_is_the_handover_formula() { + // lesen/uebergabe._klassen_feld on the same counts, ten shown premium hands + let mut own = [0; CLASSES]; + own[0] = 10; + let q = shown_river_read(&NL2_LINES, &own)[0]; + for (a, b) in q.iter().zip([0.1631, 0.0987, 0.3194, 0.2935, 0.1254]) { + assert!((a - b).abs() < 1e-4, "{q:?}"); + } + // nothing shown: the line prior, a distribution + let p = shown_river_read(&NL2_LINES, &[0; CLASSES]); + assert!((p[1].iter().sum::() - 1.0).abs() < 1e-12 && p[0][2] > p[0][0]); + } + fn cards(s: &str) -> Vec { Card::parse_list(s).expect("cards") } diff --git a/src/wire/decode_villain.rs b/src/wire/decode_villain.rs index a681dbf8..18ff3283 100644 --- a/src/wire/decode_villain.rs +++ b/src/wire/decode_villain.rs @@ -7,6 +7,43 @@ use crate::json::field::{at, join, optional, text}; use crate::json::member::{flag_member, number_member, opt_items_member, opt_number_member, u8_member}; use crate::json::Value; +/// `profile.shown` of the memory handover (`lesen/uebergabe.py`, plan D3): the preflop-class +/// distribution of the shown hands per line, already shrunk toward the line population. The two +/// river lines ("river-aggr", "river-passiv"); a missing line takes the player's overall `klassen`. +/// Absent, or no usable distribution: `None` (the profile unchanged). +fn shown_river(object: &Value, path: &str) -> Result, Fault> { + use crate::exploit::range_spec::CLASSES; + let Some(shown) = optional(object, path, "shown")? else { return Ok(None) }; + let at_shown = join(path, "shown"); + let dist = |v: &Value, at: &str| -> Result, Fault> { + Ok(match opt_items_member(v, at, "klassen")? { + Some(items) if items.len() == CLASSES => { + let mut d = [0.0; CLASSES]; + for (i, x) in items.iter().enumerate() { + match x { + Value::Number(n) if n.is_finite() && *n >= 0.0 => d[i] = *n, + _ => return Ok(None), + } + } + (d.iter().sum::() > 0.0).then_some(d) + } + _ => None, + }) + }; + let overall = dist(shown, &at_shown)?; + let at_lines = join(&at_shown, "linien"); + let line = |name: &str| -> Result, Fault> { + let Some(lines) = optional(shown, &at_shown, "linien")? else { return Ok(None) }; + let Some(l) = optional(lines, &at_lines, name)? else { return Ok(None) }; + dist(l, &join(&at_lines, name)) + }; + let (aggr, passiv) = (line("river-aggr")?.or(overall), line("river-passiv")?.or(overall)); + Ok(match (aggr, passiv) { + (Some(a), Some(p)) => Some([a, p]), + _ => None, + }) +} + fn profile(villain: &Value, path: &str) -> Result, Fault> { let Some(object) = optional(villain, path, "profile")? else { return Ok(None); @@ -41,6 +78,7 @@ fn profile(villain: &Value, path: &str) -> Result, Fault> { river_bluff_shown: opt_number_member(object, &at_profile, "riverBluffShown")?, // Only from the memory handover (`reads`, below). flop_aggression: None, + shown_river: shown_river(object, &at_profile)?, fold_to_steal: None, fold_to_raise: None, // Raise frequency facing a postflop bet (`RERAISE_TIEFE` gate): a forced read for measurement diff --git a/tests/bluff_range.rs b/tests/bluff_range.rs index d94dd07c..54622f6f 100644 --- a/tests/bluff_range.rs +++ b/tests/bluff_range.rs @@ -16,7 +16,7 @@ use rechner::variant::{rules, Variant}; use spot_fixture::cards; fn spec(bluff_share: f64) -> RangeSpec { - RangeSpec { + RangeSpec { class_target: None, lo: 0.0, hi: 0.6, continues: vec![Continuation { diff --git a/tests/called_range_share.rs b/tests/called_range_share.rs index c60359dc..edd4dc6c 100644 --- a/tests/called_range_share.rs +++ b/tests/called_range_share.rs @@ -33,7 +33,7 @@ const BOARD: &str = "Kd 8h 3c"; const THIN: f64 = 1.0 / 3.0; fn floor_spec(min_made: Made, continue_share: Option) -> RangeSpec { - RangeSpec { + RangeSpec { class_target: None, lo: 0.0, hi: 1.0, continues: vec![Continuation { diff --git a/tests/engine_range_filter.rs b/tests/engine_range_filter.rs index 58ce00ea..f7c043ce 100644 --- a/tests/engine_range_filter.rs +++ b/tests/engine_range_filter.rs @@ -18,7 +18,7 @@ fn keeps(spec: &RangeSpec, hand: &str) -> bool { #[test] fn keeps_exactly_the_hands_inside_the_percentile_band() { - let spec = RangeSpec { lo: 0.05, hi: 0.30, continues: Vec::new() }; + let spec = RangeSpec { class_target: None, lo: 0.05, hi: 0.30, continues: Vec::new() }; for hand in HANDS { let p = percentile(Variant::Nlhe, &cards(hand)); assert_eq!(keeps(&spec, hand), (0.05..=0.30).contains(&p), "{hand} at {p}"); @@ -34,7 +34,7 @@ fn top_spec_keeps_the_best_hands_only() { #[test] fn the_lower_bound_cuts_off_the_very_best_hands() { - let spec = RangeSpec { lo: 0.2, hi: 1.0, continues: Vec::new() }; + let spec = RangeSpec { class_target: None, lo: 0.2, hi: 1.0, continues: Vec::new() }; assert!(!keeps(&spec, "Ah Ad")); assert!(keeps(&spec, "7d 2c")); } diff --git a/tests/reraise_narrowing.rs b/tests/reraise_narrowing.rs index 58cd0d1e..5f5a8380 100644 --- a/tests/reraise_narrowing.rs +++ b/tests/reraise_narrowing.rs @@ -24,7 +24,7 @@ use spot_fixture::cards; const BOARD: &str = "Kd 8h 3c"; fn spec(top_share: Option, bluff_share: f64) -> RangeSpec { - RangeSpec { + RangeSpec { class_target: None, lo: 0.0, hi: 1.0, continues: vec![Continuation { diff --git a/tests/shown_tilt.rs b/tests/shown_tilt.rs new file mode 100644 index 00000000..325dbfb7 --- /dev/null +++ b/tests/shown_tilt.rs @@ -0,0 +1,62 @@ +//! Spec: shown hands tilt the river range per preflop class (plan D3, `ZEIGT_KIPP`). +//! +//! A `RangeSpec::class_target` thins the range so its preflop-class shares (`chen_class`) move to the +//! target: the I-projection onto that class marginal. Without a target the range is unchanged. + +mod spot_fixture; + +use rechner::card::{deck, Card}; +use rechner::engine::range_filter::range_filter; +use rechner::exploit::range_spec::{chen_class, Continuation, RangeSpec, CLASSES}; +use rechner::read::made::Made; +use rechner::variant::{rules, Variant}; +use spot_fixture::cards; + +fn spec(target: Option<[f64; CLASSES]>) -> RangeSpec { + RangeSpec { + lo: 0.0, + hi: 0.7, + continues: vec![Continuation { + board_len: 5, + min_made: Made::BottomPair, + draws_continue: false, + min_draw: rechner::read::draw::Draw::Gutshot, + bluff_share: 0.2, + continue_share: None, + top_share: None, + }], + class_target: target, + } +} + +fn shares(target: Option<[f64; CLASSES]>) -> ([f64; CLASSES], usize) { + let board = cards("Kd 8s 4c 2h Jc"); + let f = range_filter(&spec(target), rules(Variant::Nlhe), Variant::Nlhe, &board); + let pool = deck::without(&board); + let mut n = [0.0; CLASSES]; + let mut all = 0; + for i in 0..pool.len() { + for j in i + 1..pool.len() { + let h: [Card; 2] = [pool[i], pool[j]]; + if f(&h) { + n[chen_class(&h)] += 1.0; + all += 1; + } + } + } + (n.map(|x| x / all as f64), all) +} + +#[test] +fn the_kept_range_takes_the_target_class_shares() { + let (plain, n_plain) = shares(None); + let target = [0.05, 0.10, 0.35, 0.35, 0.15]; + let (tilted, n_tilted) = shares(Some(target)); + assert!(n_tilted < n_plain && n_tilted > 0, "thinned, not emptied: {n_plain} -> {n_tilted}"); + for c in 0..CLASSES { + assert!((tilted[c] - target[c]).abs() < 0.04, "class {c}: {tilted:?} vs {target:?} (plain {plain:?})"); + } + // the plain range's own shares as target: (almost) nothing is thinned + let (_, n_same) = shares(Some(plain)); + assert!(n_same as f64 > 0.97 * n_plain as f64, "{n_same} of {n_plain}"); +} diff --git a/tests/uebergabe_spec.py b/tests/uebergabe_spec.py index 2c2fcc15..c949b5c6 100644 --- a/tests/uebergabe_spec.py +++ b/tests/uebergabe_spec.py @@ -70,7 +70,8 @@ class Ablage(unittest.TestCase): def test_gezeigte_haende_verengen_je_linie(self): g = uebergabe.fuer_spieler("77", STUFE, self.q)["gezeigt"] self.assertEqual(g["n"], 1) - self.assertEqual(sorted(g["linien"]), ["river-aggr"]) + self.assertEqual(sorted(g["linien"]), ["river-aggr", "river-passiv"], "River-Linien immer (hierarchisch)") + self.assertEqual(g["linien"]["river-passiv"]["n"], 0) self.assertAlmostEqual(sum(g["klassen"]), 1.0, places=3) ohne = uebergabe.fuer_spieler("99", STUFE, self.q)["gezeigt"] self.assertGreater(g["klassen"][0], ohne["klassen"][0], "gezeigte Asse kippen zu Premium") diff --git a/tests/wire_decode.rs b/tests/wire_decode.rs index ab35fdf1..8d4b00c7 100644 --- a/tests/wire_decode.rs +++ b/tests/wire_decode.rs @@ -309,6 +309,18 @@ fn showdown_read_reaches_the_profile() { assert_eq!((q.river_bluff_share, q.river_bluff_shown), (None, None)); } +/// `profile.shown` (memory handover, plan D3): the river lines land on `shown_river`; a missing line +/// takes the player's overall classes; no `shown` = `None`. +#[test] +fn shown_lines_reach_the_profile() { + let shown = r#""villains":[{"seat":1,"stack":50,"folded":false,"profile":{"vpip":0.3,"hands":80, + "shown":{"n":3,"klassen":[0.1,0.2,0.3,0.2,0.2],"linien":{"river-aggr":{"n":2,"klassen":[0.3,0.3,0.2,0.1,0.1]}}}}}]"#; + let p = run(&plus(shown)).unwrap().villains[0].profile.unwrap(); + assert_eq!(p.shown_river, Some([[0.3, 0.3, 0.2, 0.1, 0.1], [0.1, 0.2, 0.3, 0.2, 0.2]])); + let none = r#""villains":[{"seat":1,"stack":50,"folded":false,"profile":{"vpip":0.3,"hands":80}}]"#; + assert_eq!(run(&plus(none)).unwrap().villains[0].profile.unwrap().shown_river, None); +} + #[test] fn street_reads_are_pulled_to_the_pooled_read() { // One river bet seen: the river belief moves only 1/16 of the way off the pooled aggression.