107 lines
5.1 KiB
Rust
107 lines
5.1 KiB
Rust
//! Bluff share of an open bet from the counted open-bet frequency (`EINSATZ_BLUFF=1`, 17.11.).
|
||
//!
|
||
//! `aggression` counts calls in its denominator: a player who calls a lot and bluffs often when he bets
|
||
//! (nemesis-2) reads as passive and his bets as value. What tells how much air a bet carries is how
|
||
//! often the player bets when he may check (`Profile::bet_open`, bets over checks + bets with no bet on
|
||
//! the street yet). Range consistency: a player bets his value hands (a fixed share of his range);
|
||
//! how often he bets beyond that decides the air in his bets.
|
||
//!
|
||
//! | step | rule |
|
||
//! |---|---|
|
||
//! | posterior | `f = (k + κ·μ) / (n + κ)` with the NL2 pool `μ` per street and `κ` = `POOL_KAPPA` (`messung/gedaechtnis/einsatz/pool-einsatz.txt`) |
|
||
//! | pool | at `f = μ` the blind belief `b0`: air `b0·μ`, the rest value of the range |
|
||
//! | air curve | air per chance `b0·μ·r^γ` with `r = f / μ`, `γ` = `GAMMA` per street, calibrated on PHH showdowns (NL25+50, 4.66 M hands, `messung/gedaechtnis/einsatz/phh-eichung.txt`) |
|
||
//! | share | air / `f` = `b0·r^(γ-1)`, clamped to `[0, MAX_BLUFF_SHARE]` |
|
||
//!
|
||
//! At `f = μ` (no sample) the read says exactly what blind says: information cannot hurt from the prior.
|
||
//! Off (default): nothing counts it and the profile stays bit-identical. Gate 17.11. with the PHH curve:
|
||
//! loser (ladder -0.99, maniac -9.69; `messung/gedaechtnis/einsatz/tor-ebg.txt`), stays off.
|
||
|
||
use super::bluff_share::MAX_BLUFF_SHARE;
|
||
use super::profile::Profile;
|
||
use crate::game::Street;
|
||
|
||
/// NL2 pool open-bet frequency (flop, turn, river): own raw logs 17.11., 4862 hands, 373/350/322
|
||
/// players (`pool_einsatz.py`).
|
||
pub const POOL: [f64; 3] = [0.340, 0.367, 0.328];
|
||
/// Pseudo-chances of the pool prior (between-player spread of the same logs, kappa 10.1 / 12.3 / 11.1).
|
||
pub const POOL_KAPPA: f64 = 11.0;
|
||
|
||
/// Exponent of the air curve per street (flop, turn, river): shown open bets at showdown, air = equity
|
||
/// < 0.40 against a random hand, ratio to the r ~ 1 bucket (selection bias of shown hands cancels as a
|
||
/// factor). Player bootstrap 95 %: flop [2.19; 2.28], turn [2.29; 2.39], river [2.26; 2.34]. Replaces the
|
||
/// assumption `AIR_OF_REST = 0.5` (66af4c4a), which put too little air into frequent bettors and took too much
|
||
/// out of rare ones (linear slopes measured 3.2-4.2 above, 1.6-1.8 below the pool, in units of b0).
|
||
pub const GAMMA: [f64; 3] = [2.23, 2.34, 2.30];
|
||
|
||
/// Switch `EINSATZ_BLUFF=1` (read once).
|
||
pub fn enabled() -> bool {
|
||
use std::sync::OnceLock;
|
||
static ON: OnceLock<bool> = OnceLock::new();
|
||
*ON.get_or_init(|| std::env::var("EINSATZ_BLUFF").as_deref() == Ok("1"))
|
||
}
|
||
|
||
fn slot(street: Street) -> Option<usize> {
|
||
match street {
|
||
Street::Flop => Some(0),
|
||
Street::Turn => Some(1),
|
||
Street::River => Some(2),
|
||
Street::Preflop => None,
|
||
}
|
||
}
|
||
|
||
/// The posterior open-bet frequency on `street`; `None` without a counted read there.
|
||
pub fn frequency(p: &Profile, street: Street) -> Option<f64> {
|
||
let i = slot(street)?;
|
||
let (k, n) = p.bet_open[i].filter(|(k, n)| k.is_finite() && n.is_finite() && *n > 0.0 && *k >= 0.0 && k <= n)?;
|
||
Some((k + POOL_KAPPA * POOL[i]) / (n + POOL_KAPPA))
|
||
}
|
||
|
||
/// Air share of an open bet on `street` for a player with the counted frequency, given what blind
|
||
/// believes there (`blind`); `None` (keep the incoming share) when off or without a read.
|
||
pub fn open_bluff_share(profile: Option<&Profile>, street: Street, blind: f64) -> Option<f64> {
|
||
if !enabled() {
|
||
return None;
|
||
}
|
||
let f = frequency(profile?, street)?;
|
||
let i = slot(street)?;
|
||
Some(share(f, POOL[i], GAMMA[i], blind))
|
||
}
|
||
|
||
/// The air share of bets at frequency `f` around the pool `mu` (curve exponent `gamma`) with the blind
|
||
/// belief `blind` there.
|
||
pub fn share(f: f64, mu: f64, gamma: f64, blind: f64) -> f64 {
|
||
let b0 = blind.clamp(0.0, MAX_BLUFF_SHARE);
|
||
let r = f.max(1e-6) / mu.max(1e-6);
|
||
(b0 * r.powf(gamma - 1.0)).clamp(0.0, MAX_BLUFF_SHARE)
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
|
||
fn p(k: f64, n: f64) -> Profile {
|
||
Profile { bet_open: [Some((k, n)); 3], ..Profile::default() }
|
||
}
|
||
|
||
/// No sample = the pool = blind; a frequent bettor bets wider (more air), a rare one is value.
|
||
#[test]
|
||
fn frequency_moves_air_around_the_blind_belief() {
|
||
let mu = POOL[2];
|
||
let f = frequency(&p(0.0, 0.0001), Street::River).unwrap();
|
||
assert!((f - mu).abs() < 1e-3);
|
||
let g = GAMMA[2];
|
||
let k = |k: f64, n: f64| share(frequency(&p(k, n), Street::River).unwrap(), mu, g, 0.3);
|
||
assert!((k(mu * 40.0, 40.0) - 0.3).abs() < 1e-9);
|
||
assert!(k(30.0, 40.0) > 0.3);
|
||
assert!(k(4.0, 40.0) < 0.3);
|
||
assert!((share(mu, mu, g, 0.3) - 0.3).abs() < 1e-12);
|
||
// PHH river: r 1.46 -> shown air 1.54x the pool bucket, r 0.62 -> 0.56x
|
||
assert!((share(1.46 * mu, mu, g, 0.3) / 0.3 - 1.46f64.powf(g - 1.0)).abs() < 1e-9);
|
||
assert!(share(0.62 * mu, mu, g, 0.3) < 0.3 * 0.6);
|
||
assert!(share(0.9, mu, g, 0.5) <= MAX_BLUFF_SHARE);
|
||
assert_eq!(frequency(&Profile::default(), Street::River), None);
|
||
assert_eq!(frequency(&p(1.0, 2.0), Street::Preflop), None);
|
||
}
|
||
}
|