Files
pokerfreak/src/sim/hud.rs
T
mmintelandClaude Opus 5.5 1d15019031 Aufraeumen: Wurzel und Docs ohne Redundanz
- messung_<track>/ (12 Tracks) nach messung/<track>/; messung_engine bleibt (laufende Warteschlange).
  Pfadverweise in Code, Specs und Docs nachgezogen, Zeilen mit fremden Worktrees unveraendert.
- zproben/ nach archiv/proben/; Reste x, target_release, mutants.out(.old) entfernt, ignoriert.
- docs: Wurzel-VERTRAG.md (veraltete Kopie), NAHT, PROMPT, PROMPT-2, SCHARF-PRUEFUNG,
  WAS_ICH_BRAUCHE geloescht; docs/notizen/README.md (alte Kern-README) aufgeloest in MODULES.md
  und CLAUDE.md.
- plans/: 12 erledigte Plaene geloescht; es bleiben die vier, die Specs als Vertrag zitieren.
- STAND-weltklasse.md: veraltete Abschnitte 1, 2, 4, 5 (Lage 13.11., doppelt zu STATUS/PLAN) entfernt,
  jetzt reines Messprotokoll.
- README: Deutung an die eigene Tabelle angeglichen (C-Bet-Folder, GTO, LBR).
- CLAUDE.md: Ordnertabelle vollstaendig, Messordner-Regel messung/<track>/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 23:19:52 +01:00

110 lines
3.7 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! The client HUD a live seat carries (PokerIntel), for the `ReadMode::Hud` ladder rows.
//!
//! Live, 95 % of seats arrive with PokerIntel numbers whose effective sample is far below the hands
//! they claim (`lesen/pokerintel.py`, STAND §16: vpip ~12 chances, fold ~4). The sim reproduces that:
//! a pre-session on its own seed measures the opponent's true rates (`SessionMemory::raw_profile`),
//! then each field is drawn from Beta(m·θ, m·(1−θ)) with the measured m. The engine then reads that
//! HUD exactly like the live wire (`SessionMemory::hud_read` → `sample::hud_profile`).
use super::memory::SessionMemory;
use super::population::normal;
use crate::exploit::profile::Profile;
use crate::rng::Rng;
/// Deals of the truth pre-session.
pub const HUD_VOR: u32 = 800;
/// Effective chances per field (`messung/gedaechtnis/pokerintel.json`, fit with fixed mean).
pub const M_VPIP: f64 = 12.1;
pub const M_PFR: f64 = 10.0;
pub const M_FOLD: f64 = 4.0;
pub const M_FOLD_TO_CBET: f64 = 3.1;
pub const M_FOLD_TO_THREE_BET: f64 = 30.0;
pub const M_CHECK_RAISE: f64 = 12.5;
/// Gamma(shape, 1) by Marsaglia–Tsang (shape < 1 via the boost u^(1/shape)).
fn gamma(shape: f64, rng: Rng) -> (f64, Rng) {
if shape < 1.0 {
let (g, rng) = gamma(shape + 1.0, rng);
let (u, rng) = rng.unit();
return (g * u.max(1e-300).powf(1.0 / shape), rng);
}
let d = shape - 1.0 / 3.0;
let c = 1.0 / (9.0 * d).sqrt();
let mut rng = rng;
loop {
let (z, r) = normal(rng);
let (u, r) = r.unit();
rng = r;
let v = (1.0 + c * z).powi(3);
if v > 0.0 && u.max(1e-300).ln() < 0.5 * z * z + d - d * v + d * v.ln() {
return (d * v, rng);
}
}
}
/// One draw of a rate measured over `m` chances whose truth is `theta`.
pub fn noisy(theta: f64, m: f64, rng: Rng) -> (f64, Rng) {
let t = theta.clamp(0.005, 0.995);
let (a, rng) = gamma(m * t, rng);
let (b, rng) = gamma(m * (1.0 - t), rng);
(a / (a + b), rng)
}
/// The HUD a seat shows: every known truth field drawn noisily, unknown fields stay `None`.
pub fn draw(truth: &Profile, rng: Rng) -> Profile {
let mut rng = rng;
let mut f = |x: Option<f64>, m: f64| {
x.map(|t| {
let (v, r) = noisy(t, m, rng);
rng = r;
v
})
};
Profile {
vpip: f(truth.vpip, M_VPIP),
pfr: f(truth.pfr, M_PFR),
fold_to_bet: f(truth.fold_to_bet, M_FOLD),
fold_to_cbet: f(truth.fold_to_cbet, M_FOLD_TO_CBET),
fold_to_three_bet: f(truth.fold_to_three_bet, M_FOLD_TO_THREE_BET),
check_raise: f(truth.check_raise, M_CHECK_RAISE),
..Profile::default()
}
}
/// The truth of a pre-session memory, as the HUD source.
pub fn truth(memory: &SessionMemory) -> Profile {
memory.raw_profile()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn noisy_has_the_right_mean_and_spread() {
let (n, theta, m) = (20000, 0.3, 10.0);
let mut rng = Rng::seeded(7);
let mut xs = Vec::with_capacity(n);
for _ in 0..n {
let (x, r) = noisy(theta, m, rng);
rng = r;
xs.push(x);
}
let mean = xs.iter().sum::<f64>() / n as f64;
let var = xs.iter().map(|x| (x - mean).powi(2)).sum::<f64>() / n as f64;
assert!((mean - theta).abs() < 0.01, "mean {mean}");
let want = theta * (1.0 - theta) / (m + 1.0);
assert!((var / want - 1.0).abs() < 0.08, "var {var} want {want}");
}
#[test]
fn small_shapes_stay_in_range() {
let mut rng = Rng::seeded(3);
for _ in 0..2000 {
let (x, r) = noisy(0.02, 3.0, rng);
rng = r;
assert!((0.0..=1.0).contains(&x));
}
}
}