Schaetzer (lesen/pokerintel.py): vpip/pfr tragen ~60 Motorhaende, foldToBet ~8 statt pauschal 20. hud_profile teilt Draht und Sim; ReadMode::Hud zieht verrauschte PokerIntel-Zahlen (Beta, gemessenes m) aus einer Vorsession und liest sie wie der Draht. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
582 lines
27 KiB
Rust
582 lines
27 KiB
Rust
//! Session memory (Stage 1): the engine builds its read from the opponent's OBSERVED actions over
|
|
//! the hands of a session, instead of being handed the converged HUD read (`sim::reads`) or playing
|
|
//! blind. A HUD that only counts - per opponent seat, preflop voluntary money and raises, postflop
|
|
//! folds-to-a-bet and aggression - turned into a `Profile` once a warmup of hands is seen, so the
|
|
//! first hands play blind and the read converges to the truth over the session.
|
|
//!
|
|
//! The gap blind -> read-given that `benchmarks/baseline.txt` / `tests/sim_blind` measure is exactly
|
|
//! what this must recapture: a `... (memory)` scenario lands between the blind and the read-given
|
|
//! twin, the share of the prize that observation alone earns. Every opponent seat is the same fixed
|
|
//! archetype, so their counts pool into one read.
|
|
|
|
use crate::exploit::profile::Profile;
|
|
use crate::exploit::sample::shrink_aggression;
|
|
use crate::game::{line, ActionRecord, SeenAction, Street};
|
|
|
|
pub use super::welt_memory::{
|
|
strength_band, Cell, Move, Pos, Reveal, SizeBucket, Showdown, Texture, Tank, WorldEvent, WorldHand,
|
|
WorldMemory, STRENGTH_BANDS,
|
|
};
|
|
|
|
/// Hands to observe before the read is trusted; until then `read` is `None` (the engine plays
|
|
/// blind). Keeps an early, noisy sample from steering worse than no read at all.
|
|
pub const WARMUP_HANDS: u32 = 25;
|
|
|
|
/// Postflop actions at which the read's confidence reaches 0.5 (half-life). Matches the Bayesian
|
|
/// posterior's `VERTRAUEN_HALB` so the counts HUD and `exploit::posterior` agree on how fast a read
|
|
/// earns trust. The river gearbox turns this confidence into the KL trust radius.
|
|
pub const CONFIDENCE_HALF: f64 = 30.0;
|
|
|
|
/// Running tallies over the opponent archetype. Preflop opportunities (`hands`) and the voluntary /
|
|
/// raise counts drive vpip and pfr; the postflop tallies drive fold-to-bet and aggression.
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
struct Counts {
|
|
hands: u32,
|
|
vpip: u32,
|
|
pfr: u32,
|
|
folded_to_bet: u32,
|
|
passive_call: u32,
|
|
passive_check: u32,
|
|
aggressive: u32,
|
|
// Per-street aggression split (turn and river only — the streets the subgame gearboxes solve).
|
|
// `*_passive` is calls plus checks on that street (the aggression denominator, matching the pooled
|
|
// one which counts checks); folds are excluded, as in the pooled aggression.
|
|
turn_aggressive: u32,
|
|
turn_passive: u32,
|
|
river_aggressive: u32,
|
|
river_passive: u32,
|
|
// Facing-a-bet outcomes per street (flop, turn, river): folds and calls, for the per-street
|
|
// fold-to-bet read.
|
|
street_fold: [u32; 3],
|
|
street_call: [u32; 3],
|
|
// Line-specific HUD stats (`game::line`): responses facing a c-bet / a 3-bet after opening /
|
|
// a bet after own check, and how many of them folded / folded / raised.
|
|
cbet_faced: u32,
|
|
cbet_folded: u32,
|
|
three_bet_faced: u32,
|
|
three_bet_folded: u32,
|
|
xr_chances: u32,
|
|
xr_made: u32,
|
|
}
|
|
|
|
fn street_index(street: Street) -> Option<usize> {
|
|
match street {
|
|
Street::Flop => Some(0),
|
|
Street::Turn => Some(1),
|
|
Street::River => Some(2),
|
|
Street::Preflop => None,
|
|
}
|
|
}
|
|
|
|
/// Facing-a-bet samples that weigh as much as the pooled read when shrinking a street's fold rate.
|
|
pub const STREET_FOLD_PRIOR: f64 = crate::exploit::sample::STREET_PRIOR;
|
|
|
|
static STREET_FOLD: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(true);
|
|
|
|
/// Switch the per-street fold read on or off (A/B arm for the ladder). Default on.
|
|
pub fn set_street_fold(on: bool) {
|
|
STREET_FOLD.store(on, std::sync::atomic::Ordering::Relaxed);
|
|
}
|
|
|
|
fn street_fold_on() -> bool {
|
|
STREET_FOLD.load(std::sync::atomic::Ordering::Relaxed)
|
|
}
|
|
|
|
/// Line-specific HUD reads switched into `read()`: bit 1 fold to c-bet, 2 fold to 3-bet, 4 check-raise.
|
|
static LINE_READS: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0);
|
|
|
|
/// Line reads in `read()` (A/B arm): `READ_CBET | READ_THREE_BET | READ_CHECK_RAISE`. Default none.
|
|
pub fn set_line_reads(mask: u8) {
|
|
LINE_READS.store(mask, std::sync::atomic::Ordering::Relaxed);
|
|
}
|
|
pub const READ_CBET: u8 = 1;
|
|
pub const READ_THREE_BET: u8 = 2;
|
|
pub const READ_CHECK_RAISE: u8 = 4;
|
|
|
|
fn line_read_on(bit: u8) -> bool {
|
|
LINE_READS.load(std::sync::atomic::Ordering::Relaxed) & bit != 0
|
|
}
|
|
|
|
/// Population anchors the line reads shrink toward over `STREET_FOLD_PRIOR` samples (a regular's
|
|
/// HUD): fold to 3-bet and check-raise have no pooled read to anchor on.
|
|
use crate::exploit::sample::{
|
|
CHECK_RAISE_ANCHOR as CHECK_RAISE_PRIOR, CHECK_RAISE_KAPPA, FOLD_TO_THREE_BET_ANCHOR as FOLD_TO_THREE_BET_PRIOR,
|
|
};
|
|
|
|
static RIVER_SHOWDOWN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
|
|
|
/// Switch the river showdown read (`Profile::river_bluff_share`, from the world memory's revealed river
|
|
/// bets) into `read()` (A/B arm for the ladder). Default off until the ladder proves it.
|
|
pub fn set_river_showdown(on: bool) {
|
|
RIVER_SHOWDOWN.store(on, std::sync::atomic::Ordering::Relaxed);
|
|
}
|
|
|
|
fn river_showdown_on() -> bool {
|
|
RIVER_SHOWDOWN.load(std::sync::atomic::Ordering::Relaxed)
|
|
}
|
|
|
|
/// The read a HUD accumulates from watching one fixed opponent archetype play a session.
|
|
#[derive(Clone, Debug, Default, PartialEq)]
|
|
pub struct SessionMemory {
|
|
c: Counts,
|
|
/// The richer dimensions (sizing x strength, texture x position cells, showdown reveals, timing),
|
|
/// see `sim::welt_memory`. Filled only by `observe_world_hand`; `read()` ignores it, so the classic
|
|
/// HUD read (and every existing ladder number) is unchanged by it.
|
|
world: WorldMemory,
|
|
}
|
|
|
|
impl SessionMemory {
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// The world-dimension observations (sizing, texture/position cells, showdowns, timing).
|
|
pub fn world(&self) -> &WorldMemory {
|
|
&self.world
|
|
}
|
|
|
|
/// Fold one finished hand's world observations (see `WorldHand`) into the world memory.
|
|
/// The raw (chances, hits) per read, for the empirical-Bayes fit of the population priors
|
|
/// (`lesen/eichung.py`), named like `lesen/zaehler.py`.
|
|
pub fn line_counts(&self) -> Vec<(&'static str, u32, u32)> {
|
|
let c = &self.c;
|
|
vec![
|
|
("vpip", c.hands, c.vpip),
|
|
("pfr", c.hands, c.pfr),
|
|
("aggression", c.aggressive + c.passive_call + c.passive_check, c.aggressive),
|
|
("flopFoldToBet", c.street_fold[0] + c.street_call[0], c.street_fold[0]),
|
|
("turnFoldToBet", c.street_fold[1] + c.street_call[1], c.street_fold[1]),
|
|
("riverFoldToBet", c.street_fold[2] + c.street_call[2], c.street_fold[2]),
|
|
("foldToCbet", c.cbet_faced, c.cbet_folded),
|
|
("foldToThreeBet", c.three_bet_faced, c.three_bet_folded),
|
|
("checkRaise", c.xr_chances, c.xr_made),
|
|
]
|
|
}
|
|
|
|
pub fn observe_world_hand(&mut self, hand: &WorldHand) {
|
|
self.world.observe_world_hand(hand);
|
|
}
|
|
|
|
/// Fold every opponent seat's actions of one finished hand into the counts. `hero` is the
|
|
/// 0-based hero seat; every other of the `players` seats is an opponent of the same archetype.
|
|
pub fn observe_hand(&mut self, history: &[ActionRecord], hero: usize, players: usize) {
|
|
for seat in 1..=players as u8 {
|
|
if seat as usize - 1 != hero {
|
|
self.observe_seat(history, seat);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The line-specific responses of `seat`: each of its actions judged against the line before it.
|
|
fn observe_lines(&mut self, history: &[ActionRecord], seat: u8) {
|
|
for (k, r) in history.iter().enumerate().filter(|(_, r)| r.seat == seat) {
|
|
let before = &history[..k];
|
|
let folded = r.action == SeenAction::Fold;
|
|
if r.street == Street::Flop && line::facing_cbet(before, seat) {
|
|
self.c.cbet_faced += 1;
|
|
self.c.cbet_folded += folded as u32;
|
|
}
|
|
if r.street == Street::Preflop && line::facing_three_bet(before, seat) {
|
|
self.c.three_bet_faced += 1;
|
|
self.c.three_bet_folded += folded as u32;
|
|
}
|
|
if r.street != Street::Preflop && line::check_raise_chance(before, seat, r.street) {
|
|
self.c.xr_chances += 1;
|
|
self.c.xr_made += r.action.is_aggressive() as u32;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// One seat's actions of a finished hand (a per-opponent memory at a mixed table, `sim::sechsmax`).
|
|
pub fn observe_seat(&mut self, history: &[ActionRecord], seat: u8) {
|
|
self.observe_lines(history, seat);
|
|
self.c.hands += 1;
|
|
let (mut voluntary, mut raised) = (false, false);
|
|
for r in history.iter().filter(|r| r.seat == seat) {
|
|
if r.street == Street::Preflop {
|
|
// Blinds are forced (PostSmallBlind / PostBigBlind); a check is free. Only a call or
|
|
// an aggressive action puts money in by choice.
|
|
match r.action {
|
|
SeenAction::Call | SeenAction::Bet | SeenAction::Raise | SeenAction::AllIn => {
|
|
voluntary = true;
|
|
}
|
|
_ => {}
|
|
}
|
|
raised |= r.action.is_aggressive();
|
|
} else {
|
|
// Postflop a fold or a call only happens facing a bet; a check faces nothing. The
|
|
// check still counts as a passive action for aggression (matching how the oracle
|
|
// reads are measured, `tests/sim_opponent_stats`): leaving checks out of the
|
|
// denominator makes a passive, check-heavy opponent look far more aggressive than it
|
|
// is, and `bluff_share` reads aggression directly.
|
|
match r.action {
|
|
SeenAction::Fold => {
|
|
self.c.folded_to_bet += 1;
|
|
if let Some(i) = street_index(r.street) {
|
|
self.c.street_fold[i] += 1;
|
|
}
|
|
}
|
|
SeenAction::Call => {
|
|
if let Some(i) = street_index(r.street) {
|
|
self.c.street_call[i] += 1;
|
|
}
|
|
self.c.passive_call += 1;
|
|
self.bump_passive(r.street);
|
|
}
|
|
SeenAction::Check => {
|
|
self.c.passive_check += 1;
|
|
self.bump_passive(r.street);
|
|
}
|
|
a if a.is_aggressive() => {
|
|
self.c.aggressive += 1;
|
|
self.bump_aggressive(r.street);
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
self.c.vpip += voluntary as u32;
|
|
self.c.pfr += raised as u32;
|
|
}
|
|
|
|
/// A passive postflop action (call or check) on the turn/river, for the per-street aggression
|
|
/// denominator. Flop and preflop are not split.
|
|
fn bump_passive(&mut self, street: Street) {
|
|
match street {
|
|
Street::Turn => self.c.turn_passive += 1,
|
|
Street::River => self.c.river_passive += 1,
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
/// An aggressive postflop action (bet or raise) on the turn/river, for the per-street numerator.
|
|
fn bump_aggressive(&mut self, street: Street) {
|
|
match street {
|
|
Street::Turn => self.c.turn_aggressive += 1,
|
|
Street::River => self.c.river_aggressive += 1,
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
/// The read so far, or `None` during the warmup. vpip / pfr are over hands; fold-to-bet is folds
|
|
/// over folds-plus-calls facing a bet; aggression is bets-and-raises over bets-raises-and-calls.
|
|
pub fn read(&self) -> Option<Profile> {
|
|
if self.c.hands < WARMUP_HANDS {
|
|
return None;
|
|
}
|
|
let ratio = |num: u32, den: u32| (den > 0).then(|| num as f64 / den as f64);
|
|
let facing_bet = self.c.folded_to_bet + self.c.passive_call;
|
|
// Aggression frequency: bets and raises over every non-folding postflop action, checks
|
|
// included (see `observe_seat`).
|
|
let postflop_actions = self.c.aggressive + self.c.passive_call + self.c.passive_check;
|
|
// Confidence for the gearbox: the read is only as trustworthy as its weaker postflop sample —
|
|
// the facing-a-bet count (drives fold_to_bet / the defense belief) and the total postflop
|
|
// count (drives aggression / the betting-polarization belief). Half at CONFIDENCE_HALF.
|
|
let conf = |n: u32| n as f64 / (n as f64 + CONFIDENCE_HALF);
|
|
let confidence = conf(facing_bet.min(postflop_actions));
|
|
// Per-street aggression: bets/raises over bets-raises-plus-passive on that street (same shape
|
|
// as the pooled frequency). `None` until the street has an action, so `believed_villain` falls
|
|
// back to the pooled read.
|
|
let street_aggr = |aggr: u32, passive: u32| ratio(aggr, aggr + passive);
|
|
let pooled_fold = ratio(self.c.folded_to_bet, facing_bet);
|
|
let mut street_fold_to_bet = [None; 3];
|
|
if let (true, Some(pooled)) = (street_fold_on(), pooled_fold) {
|
|
for i in 0..3 {
|
|
let n = (self.c.street_fold[i] + self.c.street_call[i]) as f64;
|
|
if n > 0.0 {
|
|
street_fold_to_bet[i] =
|
|
Some((self.c.street_fold[i] as f64 + STREET_FOLD_PRIOR * pooled) / (n + STREET_FOLD_PRIOR));
|
|
}
|
|
}
|
|
}
|
|
let river_bluff = self.world.river_bluff().filter(|_| river_showdown_on());
|
|
// Line reads, shrunk like the street reads: c-bet folds toward the flop fold read (else the
|
|
// pooled one), the others toward a regular's number.
|
|
let shrunk = |num: u32, den: u32, anchor: Option<f64>| {
|
|
anchor.filter(|_| den > 0).map(|a| (num as f64 + STREET_FOLD_PRIOR * a) / (den as f64 + STREET_FOLD_PRIOR))
|
|
};
|
|
let flop_anchor = street_fold_to_bet[0].or(pooled_fold);
|
|
let fold_to_cbet = shrunk(self.c.cbet_folded, self.c.cbet_faced, flop_anchor).filter(|_| line_read_on(READ_CBET));
|
|
let fold_to_three_bet = shrunk(self.c.three_bet_folded, self.c.three_bet_faced, Some(FOLD_TO_THREE_BET_PRIOR))
|
|
.filter(|_| line_read_on(READ_THREE_BET));
|
|
let check_raise = (self.c.xr_chances > 0)
|
|
.then(|| (self.c.xr_made as f64 + CHECK_RAISE_KAPPA * CHECK_RAISE_PRIOR) / (self.c.xr_chances as f64 + CHECK_RAISE_KAPPA))
|
|
.filter(|_| line_read_on(READ_CHECK_RAISE));
|
|
Some(Profile {
|
|
street_fold_to_bet,
|
|
fold_to_cbet,
|
|
fold_to_three_bet,
|
|
check_raise,
|
|
river_bluff_share: river_bluff.map(|(s, _)| s),
|
|
river_bluff_shown: river_bluff.map(|(_, n)| n as f64),
|
|
vpip: ratio(self.c.vpip, self.c.hands),
|
|
pfr: ratio(self.c.pfr, self.c.hands),
|
|
fold_to_bet: ratio(self.c.folded_to_bet, facing_bet),
|
|
aggression: ratio(self.c.aggressive, postflop_actions),
|
|
turn_aggression: street_aggr(self.c.turn_aggressive, self.c.turn_passive),
|
|
river_aggression: street_aggr(self.c.river_aggressive, self.c.river_passive),
|
|
confidence: Some(confidence),
|
|
..Profile::default()
|
|
})
|
|
}
|
|
}
|
|
|
|
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`).
|
|
pub fn raw_profile(&self) -> Profile {
|
|
let ratio = |num: u32, den: u32| (den > 0).then(|| num as f64 / den as f64);
|
|
Profile {
|
|
vpip: ratio(self.c.vpip, self.c.hands),
|
|
pfr: ratio(self.c.pfr, self.c.hands),
|
|
fold_to_bet: ratio(self.c.folded_to_bet, self.c.folded_to_bet + self.c.passive_call),
|
|
aggression: ratio(self.c.aggressive, self.c.aggressive + self.c.passive_call + self.c.passive_check),
|
|
fold_to_cbet: ratio(self.c.cbet_folded, self.c.cbet_faced),
|
|
fold_to_three_bet: ratio(self.c.three_bet_folded, self.c.three_bet_faced),
|
|
check_raise: ratio(self.c.xr_made, self.c.xr_chances),
|
|
..Profile::default()
|
|
}
|
|
}
|
|
|
|
/// The read a live table gives (`wire::decode_villain`): the client HUD `hud` (raw PokerIntel
|
|
/// numbers) believed over `GLAUBHAFT` + the hands seen so far (`sample::hud_profile`), the
|
|
/// aggression on its own counted moves, the street reads counted here toward the HUD-pooled ones.
|
|
pub fn hud_read(&self, hud: &Profile) -> Option<Profile> {
|
|
let hands = crate::exploit::sample::GLAUBHAFT + self.c.hands as f64;
|
|
let base = crate::exploit::sample::hud_profile(hud, hands);
|
|
let ratio = |num: u32, den: u32| (den > 0).then(|| num as f64 / den as f64);
|
|
let actions = self.c.aggressive + self.c.passive_call + self.c.passive_check;
|
|
let p = if actions > 0 {
|
|
shrink_aggression(base, ratio(self.c.aggressive, actions), actions as f64)
|
|
} else {
|
|
base
|
|
};
|
|
let street = |aggr: u32, passive: u32, anchor: Option<f64>| {
|
|
crate::exploit::sample::shrink_street(ratio(aggr, aggr + passive), (aggr + passive) as f64, anchor)
|
|
};
|
|
let mut street_fold_to_bet = [None; 3];
|
|
if street_fold_on() {
|
|
for (i, s) in street_fold_to_bet.iter_mut().enumerate() {
|
|
*s = street(self.c.street_fold[i], self.c.street_call[i], p.fold_to_bet);
|
|
}
|
|
}
|
|
let river_bluff = self.world.river_bluff().filter(|_| river_showdown_on());
|
|
Some(Profile {
|
|
turn_aggression: street(self.c.turn_aggressive, self.c.turn_passive, p.aggression).or(p.turn_aggression),
|
|
river_aggression: street(self.c.river_aggressive, self.c.river_passive, p.aggression).or(p.river_aggression),
|
|
street_fold_to_bet,
|
|
river_bluff_share: river_bluff.map(|(s, _)| s),
|
|
river_bluff_shown: river_bluff.map(|(_, n)| n as f64),
|
|
..p
|
|
})
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::exploit::style::{classify, Style};
|
|
|
|
fn rec(street: Street, seat: u8, action: SeenAction) -> ActionRecord {
|
|
ActionRecord { street, seat, action, amount: None }
|
|
}
|
|
|
|
/// The line reads count only the responses to their own line, shrink toward their anchors, and
|
|
/// stay out of the read until switched on (so the ladder stays bit-identical by default).
|
|
#[test]
|
|
fn line_reads_count_their_own_spots() {
|
|
use SeenAction::*;
|
|
let mut m = SessionMemory::new();
|
|
// Hero (seat 1) opens and c-bets, the opponent (seat 2) folds the flop: a c-bet fold.
|
|
let cbet_fold = [
|
|
rec(Street::Preflop, 1, PostSmallBlind), rec(Street::Preflop, 2, PostBigBlind),
|
|
rec(Street::Preflop, 1, Raise), rec(Street::Preflop, 2, Call),
|
|
rec(Street::Flop, 2, Check), rec(Street::Flop, 1, Bet), rec(Street::Flop, 2, Fold),
|
|
];
|
|
// The opponent opens, hero 3-bets, the opponent folds.
|
|
let three_fold = [
|
|
rec(Street::Preflop, 2, PostSmallBlind), rec(Street::Preflop, 1, PostBigBlind),
|
|
rec(Street::Preflop, 2, Raise), rec(Street::Preflop, 1, Raise), rec(Street::Preflop, 2, Fold),
|
|
];
|
|
for _ in 0..30 {
|
|
m.observe_hand(&cbet_fold, 0, 2);
|
|
m.observe_hand(&three_fold, 0, 2);
|
|
}
|
|
assert_eq!((m.c.cbet_faced, m.c.cbet_folded), (30, 30));
|
|
assert_eq!((m.c.three_bet_faced, m.c.three_bet_folded), (30, 30));
|
|
assert_eq!((m.c.xr_chances, m.c.xr_made), (30, 0), "checked, faced the bet, folded: no check-raise");
|
|
let off = m.read().expect("read");
|
|
assert_eq!((off.fold_to_cbet, off.fold_to_three_bet, off.check_raise), (None, None, None));
|
|
set_line_reads(READ_CBET | READ_THREE_BET | READ_CHECK_RAISE);
|
|
let on = m.read().expect("read");
|
|
set_line_reads(0);
|
|
assert!(on.fold_to_cbet.unwrap() > 0.9);
|
|
assert!((on.fold_to_three_bet.unwrap() - (30.0 + 15.0 * 0.55) / 45.0).abs() < 1e-12);
|
|
assert!((on.check_raise.unwrap() - 15.0 * 0.08 / 45.0).abs() < 1e-12);
|
|
}
|
|
|
|
/// One heads-up hand (hero seat 0 = seat 1, opponent seat 2): the opponent calls hero's preflop
|
|
/// raise (voluntary, not a raise), then calls a flop bet and folds the turn (passive, folds to a
|
|
/// bet, never aggressive).
|
|
fn loose_passive_hand() -> Vec<ActionRecord> {
|
|
vec![
|
|
rec(Street::Preflop, 1, SeenAction::PostSmallBlind),
|
|
rec(Street::Preflop, 2, SeenAction::PostBigBlind),
|
|
rec(Street::Preflop, 1, SeenAction::Raise),
|
|
rec(Street::Preflop, 2, SeenAction::Call),
|
|
rec(Street::Flop, 1, SeenAction::Bet),
|
|
rec(Street::Flop, 2, SeenAction::Call),
|
|
rec(Street::Turn, 1, SeenAction::Bet),
|
|
rec(Street::Turn, 2, SeenAction::Fold),
|
|
]
|
|
}
|
|
|
|
#[test]
|
|
fn no_read_before_the_warmup() {
|
|
let mut m = SessionMemory::new();
|
|
let h = loose_passive_hand();
|
|
for _ in 0..WARMUP_HANDS - 1 {
|
|
m.observe_hand(&h, 0, 2);
|
|
}
|
|
assert_eq!(m.read(), None);
|
|
m.observe_hand(&h, 0, 2);
|
|
assert!(m.read().is_some());
|
|
}
|
|
|
|
#[test]
|
|
fn a_seat_that_only_posts_a_blind_is_not_vpip() {
|
|
// Hero seat 0; the opponent (seat 2) is the big blind and checks its option: no voluntary
|
|
// money, no raise.
|
|
let hand = vec![
|
|
rec(Street::Preflop, 1, SeenAction::PostSmallBlind),
|
|
rec(Street::Preflop, 2, SeenAction::PostBigBlind),
|
|
rec(Street::Preflop, 1, SeenAction::Call),
|
|
rec(Street::Preflop, 2, SeenAction::Check),
|
|
];
|
|
let mut m = SessionMemory::new();
|
|
for _ in 0..WARMUP_HANDS {
|
|
m.observe_hand(&hand, 0, 2);
|
|
}
|
|
let p = m.read().expect("read after warmup");
|
|
assert_eq!(p.vpip, Some(0.0));
|
|
assert_eq!(p.pfr, Some(0.0));
|
|
}
|
|
|
|
#[test]
|
|
fn the_loose_passive_opponent_reads_as_a_calling_station() {
|
|
let mut m = SessionMemory::new();
|
|
let h = loose_passive_hand();
|
|
for _ in 0..40 {
|
|
m.observe_hand(&h, 0, 2);
|
|
}
|
|
let p = m.read().expect("read");
|
|
assert_eq!(p.vpip, Some(1.0)); // calls every preflop
|
|
assert_eq!(p.pfr, Some(0.0));
|
|
assert_eq!(p.fold_to_bet, Some(0.5)); // one call, one fold facing a bet
|
|
assert_eq!(p.aggression, Some(0.0)); // never bets or raises postflop
|
|
assert_eq!(classify(&p), Style::CallingStation);
|
|
}
|
|
|
|
#[test]
|
|
fn checks_count_toward_aggression_so_a_passive_opponent_reads_passive() {
|
|
// Seat 2 bets once but checks the flop in every other hand. Aggression must be 1 / (1 bet +
|
|
// many checks), near zero - not 1 / 1 from leaving the checks out of the denominator.
|
|
let bet = vec![
|
|
rec(Street::Preflop, 1, SeenAction::PostSmallBlind),
|
|
rec(Street::Preflop, 2, SeenAction::PostBigBlind),
|
|
rec(Street::Preflop, 1, SeenAction::Call),
|
|
rec(Street::Preflop, 2, SeenAction::Check),
|
|
rec(Street::Flop, 2, SeenAction::Bet),
|
|
];
|
|
let check = vec![
|
|
rec(Street::Preflop, 1, SeenAction::PostSmallBlind),
|
|
rec(Street::Preflop, 2, SeenAction::PostBigBlind),
|
|
rec(Street::Preflop, 1, SeenAction::Call),
|
|
rec(Street::Preflop, 2, SeenAction::Check),
|
|
rec(Street::Flop, 2, SeenAction::Check),
|
|
];
|
|
let mut m = SessionMemory::new();
|
|
m.observe_hand(&bet, 0, 2);
|
|
for _ in 0..29 {
|
|
m.observe_hand(&check, 0, 2);
|
|
}
|
|
let p = m.read().expect("read");
|
|
assert_eq!(p.aggression, Some(1.0 / 30.0)); // 1 bet, 29 checks
|
|
}
|
|
|
|
#[test]
|
|
fn per_street_aggression_splits_the_turn_from_the_pooled_read() {
|
|
// Seat 2 checks the flop (passive) but bets the turn (aggressive), no river action. The pooled
|
|
// aggression is 1 bet / (1 bet + 1 check) = 0.5, but the TURN aggression is 1/1 = 1.0, and the
|
|
// river stays None. This is exactly the barreler the pooled read under-sells.
|
|
let hand = vec![
|
|
rec(Street::Preflop, 1, SeenAction::PostSmallBlind),
|
|
rec(Street::Preflop, 2, SeenAction::PostBigBlind),
|
|
rec(Street::Preflop, 1, SeenAction::Raise),
|
|
rec(Street::Preflop, 2, SeenAction::Call),
|
|
rec(Street::Flop, 1, SeenAction::Check),
|
|
rec(Street::Flop, 2, SeenAction::Check),
|
|
rec(Street::Turn, 1, SeenAction::Check),
|
|
rec(Street::Turn, 2, SeenAction::Bet),
|
|
];
|
|
let mut m = SessionMemory::new();
|
|
for _ in 0..40 {
|
|
m.observe_hand(&hand, 0, 2);
|
|
}
|
|
let p = m.read().expect("read");
|
|
assert_eq!(p.aggression, Some(0.5)); // 1 bet, 1 flop check pooled
|
|
assert_eq!(p.turn_aggression, Some(1.0)); // bets every turn, never passive on the turn
|
|
assert_eq!(p.river_aggression, None); // no river action seen
|
|
}
|
|
|
|
#[test]
|
|
fn street_fold_is_shrunk_toward_the_pooled_read() {
|
|
// Folds every flop bet, calls every turn bet: pooled fold 0.5; the flop (n=40 folds) moves
|
|
// well above it, the turn well below it, the river (no data) stays None.
|
|
let hand = vec![
|
|
rec(Street::Preflop, 1, SeenAction::PostSmallBlind),
|
|
rec(Street::Preflop, 2, SeenAction::PostBigBlind),
|
|
rec(Street::Preflop, 1, SeenAction::Raise),
|
|
rec(Street::Preflop, 2, SeenAction::Call),
|
|
rec(Street::Flop, 1, SeenAction::Bet),
|
|
rec(Street::Flop, 2, SeenAction::Fold),
|
|
];
|
|
let call = vec![
|
|
rec(Street::Preflop, 1, SeenAction::Raise),
|
|
rec(Street::Preflop, 2, SeenAction::Call),
|
|
rec(Street::Turn, 1, SeenAction::Bet),
|
|
rec(Street::Turn, 2, SeenAction::Call),
|
|
];
|
|
let mut m = SessionMemory::new();
|
|
for _ in 0..20 {
|
|
m.observe_hand(&hand, 0, 2);
|
|
m.observe_hand(&call, 0, 2);
|
|
}
|
|
let p = m.read().expect("read");
|
|
assert_eq!(p.fold_to_bet, Some(0.5));
|
|
let flop = p.street_fold_to_bet[0].expect("flop");
|
|
let turn = p.street_fold_to_bet[1].expect("turn");
|
|
assert!(flop > 0.7 && flop < 1.0, "{flop}");
|
|
assert!(turn < 0.3 && turn > 0.0, "{turn}");
|
|
assert_eq!(p.street_fold_to_bet[2], None);
|
|
}
|
|
|
|
#[test]
|
|
fn a_tight_folding_opponent_reads_as_a_nit() {
|
|
// Seat 2 folds preflop every hand: no voluntary money, and (vpip 0) classifies as a nit.
|
|
let hand = vec![
|
|
rec(Street::Preflop, 1, SeenAction::PostSmallBlind),
|
|
rec(Street::Preflop, 2, SeenAction::PostBigBlind),
|
|
rec(Street::Preflop, 1, SeenAction::Raise),
|
|
rec(Street::Preflop, 2, SeenAction::Fold),
|
|
];
|
|
let mut m = SessionMemory::new();
|
|
for _ in 0..40 {
|
|
m.observe_hand(&hand, 0, 2);
|
|
}
|
|
let p = m.read().expect("read");
|
|
assert_eq!(p.vpip, Some(0.0));
|
|
assert_eq!(classify(&p), Style::Nit);
|
|
}
|
|
}
|