- STEAL_BREITE=wert allein gegen Live: Leiter +1,32 ±0,20 GEWINNER (station +24,38), Micro +0,07, Lerner +0,06, Pools 0/-0,02, 6-max +2,7/+2,5, LBR nicht schlechter, Pflichtfaelle 33/43 wie live, Replay 0 von 889 anders. Live-Kandidat. - INFO_KONSISTENT=paar: Freigabe am River fuehrte zu Paar-Raises auf 2x Pot (Pflichtfaelle 177113202312, 177689800544 schlechter als live). Jetzt nur Flop/Turn; Pflichtfaelle 33/43 bestanden, Tor laeuft. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
331 lines
15 KiB
Rust
331 lines
15 KiB
Rust
//! How much a profile is worth: its sample. Opponent statistics come without a hand count, so
|
||
//! the caller sends one (`villains[].profile.hands`, extension, not in VERTRAG.md). Few hands
|
||
//! mean the numbers are mostly noise; they are pulled toward the population before anything
|
||
//! reads them.
|
||
//!
|
||
//! | step | rule |
|
||
//! |---|---|
|
||
//! | trust | `w = hands / (hands + PRIOR_HANDS)`; no, negative or broken count: 0 |
|
||
//! | shrink | each known frequency `x` becomes `p + w * (x - p)` with the population `p` in `PRIOR` |
|
||
//! | absent | a missing frequency stays missing; a profile without `hands` is used as given |
|
||
|
||
use crate::exploit::profile::Profile;
|
||
|
||
/// Hands at which the sample and the population weigh the same (`trust` 0.5).
|
||
pub const PRIOR_HANDS: f64 = 30.0;
|
||
|
||
/// The population an unknown opponent is assumed to be: a regular of the stock. The HUD extras have
|
||
/// no population prior yet: a missing one leaves `shrink` to pass the measured value through, so a
|
||
/// field without a prior is never pulled off the client's number.
|
||
pub const PRIOR: Profile = Profile {
|
||
vpip: Some(0.28),
|
||
pfr: Some(0.18),
|
||
fold_to_bet: Some(0.45),
|
||
aggression: Some(0.35),
|
||
// No population prior for per-street aggression: a missing one lets `shrink` pass the measured
|
||
// value through unshrunk.
|
||
turn_aggression: None,
|
||
river_aggression: None,
|
||
street_fold_to_bet: [None; 3],
|
||
cbet: None,
|
||
fold_to_cbet: None,
|
||
three_bet: None,
|
||
fold_to_three_bet: None,
|
||
steal: None,
|
||
check_raise: None,
|
||
wtsd: None,
|
||
wsd: None,
|
||
confidence: None,
|
||
aggression_confidence: None,
|
||
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,
|
||
reraise_to_raise: None,
|
||
size_gain: None,
|
||
fold_only: false,
|
||
pool_baseline: false,
|
||
pool_raise_value: false,
|
||
};
|
||
|
||
/// Postflop moves at which an aggression read and the population weigh the same — the session
|
||
/// memory's half-life (`sim::memory::CONFIDENCE_HALF`), so a live read earns trust as fast as a
|
||
/// simulated one.
|
||
pub const AGGRESSION_HALF: f64 = 30.0;
|
||
|
||
/// Weight of the sample in `[0, 1)`.
|
||
pub fn trust(hands: f64) -> f64 {
|
||
if hands.is_nan() || hands <= 0.0 {
|
||
return 0.0;
|
||
}
|
||
hands / (hands + PRIOR_HANDS)
|
||
}
|
||
|
||
fn pull(x: Option<f64>, p: Option<f64>, w: f64) -> Option<f64> {
|
||
match (x.filter(|v| !v.is_nan()), p) {
|
||
(Some(x), Some(p)) => Some(p + w * (x - p)),
|
||
(x, _) => x,
|
||
}
|
||
}
|
||
|
||
/// The profile as the engine should believe it after `hands` hands.
|
||
pub fn shrink(profile: &Profile, hands: f64) -> Profile {
|
||
let w = trust(hands);
|
||
Profile {
|
||
vpip: pull(profile.vpip, PRIOR.vpip, w),
|
||
pfr: pull(profile.pfr, PRIOR.pfr, w),
|
||
fold_to_bet: pull(profile.fold_to_bet, PRIOR.fold_to_bet, w),
|
||
aggression: pull(profile.aggression, PRIOR.aggression, w),
|
||
turn_aggression: pull(profile.turn_aggression, PRIOR.turn_aggression, w),
|
||
river_aggression: pull(profile.river_aggression, PRIOR.river_aggression, w),
|
||
street_fold_to_bet: profile.street_fold_to_bet,
|
||
cbet: pull(profile.cbet, PRIOR.cbet, w),
|
||
fold_to_cbet: pull(profile.fold_to_cbet, PRIOR.fold_to_cbet, w),
|
||
three_bet: pull(profile.three_bet, PRIOR.three_bet, w),
|
||
fold_to_three_bet: pull(profile.fold_to_three_bet, PRIOR.fold_to_three_bet, w),
|
||
steal: pull(profile.steal, PRIOR.steal, w),
|
||
check_raise: pull(profile.check_raise, PRIOR.check_raise, w),
|
||
wtsd: pull(profile.wtsd, PRIOR.wtsd, w),
|
||
wsd: pull(profile.wsd, PRIOR.wsd, w),
|
||
// The sample weight IS the read confidence (same half-life): a client profile with a hand
|
||
// count earns the gearbox's trust exactly as a session-memory read does. Keep an explicit
|
||
// confidence if one was already set.
|
||
confidence: profile.confidence.or(Some(w)),
|
||
aggression_confidence: profile.aggression_confidence,
|
||
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,
|
||
reraise_to_raise: profile.reraise_to_raise,
|
||
size_gain: profile.size_gain,
|
||
fold_only: profile.fold_only,
|
||
pool_baseline: profile.pool_baseline,
|
||
pool_raise_value: profile.pool_raise_value,
|
||
}
|
||
}
|
||
|
||
/// Messschalter (einmal gelesen) `INFO_KONSISTENT=1` (Auftrag 17.11. "Information schadet nie"): jede
|
||
/// Schwelle auf der Aggression liest den Read als Posterior. Der Read ist `w * roh + (1 - w) * PRIOR`
|
||
/// (`shrink_aggression`, Prior 0,35); die Schwellen der Entscheidung (Station 0,45, Bluff-Mittel 0,45,
|
||
/// passiv 0,45) sind aber in Orakel-Einheiten geeicht, in denen "nichts bekannt" = blind = neutral heisst.
|
||
/// Ohne Schalter war ein Read ohne Aggressions-Stichprobe darum "passiver als blind" (0,35 < 0,45):
|
||
/// weniger Bluffs geglaubt, Paar-Raise gesperrt, Station-Klasse - Information schadete. Mit Schalter
|
||
/// zaehlt der Stichproben-Teil `w` mit dem rohen Wert, der Rest mit dem neutralen Wert der Schwelle;
|
||
/// ein voller Read (Orakel, `aggression_confidence` fehlt = 1) bleibt unveraendert. Vorgabe aus: bitgleich.
|
||
pub fn info_konsistent() -> bool {
|
||
info_modus() & 1 != 0
|
||
}
|
||
|
||
/// Nur der Paar-Raise-Riegel (`PAAR_RAISE`, `engine::options::all_passive`), nur Flop/Turn: `INFO_KONSISTENT=1|paar`.
|
||
pub fn info_konsistent_paar() -> bool {
|
||
info_modus() & 2 != 0
|
||
}
|
||
|
||
/// Bit 1 = Bluff-Anteil, Bit 2 = Paar-Riegel; `1` beide, `bluff` / `paar` je einer (Zerlegung).
|
||
fn info_modus() -> u8 {
|
||
use std::sync::OnceLock;
|
||
static MODUS: OnceLock<u8> = OnceLock::new();
|
||
*MODUS.get_or_init(|| match std::env::var("INFO_KONSISTENT").as_deref() {
|
||
Ok("1") => 3,
|
||
Ok("bluff") => 1,
|
||
Ok("paar") => 2,
|
||
_ => 0,
|
||
})
|
||
}
|
||
|
||
/// Gewicht der eigenen Aggressions-Stichprobe im Read (`aggression_confidence`; fehlt sie bei einem
|
||
/// Read mit Aggression, ist er voll = 1). `None` ohne Aggressions-Read.
|
||
pub fn aggression_weight(p: &Profile) -> Option<f64> {
|
||
p.aggression.filter(|a| a.is_finite())?;
|
||
Some(p.aggression_confidence.filter(|c| c.is_finite()).unwrap_or(1.0).clamp(0.0, 1.0))
|
||
}
|
||
|
||
/// Die Aggression des Reads mit dem Prior-Teil auf `neutral` statt auf `PRIOR` (siehe
|
||
/// `info_konsistent`): `w * roh + (1 - w) * neutral`. `None` ohne Aggressions-Read.
|
||
pub fn aggression_at(p: &Profile, neutral: f64) -> Option<f64> {
|
||
let a = p.aggression.filter(|a| a.is_finite())?.clamp(0.0, 1.0);
|
||
let w = aggression_weight(p)?;
|
||
let prior = PRIOR.aggression.unwrap_or(0.35);
|
||
Some((a + (1.0 - w) * (neutral - prior)).clamp(0.0, 1.0))
|
||
}
|
||
|
||
/// The aggression read on its OWN sample: `raw` was measured over `actions` postflop moves (not over
|
||
/// the HUD's hands), so it is shrunk toward the population with that weight and carries it as
|
||
/// `aggression_confidence`. No usable count: the profile is returned unchanged.
|
||
pub fn shrink_aggression(profile: Profile, raw: Option<f64>, actions: f64) -> Profile {
|
||
if actions.is_nan() || actions < 0.0 {
|
||
return profile;
|
||
}
|
||
let w = actions / (actions + AGGRESSION_HALF);
|
||
Profile { aggression: pull(raw, PRIOR.aggression, w), aggression_confidence: Some(w), ..profile }
|
||
}
|
||
|
||
/// Share of a HUD's hands in which the player faces a c-bet / a 3-bet after opening / a bet after
|
||
/// checking (rough 6-max frequencies): the effective sample of each line stat.
|
||
pub const CBET_SPOT_SHARE: f64 = 0.15;
|
||
pub const THREE_BET_SPOT_SHARE: f64 = 0.04;
|
||
pub const CHECK_RAISE_SPOT_SHARE: f64 = 0.10;
|
||
|
||
/// The base sample `lesen/profil.py` gives a believable client HUD (`GLAUBHAFT`): the wire's `hands` is
|
||
/// this plus the hands we saw ourselves.
|
||
pub const GLAUBHAFT: f64 = 20.0;
|
||
|
||
/// Measured worth of the PokerIntel numbers in engine hands (`lesen/pokerintel.py`, STAND §16): the
|
||
/// hand count that gives the engine's trust `h/(h+30)` the weight the data earn against the population.
|
||
/// vpip/pfr are worth far more than the flat 20 (fitted weight 0.76–0.88, lower 95 % bound >= 0.57 →
|
||
/// 60 hands = weight 0.67), the fold-to-bet number far less (weight 0.07–0.22 → 8 hands = 0.21). The
|
||
/// other fields stay at the flat base: their intervals reach 0 and 1, the data do not carry a change.
|
||
pub const PI_HANDS_VPIP: f64 = 60.0;
|
||
pub const PI_HANDS_PFR: f64 = 60.0;
|
||
pub const PI_HANDS_FOLD: f64 = 8.0;
|
||
|
||
/// Switch `POKERINTEL=1` (read once): the HUD fields get their measured weights (`hud_profile`).
|
||
/// Off (default): the flat `GLAUBHAFT` base for every field, bit-identical to before.
|
||
pub fn pokerintel_on() -> bool {
|
||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||
*ON.get_or_init(|| std::env::var("POKERINTEL").as_deref() == Ok("1"))
|
||
}
|
||
|
||
/// The sample one field rests on when the client base `GLAUBHAFT` is worth `base` hands for it: our own
|
||
/// hands on top count as they are; a thin profile (below the base, `lesen/profil.py DUENN`) is scaled.
|
||
pub fn field_hands(hands: f64, base: f64) -> f64 {
|
||
if hands.is_nan() || hands <= 0.0 {
|
||
return hands;
|
||
}
|
||
if hands >= GLAUBHAFT {
|
||
hands - GLAUBHAFT + base
|
||
} else {
|
||
hands * base / GLAUBHAFT
|
||
}
|
||
}
|
||
|
||
/// A client HUD with a hand count, as the engine believes it: `shrink` over `hands`, then the line stats
|
||
/// (foldToCbet, foldToThreeBet, checkRaise) over the fraction of hands their spot arises in, toward their
|
||
/// anchors (as the sim memory does), so 40 HUD hands are not 40 c-bets. With `POKERINTEL=1`
|
||
/// (`hud_profile_weighted`) vpip, pfr and fold-to-bet carry their measured worth instead of the flat
|
||
/// base, and the fold/range read's `confidence` is the fold-to-bet trust.
|
||
pub fn hud_profile(raw: &Profile, hands: f64) -> Profile {
|
||
hud_profile_with(raw, hands, pokerintel_on())
|
||
}
|
||
|
||
pub fn hud_profile_with(raw: &Profile, hands: f64, weighted: bool) -> Profile {
|
||
let mut p = shrink(raw, hands);
|
||
if weighted {
|
||
let w = |base: f64| trust(field_hands(hands, base));
|
||
let w_fold = w(PI_HANDS_FOLD);
|
||
p.vpip = pull(raw.vpip, PRIOR.vpip, w(PI_HANDS_VPIP));
|
||
p.pfr = pull(raw.pfr, PRIOR.pfr, w(PI_HANDS_PFR));
|
||
p.fold_to_bet = pull(raw.fold_to_bet, PRIOR.fold_to_bet, w_fold);
|
||
p.confidence = raw.confidence.or(Some(w_fold));
|
||
}
|
||
let line = |x: Option<f64>, share: f64, anchor: Option<f64>| shrink_street(x, hands * share, anchor);
|
||
let cbet_anchor = p.fold_to_bet.or(Some(crate::exploit::fold_chance::DEFAULT_FOLD_TO_BET));
|
||
Profile {
|
||
fold_to_cbet: line(p.fold_to_cbet, CBET_SPOT_SHARE, cbet_anchor),
|
||
fold_to_three_bet: line(p.fold_to_three_bet, THREE_BET_SPOT_SHARE, Some(FOLD_TO_THREE_BET_ANCHOR)),
|
||
check_raise: line(p.check_raise, CHECK_RAISE_SPOT_SHARE, Some(CHECK_RAISE_ANCHOR)),
|
||
..p
|
||
}
|
||
}
|
||
|
||
/// Anchors of the line reads that have no pooled read to shrink toward (a regular's HUD): fold to
|
||
/// 3-bet and check-raise. Shared by the sim memory and the wire.
|
||
pub const FOLD_TO_THREE_BET_ANCHOR: f64 = 0.55;
|
||
pub const CHECK_RAISE_ANCHOR: f64 = 0.08;
|
||
/// Prior strength of the check-raise read in pseudo-chances (Beta(mu*kappa, (1-mu)*kappa)).
|
||
pub const CHECK_RAISE_KAPPA: f64 = 15.0;
|
||
|
||
/// Street samples at which one street's own read and the pooled read weigh the same — the session
|
||
/// memory's `sim::memory::STREET_FOLD_PRIOR`, so a live street read earns trust as a simulated one.
|
||
pub const STREET_PRIOR: f64 = 15.0;
|
||
|
||
/// One street's read (`raw`, measured over `n` moves on that street) pulled toward the `pooled` read of
|
||
/// all streets: `(raw·n + STREET_PRIOR·pooled) / (n + STREET_PRIOR)`. A few river moves barely move
|
||
/// the river belief off the pooled one. No street sample, a broken count or no pooled read to anchor
|
||
/// on: `None`, so the engine falls back to the pooled read (never a raw 0/1 from one move).
|
||
pub fn shrink_street(raw: Option<f64>, n: f64, pooled: Option<f64>) -> Option<f64> {
|
||
let raw = raw.filter(|x| !x.is_nan())?;
|
||
let pooled = pooled.filter(|x| !x.is_nan())?;
|
||
if n.is_nan() || n <= 0.0 {
|
||
return None;
|
||
}
|
||
Some((raw * n + STREET_PRIOR * pooled) / (n + STREET_PRIOR))
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
|
||
fn hud() -> Profile {
|
||
Profile {
|
||
vpip: Some(0.45),
|
||
pfr: Some(0.08),
|
||
fold_to_bet: Some(0.70),
|
||
aggression: Some(0.2),
|
||
fold_to_cbet: Some(0.8),
|
||
fold_to_three_bet: Some(0.3),
|
||
check_raise: Some(0.2),
|
||
..Profile::default()
|
||
}
|
||
}
|
||
|
||
/// Switch off: exactly the old wire (shrink over `hands`, line stats over their spot share).
|
||
#[test]
|
||
fn off_is_the_old_wire() {
|
||
for hands in [0.0, 5.0, 20.0, 44.0, 300.0, f64::NAN] {
|
||
let raw = hud();
|
||
let p = shrink(&raw, hands);
|
||
let anchor = p.fold_to_bet.or(Some(crate::exploit::fold_chance::DEFAULT_FOLD_TO_BET));
|
||
let old = Profile {
|
||
fold_to_cbet: shrink_street(p.fold_to_cbet, hands * CBET_SPOT_SHARE, anchor),
|
||
fold_to_three_bet: shrink_street(p.fold_to_three_bet, hands * THREE_BET_SPOT_SHARE, Some(FOLD_TO_THREE_BET_ANCHOR)),
|
||
check_raise: shrink_street(p.check_raise, hands * CHECK_RAISE_SPOT_SHARE, Some(CHECK_RAISE_ANCHOR)),
|
||
..p
|
||
};
|
||
let new = hud_profile_with(&raw, hands, false);
|
||
assert_eq!(format!("{old:?}"), format!("{new:?}"), "hands {hands}");
|
||
}
|
||
}
|
||
|
||
/// Switch on: vpip/pfr believed more, fold-to-bet less, by the measured effective samples.
|
||
#[test]
|
||
fn on_reweights_by_field() {
|
||
let raw = hud();
|
||
let (off, on) = (hud_profile_with(&raw, 24.0, false), hud_profile_with(&raw, 24.0, true));
|
||
let d = |x: Option<f64>, p: f64| (x.unwrap() - p).abs();
|
||
assert!(d(on.vpip, 0.28) > d(off.vpip, 0.28));
|
||
assert!(d(on.pfr, 0.18) > d(off.pfr, 0.18));
|
||
assert!(d(on.fold_to_bet, 0.45) < d(off.fold_to_bet, 0.45));
|
||
assert!(on.confidence.unwrap() < off.confidence.unwrap());
|
||
assert_eq!(on.aggression, off.aggression);
|
||
}
|
||
|
||
#[test]
|
||
fn field_hands_maps_the_default_and_counts_own_hands_fully() {
|
||
assert_eq!(field_hands(GLAUBHAFT, 60.0), 60.0);
|
||
assert_eq!(field_hands(GLAUBHAFT + 10.0, 8.0), 18.0);
|
||
assert_eq!(field_hands(10.0, 60.0), 30.0);
|
||
assert_eq!(field_hands(0.0, 60.0), 0.0);
|
||
}
|
||
|
||
/// Information schadet nie: ein Read ohne Aggressions-Stichprobe steht auf dem neutralen Wert der
|
||
/// Schwelle (= blind), ein voller Read (Orakel ohne `aggression_confidence`) bleibt unveraendert,
|
||
/// dazwischen zaehlt die Stichprobe mit ihrem Gewicht.
|
||
#[test]
|
||
fn aggression_at_reads_the_prior_part_as_neutral() {
|
||
let leer = shrink_aggression(Profile::default(), Some(0.9), 0.0);
|
||
assert!((aggression_at(&leer, 0.45).unwrap() - 0.45).abs() < 1e-12);
|
||
let orakel = Profile { aggression: Some(0.25), ..Profile::default() };
|
||
assert_eq!(aggression_at(&orakel, 0.45), Some(0.25));
|
||
let halb = shrink_aggression(Profile::default(), Some(0.05), AGGRESSION_HALF);
|
||
assert!((aggression_at(&halb, 0.45).unwrap() - 0.25).abs() < 1e-12);
|
||
assert_eq!(aggression_at(&Profile::default(), 0.45), None);
|
||
}
|
||
}
|