From 4f6e0ab0fd7b4ed47e00fda7437e5915d4c3c0ce Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 17 Nov 2026 13:32:53 +0100 Subject: [PATCH] ZEIGT_KIPP=richtung: gezeigte Haende kippen die Aggressiv-Linie nur staerker, die Passiv-Linie nur schwaecher (nie gegen einen Station-Read); =aggr/=passiv zur Diagnose; =1 und aus unveraendert. Leck-Finder: --zusatz und --gezeigt Co-Authored-By: Claude Opus 5.5 --- lesen/leckfinder.py | 20 +++++++-- .../zeigt2/gezeigt-fremder-nl2.json | 1 + src/engine/range_filter.rs | 16 +++++-- src/exploit/range_model.rs | 45 ++++++++++++++++--- src/exploit/range_spec.rs | 11 ++++- tests/shown_tilt.rs | 30 ++++++++++--- 6 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 messung/gedaechtnis/zeigt2/gezeigt-fremder-nl2.json diff --git a/lesen/leckfinder.py b/lesen/leckfinder.py index 0ebf86f1..0c719c2c 100644 --- a/lesen/leckfinder.py +++ b/lesen/leckfinder.py @@ -5,6 +5,7 @@ Engine) wird der REALISIERTE Ausgang gegen eine feste Alternative aufsummiert. B python -I lesen/leckfinder.py spots [--stufen 25] [--teil i/k] [--spieler spieler.pkl] python -I lesen/leckfinder.py entscheiden [--prozesse 10] (arm: live | alt | stufe:) + [--zusatz "K=V;K=V"] [--gezeigt gezeigt.json] python -I lesen/leckfinder.py jams [--stufen 25] [--teil i/k] python -I lesen/leckfinder.py jams_mischen ... python -I lesen/leckfinder.py bewerten ... @@ -311,9 +312,16 @@ def lauf_spots(roh, aus, stufen=(25,), teil=(0, 1), spieler=None, melden=print): # --- Engine fragen --- -def lauf_entscheiden(spots, aus, rechner, umgebung, prozesse=10, block=2000): - """Fragt `rechner` je Spot (Idle-Priorität, `prozesse` gleichzeitig); schreibt je Zeile {id, antwort}.""" +def lauf_entscheiden(spots, aus, rechner, umgebung, prozesse=10, block=2000, gezeigt=None): + """Fragt `rechner` je Spot (Idle-Priorität, `prozesse` gleichzeitig); schreibt je Zeile {id, antwort}. + `gezeigt`: ein `profile.shown`-Feld (wie `lesen/uebergabe.py` es einem Fremden schickt: die Linien-Population), + das jedes vorhandene Gegnerprofil bekommt - so greift ZEIGT_KIPP auch hier.""" zeilen = [json.loads(z) for z in open(spots, encoding="utf-8")] + if gezeigt: + for z in zeilen: + for v in z["req"].get("villains") or (): + if isinstance(v.get("profile"), dict): + v["profile"].setdefault("shown", gezeigt) stuecke = [zeilen[i:i + block] for i in range(0, len(zeilen), block)] flags = 0x40 if sys.platform == "win32" else 0 # IDLE_PRIORITY_CLASS laufend, fertig = [], {} @@ -971,7 +979,13 @@ if __name__ == "__main__": umg.update({k: v for k, v in schalter.items() if k not in weg}) if a[4].startswith("stufe:"): # Kandidat POOL_STUFE (PLAN §8.5) umg["POOL_STUFE"] = a[4][len("stufe:"):] - lauf_entscheiden(a[1], a[2], a[3], umg, int(_arg(a, "prozesse", "10"))) + for z in _arg(a, "zusatz", "").split(";"): + if "=" in z: + k, v = z.split("=", 1) + umg[k] = v + gz = _arg(a, "gezeigt", None) + gz = json.load(open(gz, encoding="utf-8")) if gz else None + lauf_entscheiden(a[1], a[2], a[3], umg, int(_arg(a, "prozesse", "10")), gezeigt=gz) elif a[0] == "jams": teil = tuple(int(x) for x in _arg(a, "teil", "0/1").split("/")) stufen = tuple(int(x) for x in _arg(a, "stufen", "25").split(",")) diff --git a/messung/gedaechtnis/zeigt2/gezeigt-fremder-nl2.json b/messung/gedaechtnis/zeigt2/gezeigt-fremder-nl2.json new file mode 100644 index 00000000..0761f7ae --- /dev/null +++ b/messung/gedaechtnis/zeigt2/gezeigt-fremder-nl2.json @@ -0,0 +1 @@ +{"n": 0, "klassen": [0.0776, 0.1687, 0.2418, 0.2947, 0.2171], "linien": {"river-aggr": {"n": 0, "klassen": [0.0456, 0.178, 0.2359, 0.3116, 0.2289]}, "river-passiv": {"n": 0, "klassen": [0.0404, 0.1129, 0.2739, 0.3263, 0.2465]}}} \ No newline at end of file diff --git a/src/engine/range_filter.rs b/src/engine/range_filter.rs index efec23cf..a3d25106 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::{chen_class, Continuation, RangeSpec, CLASSES}; +use crate::exploit::range_spec::{chen_class, ClassTilt, Continuation, RangeSpec, CLASSES}; use crate::preflop::hand_percentile::percentile; use crate::read::draw::Draw; use crate::read::glance::glance; @@ -204,8 +204,10 @@ 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]> { +/// for Omaha, an empty range, or a target without mass. With a direction (`ClassTilt::dir`) a target +/// whose mean class moves the range the other way leaves it untilted (`None`). +fn class_keep(tilt: &ClassTilt, kept: &Kept) -> Option<[f64; CLASSES]> { + let target = &tilt.target; if kept.rules.hole_cards != 2 { return None; } @@ -220,6 +222,14 @@ fn class_keep(target: &[f64; CLASSES], kept: &Kept) -> Option<[f64; CLASSES]> { if n <= 0.0 || t <= 0.0 { return None; } + if tilt.dir != 0 { + let mean_r: f64 = (0..CLASSES).map(|c| c as f64 * r[c] / n).sum(); + let mean_t: f64 = (0..CLASSES).filter(|&c| target[c].is_finite() && target[c] > 0.0).map(|c| c as f64 * target[c] / t).sum(); + // +1 = only stronger: the target's mean class must lie below the range's (0 = premium) + if (mean_t - mean_r) * tilt.dir as f64 >= 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 { diff --git a/src/exploit/range_model.rs b/src/exploit/range_model.rs index 03e220e6..c60f444a 100644 --- a/src/exploit/range_model.rs +++ b/src/exploit/range_model.rs @@ -74,19 +74,42 @@ pub fn range_spec(spot: &Spot, villain: &Villain) -> RangeSpec { } } -/// Messschalter (einmal gelesen) `ZEIGT_KIPP=1`: thin the villain's river range per preflop class toward +/// Messschalter (einmal gelesen) `ZEIGT_KIPP`: 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 { +/// `1` both lines either way; `richtung` the aggressive line only stronger, the passive line only +/// weaker (shown hands never argue a checking/calling range stronger = never against a station read); +/// `aggr` / `passiv` one line only (diagnosis). +#[derive(Clone, Copy, PartialEq)] +enum TiltMode { + Off, + Both, + Direction, + AggrOnly, + PassiveOnly, +} + +fn tilt_mode() -> TiltMode { use std::sync::OnceLock; - static ON: OnceLock = OnceLock::new(); - *ON.get_or_init(|| std::env::var("ZEIGT_KIPP").as_deref() == Ok("1")) + static MODE: OnceLock = OnceLock::new(); + *MODE.get_or_init(|| match std::env::var("ZEIGT_KIPP").as_deref() { + Ok("1") => TiltMode::Both, + Ok("richtung") => TiltMode::Direction, + Ok("aggr") => TiltMode::AggrOnly, + Ok("passiv") => TiltMode::PassiveOnly, + _ => TiltMode::Off, + }) +} + +pub fn shown_tilt_on() -> bool { + tilt_mode() != TiltMode::Off } /// 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]> { +fn shown_tilt(spot: &Spot, villain: &Villain) -> Option { use crate::game::SeenAction as A; - if !shown_tilt_on() || spot.street != crate::game::Street::River { + let mode = tilt_mode(); + if mode == TiltMode::Off || spot.street != crate::game::Street::River { return None; } let shown = villain.profile.as_ref()?.shown_river?; @@ -96,5 +119,13 @@ fn shown_tilt(spot: &Spot, villain: &Villain) -> Option<[f64; super::range_spec: acted = true; aggr |= matches!(r.action, A::Bet | A::Raise | A::AllIn); } - acted.then(|| shown[if aggr { 0 } else { 1 }]) + if !acted || (mode == TiltMode::AggrOnly && !aggr) || (mode == TiltMode::PassiveOnly && aggr) { + return None; + } + let dir = match mode { + TiltMode::Direction if aggr => 1, + TiltMode::Direction => -1, + _ => 0, + }; + Some(super::range_spec::ClassTilt { target: shown[if aggr { 0 } else { 1 }], dir }) } diff --git a/src/exploit/range_spec.rs b/src/exploit/range_spec.rs index 894f1d53..d8c87391 100644 --- a/src/exploit/range_spec.rs +++ b/src/exploit/range_spec.rs @@ -13,7 +13,16 @@ pub struct RangeSpec { /// 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]>, + pub class_target: Option, +} + +/// The shown-hand tilt of a range (`RangeSpec::class_target`): the class target, and the only direction +/// the tilt may move the range (`ZEIGT_KIPP=richtung`): `+1` only stronger (mean preflop class falls), +/// `-1` only weaker, `0` either way (`ZEIGT_KIPP=1`). A tilt the wrong way is not applied. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct ClassTilt { + pub target: [f64; CLASSES], + pub dir: i8, } /// Preflop classes of `chen_class` (= `lesen/zeigt_eval.py` KLASSEN). diff --git a/tests/shown_tilt.rs b/tests/shown_tilt.rs index 325dbfb7..d83f8d86 100644 --- a/tests/shown_tilt.rs +++ b/tests/shown_tilt.rs @@ -7,12 +7,12 @@ 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::exploit::range_spec::{chen_class, ClassTilt, Continuation, RangeSpec, CLASSES}; use rechner::read::made::Made; use rechner::variant::{rules, Variant}; use spot_fixture::cards; -fn spec(target: Option<[f64; CLASSES]>) -> RangeSpec { +fn spec(target: Option<[f64; CLASSES]>, dir: i8) -> RangeSpec { RangeSpec { lo: 0.0, hi: 0.7, @@ -24,14 +24,15 @@ fn spec(target: Option<[f64; CLASSES]>) -> RangeSpec { bluff_share: 0.2, continue_share: None, top_share: None, + min_strength: None, }], - class_target: target, + class_target: target.map(|target| ClassTilt { target, dir }), } } -fn shares(target: Option<[f64; CLASSES]>) -> ([f64; CLASSES], usize) { +fn shares_dir(target: Option<[f64; CLASSES]>, dir: i8) -> ([f64; CLASSES], usize) { let board = cards("Kd 8s 4c 2h Jc"); - let f = range_filter(&spec(target), rules(Variant::Nlhe), Variant::Nlhe, &board); + let f = range_filter(&spec(target, dir), rules(Variant::Nlhe), Variant::Nlhe, &board); let pool = deck::without(&board); let mut n = [0.0; CLASSES]; let mut all = 0; @@ -47,6 +48,10 @@ fn shares(target: Option<[f64; CLASSES]>) -> ([f64; CLASSES], usize) { (n.map(|x| x / all as f64), all) } +fn shares(target: Option<[f64; CLASSES]>) -> ([f64; CLASSES], usize) { + shares_dir(target, 0) +} + #[test] fn the_kept_range_takes_the_target_class_shares() { let (plain, n_plain) = shares(None); @@ -60,3 +65,18 @@ fn the_kept_range_takes_the_target_class_shares() { let (_, n_same) = shares(Some(plain)); assert!(n_same as f64 > 0.97 * n_plain as f64, "{n_same} of {n_plain}"); } + +#[test] +fn a_directed_tilt_only_moves_the_range_its_way() { + let (plain, n_plain) = shares(None); + let weaker = [0.01, 0.03, 0.08, 0.28, 0.60]; + let stronger = [0.15, 0.20, 0.25, 0.25, 0.15]; + // -1 (passive line: only weaker): a weaker target tilts, a stronger one leaves the range as it is + let (w, n_w) = shares_dir(Some(weaker), -1); + assert!(n_w < n_plain && w[4] > plain[4] + 0.05, "{w:?} vs {plain:?}"); + assert_eq!(shares_dir(Some(stronger), -1), (plain, n_plain)); + // +1 (aggressive line: only stronger): the other way round + let (s, n_s) = shares_dir(Some(stronger), 1); + assert!(n_s < n_plain && s[0] > plain[0] + 0.05, "{s:?} vs {plain:?}"); + assert_eq!(shares_dir(Some(weaker), 1), (plain, n_plain)); +}