Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
327 lines
14 KiB
Rust
327 lines
14 KiB
Rust
//! Plausibility of the frozen charts: they must look like poker, not just solve the abstraction.
|
|
//!
|
|
//! Widths are shares of the 1326 combos. Frequencies are permille in the tables.
|
|
//!
|
|
//! Direction of the properties (model facts, not assumptions about real play):
|
|
//! - push/fold: shorter stack => wider jamming AND wider calling; later seat => wider jamming.
|
|
//! - open/call/3-bet: later seat => wider opening (EP <= MP <= CO <= BTN). With stack depth the
|
|
//! opening range does NOT widen monotonically in this model: the postflop payoff is a fixed
|
|
//! share of a pot that does not grow with the stacks, and only the jam line (rarer and less
|
|
//! attractive the deeper the stacks) depends on depth, so the width is nearly flat (observed
|
|
//! spread 0.04 between the 20 / 40 / 100 bb tables of one seat, peak at 40 bb). The test pins
|
|
//! what holds: the width changes by less than `DEPTH_DRIFT`.
|
|
//!
|
|
//! Observed on the frozen tables (the slacks below are several times looser): per-class
|
|
//! violations of the position order 0.0 (exact subsets) and width violations 0.0.
|
|
mod cfr_support;
|
|
|
|
use cfr_support::{id, width, width_column};
|
|
use rechner::cfr::hand_class::CLASS_COUNT;
|
|
use rechner::cfr::seat::Seat;
|
|
use rechner::preflop::generated_charts::{
|
|
AOF_PUSH_FOLD, OPEN, OPEN_DEPTHS, PUSH_FOLD, PUSH_FOLD_DEPTHS,
|
|
};
|
|
|
|
/// Per-class slack when comparing mixed frequencies across spots (mixing at range borders).
|
|
const SLACK: f64 = 0.05;
|
|
/// Width slack between neighbouring spots.
|
|
const WIDTH_SLACK: f64 = 0.01;
|
|
const DEPTH_DRIFT: f64 = 0.06;
|
|
|
|
fn push_spot(seat: Seat, depth: u8) -> &'static rechner::cfr::frozen_spot::PushFoldSpot {
|
|
PUSH_FOLD.iter().find(|s| s.seat == seat && s.depth_bb == depth).expect("push spot")
|
|
}
|
|
|
|
fn open_spot(seat: Seat, depth: u8) -> &'static rechner::cfr::frozen_spot::OpenSpot {
|
|
OPEN.iter().find(|s| s.seat == seat && s.depth_bb == depth).expect("open spot")
|
|
}
|
|
|
|
fn fraction(row: &[u16; CLASS_COUNT], class: usize) -> f64 {
|
|
row[class] as f64 / 1000.0
|
|
}
|
|
|
|
#[test]
|
|
fn tables_cover_every_seat_and_depth_exactly_once() {
|
|
assert_eq!(PUSH_FOLD.len(), 5 * PUSH_FOLD_DEPTHS.len());
|
|
assert_eq!(OPEN.len(), 4 * OPEN_DEPTHS.len() + OPEN_DEPTHS.len());
|
|
for seat in Seat::ALL {
|
|
for depth in PUSH_FOLD_DEPTHS {
|
|
assert_eq!(PUSH_FOLD.iter().filter(|s| s.seat == seat && s.depth_bb == depth).count(), 1);
|
|
}
|
|
for depth in OPEN_DEPTHS {
|
|
assert_eq!(OPEN.iter().filter(|s| s.seat == seat && s.depth_bb == depth).count(), 1);
|
|
}
|
|
}
|
|
assert_eq!(PUSH_FOLD_DEPTHS, [5, 8, 10, 12, 15, 20, 25]);
|
|
assert_eq!(OPEN_DEPTHS, [20, 40, 100]);
|
|
}
|
|
|
|
#[test]
|
|
fn permille_rows_are_well_formed() {
|
|
for s in PUSH_FOLD.iter() {
|
|
assert!(s.push.iter().chain(s.call.iter()).all(|f| *f <= 1000));
|
|
}
|
|
for s in OPEN.iter() {
|
|
assert!(s.open.iter().all(|f| *f <= 1000));
|
|
assert!(s.vs_jam.iter().all(|f| *f <= 1000));
|
|
for row in [&s.defend, &s.vs_three_bet] {
|
|
assert!(row.iter().all(|[call, raise]| call + raise <= 1000));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn aces_always_raise_or_jam_and_never_fold() {
|
|
let aa = id("AA");
|
|
for s in PUSH_FOLD.iter() {
|
|
assert_eq!(s.push[aa], 1000, "AA pushes at {} {}bb", s.seat.label(), s.depth_bb);
|
|
assert_eq!(s.call[aa], 1000, "AA calls a push at {} {}bb", s.seat.label(), s.depth_bb);
|
|
}
|
|
for s in AOF_PUSH_FOLD.iter() {
|
|
assert_eq!((s.push[aa], s.call[aa]), (1000, 1000));
|
|
}
|
|
for s in OPEN.iter() {
|
|
let tag = format!("{} {}bb", s.seat.label(), s.depth_bb);
|
|
assert_eq!(s.open[aa], 1000, "AA opens at {tag}");
|
|
let [call, three_bet] = s.defend[aa];
|
|
assert_eq!(call + three_bet, 1000, "AA never folds to an open at {tag}");
|
|
assert!(three_bet >= 900, "AA 3-bets at {tag}: {three_bet}");
|
|
let [call, jam] = s.vs_three_bet[aa];
|
|
assert_eq!(call + jam, 1000, "AA never folds to a 3-bet at {tag}");
|
|
assert!(jam >= 900, "AA jams over a 3-bet at {tag}: {jam}");
|
|
assert_eq!(s.vs_jam[aa], 1000, "AA calls a jam at {tag}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn push_ranges_widen_with_position_as_subsets() {
|
|
for depth in PUSH_FOLD_DEPTHS {
|
|
let order = [Seat::Early, Seat::Middle, Seat::Cutoff, Seat::Button, Seat::SmallBlind];
|
|
for pair in order.windows(2) {
|
|
let (early, late) = (push_spot(pair[0], depth), push_spot(pair[1], depth));
|
|
assert!(
|
|
width(&early.push) <= width(&late.push) + WIDTH_SLACK,
|
|
"{} -> {} at {depth}bb: {} vs {}",
|
|
pair[0].label(), pair[1].label(), width(&early.push), width(&late.push)
|
|
);
|
|
for c in 0..CLASS_COUNT {
|
|
assert!(
|
|
fraction(&early.push, c) <= fraction(&late.push, c) + SLACK,
|
|
"class {c} {} -> {} at {depth}bb", pair[0].label(), pair[1].label()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn shorter_stacks_jam_and_call_wider() {
|
|
for seat in Seat::ALL {
|
|
for pair in PUSH_FOLD_DEPTHS.windows(2) {
|
|
let (short, deep) = (push_spot(seat, pair[0]), push_spot(seat, pair[1]));
|
|
assert!(
|
|
width(&short.push) >= width(&deep.push) - WIDTH_SLACK,
|
|
"push {} {}bb vs {}bb", seat.label(), pair[0], pair[1]
|
|
);
|
|
assert!(
|
|
width(&short.call) >= width(&deep.call) - WIDTH_SLACK,
|
|
"call {} {}bb vs {}bb", seat.label(), pair[0], pair[1]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_big_blind_calls_wider_against_wider_pushing_seats() {
|
|
for depth in PUSH_FOLD_DEPTHS {
|
|
let order = [Seat::Early, Seat::Middle, Seat::Cutoff, Seat::Button, Seat::SmallBlind];
|
|
for pair in order.windows(2) {
|
|
assert!(
|
|
width(&push_spot(pair[0], depth).call) <= width(&push_spot(pair[1], depth).call) + WIDTH_SLACK,
|
|
"call vs {} -> {} at {depth}bb", pair[0].label(), pair[1].label()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn open_ranges_widen_with_position_as_subsets() {
|
|
for depth in OPEN_DEPTHS {
|
|
let order = [Seat::Early, Seat::Middle, Seat::Cutoff, Seat::Button];
|
|
for pair in order.windows(2) {
|
|
let (early, late) = (open_spot(pair[0], depth), open_spot(pair[1], depth));
|
|
assert!(
|
|
width(&early.open) <= width(&late.open) + WIDTH_SLACK,
|
|
"{} -> {} at {depth}bb: {} vs {}",
|
|
pair[0].label(), pair[1].label(), width(&early.open), width(&late.open)
|
|
);
|
|
for c in 0..CLASS_COUNT {
|
|
assert!(
|
|
fraction(&early.open, c) <= fraction(&late.open, c) + SLACK,
|
|
"class {c} {} -> {} at {depth}bb", pair[0].label(), pair[1].label()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn open_width_is_roughly_stable_across_depth_and_never_degenerate() {
|
|
for seat in Seat::ALL {
|
|
let widths: Vec<f64> = OPEN_DEPTHS.iter().map(|d| width(&open_spot(seat, *d).open)).collect();
|
|
let (lo, hi) = widths.iter().fold((1.0_f64, 0.0_f64), |(l, h), w| (l.min(*w), h.max(*w)));
|
|
assert!(hi - lo <= DEPTH_DRIFT, "{} widths {widths:?}", seat.label());
|
|
assert!(lo > 0.04 && hi < 0.95, "{} widths {widths:?}", seat.label());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn stronger_hands_are_never_played_less_than_clearly_weaker_ones() {
|
|
// Same ranks, suited >= offsuit; a bigger pair >= a smaller pair.
|
|
for s in PUSH_FOLD.iter() {
|
|
for (suited, offsuit) in [("AKs", "AKo"), ("T9s", "T9o"), ("A5s", "A5o"), ("KQs", "KQo")] {
|
|
assert!(fraction(&s.push, id(suited)) + 0.05 >= fraction(&s.push, id(offsuit)));
|
|
}
|
|
for (big, small) in [("AA", "KK"), ("KK", "99"), ("99", "55"), ("55", "22")] {
|
|
assert!(fraction(&s.push, id(big)) + 0.05 >= fraction(&s.push, id(small)));
|
|
assert!(fraction(&s.call, id(big)) + 0.05 >= fraction(&s.call, id(small)));
|
|
}
|
|
assert!(fraction(&s.push, id("72o")) <= fraction(&s.push, id("A2o")) + 0.05);
|
|
}
|
|
for s in OPEN.iter() {
|
|
for (big, small) in [("AA", "KK"), ("KK", "99"), ("99", "55")] {
|
|
assert!(fraction(&s.open, id(big)) + 0.05 >= fraction(&s.open, id(small)));
|
|
}
|
|
assert!(fraction(&s.open, id("32o")) <= 0.05, "{} {}bb opens 32o", s.seat.label(), s.depth_bb);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn heads_up_small_blind_matches_published_push_fold_nash() {
|
|
// Reference: heads-up push/fold Nash equilibrium at 10 effective big blinds (blinds 0.5/1):
|
|
// the small blind jams roughly the top 55-60 % of hands and the big blind calls roughly the
|
|
// top 35-42 % (Miller / Sklansky-Chubukov style charts, HoldemResources Nash calculator and
|
|
// ICMIZER heads-up charts all agree within a few points). Tolerance reflects that spread
|
|
// plus the Monte-Carlo noise of the equity table. Values quoted from memory of those
|
|
// published charts, not re-derived here.
|
|
let spot = push_spot(Seat::SmallBlind, 10);
|
|
let push = width(&spot.push);
|
|
let call = width(&spot.call);
|
|
assert!((0.52..=0.64).contains(&push), "SB 10bb push {push}");
|
|
assert!((0.32..=0.45).contains(&call), "BB 10bb call {call}");
|
|
// Classic anchors of that chart: any ace and any pair pushes; 72o folds; 32o folds.
|
|
assert!(spot.push[id("A2o")] >= 900 && spot.push[id("22")] == 1000);
|
|
assert_eq!(spot.push[id("32o")], 0);
|
|
// At 5 bb the small blind jams clearly wider (about 70 %): the big blind must call ~60 % to
|
|
// keep him honest, and 72o still loses to folding (EV -0.7 vs -0.5), so 100 % is not Nash.
|
|
let five = width(&push_spot(Seat::SmallBlind, 5).push);
|
|
assert!(five > push + 0.08 && five < 0.9, "SB 5bb push {five}");
|
|
}
|
|
|
|
#[test]
|
|
fn all_in_or_fold_tables_are_the_push_fold_tables() {
|
|
assert_eq!(AOF_PUSH_FOLD.len(), PUSH_FOLD.len());
|
|
for (a, b) in AOF_PUSH_FOLD.iter().zip(PUSH_FOLD.iter()) {
|
|
assert_eq!(a, b);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn convergence_metadata_is_consistent() {
|
|
for s in PUSH_FOLD.iter() {
|
|
let m = &s.meta;
|
|
assert!(m.iterations >= 1_000, "{} {}bb", s.seat.label(), s.depth_bb);
|
|
assert!(m.stable_since >= 1 && m.stable_since <= m.iterations);
|
|
assert_eq!(m.checkpoints[m.checkpoints.len() - 1].0, m.iterations);
|
|
// Exploitability falls along the curve (allow tiny wobble) and ends below the bound.
|
|
let first = m.checkpoints[0].1;
|
|
let last = m.checkpoints[m.checkpoints.len() - 1].1;
|
|
assert!(last <= first, "{} {}bb curve", s.seat.label(), s.depth_bb);
|
|
assert!(m.exploitability_micro_bb < 10_000, "below 0.01 bb");
|
|
}
|
|
for s in OPEN.iter() {
|
|
let m = &s.meta;
|
|
assert!(m.iterations >= 1_000);
|
|
assert!(m.stable_since >= 1 && m.stable_since <= m.iterations);
|
|
assert!(m.checkpoints[m.checkpoints.len() - 1].1 <= m.checkpoints[0].1);
|
|
assert!(m.exploitability_micro_bb < 10_000);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn tight_seats_defend_less_than_they_open_wide_and_big_blind_defends_widest_against_the_button() {
|
|
// Against a later (wider) opener the big blind continues with a wider range.
|
|
for depth in OPEN_DEPTHS {
|
|
let vs_ep = open_spot(Seat::Early, depth);
|
|
let vs_btn = open_spot(Seat::Button, depth);
|
|
let cont = |s: &rechner::cfr::frozen_spot::OpenSpot| {
|
|
width_column(&s.defend, 0) + width_column(&s.defend, 1)
|
|
};
|
|
assert!(cont(vs_ep) <= cont(vs_btn) + WIDTH_SLACK, "{depth}bb");
|
|
}
|
|
}
|
|
|
|
/// Open width of EP and MP with only the big blind as defender (the tables before both blinds
|
|
/// were players), 20 / 40 / 100 bb.
|
|
const ONE_DEFENDER_OPEN: [(Seat, [f64; 3]); 2] =
|
|
[(Seat::Early, [0.288, 0.298, 0.291]), (Seat::Middle, [0.332, 0.357, 0.340])];
|
|
/// How much narrower EP and MP must open now that both blinds defend.
|
|
const SHRINK: f64 = 0.02;
|
|
|
|
#[test]
|
|
fn early_and_middle_open_narrower_with_two_defenders() {
|
|
for (seat, before) in ONE_DEFENDER_OPEN {
|
|
for (depth, old) in OPEN_DEPTHS.iter().zip(before) {
|
|
let now = width(&open_spot(seat, *depth).open);
|
|
assert!(now <= old - SHRINK, "{} {depth}bb: {now} vs one-defender {old}", seat.label());
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn both_blinds_play_and_the_overcall_is_tighter_than_the_call() {
|
|
let aa = id("AA");
|
|
for s in PUSH_FOLD.iter().filter(|s| s.seat != Seat::SmallBlind) {
|
|
let tag = format!("{} {}bb", s.seat.label(), s.depth_bb);
|
|
assert_eq!((s.sb_call[aa], s.bb_overcall[aa]), (1000, 1000), "{tag}");
|
|
assert!(width(&s.bb_overcall) <= width(&s.call) + WIDTH_SLACK, "{tag}: overcall vs call");
|
|
assert!(width(&s.sb_call) <= width(&s.call) + WIDTH_SLACK, "{tag}: SB calls tighter than the BB");
|
|
}
|
|
for s in OPEN.iter().filter(|s| s.seat != Seat::SmallBlind) {
|
|
let tag = format!("{} {}bb", s.seat.label(), s.depth_bb);
|
|
assert_eq!(s.sb_defend[aa][0] + s.sb_defend[aa][1], 1000, "{tag}: AA never folds in the SB");
|
|
assert_eq!(s.vs_sb_three_bet[aa][0] + s.vs_sb_three_bet[aa][1], 1000, "{tag}");
|
|
assert!(s.sb_defend.iter().chain(s.vs_sb_three_bet.iter()).all(|[c, r]| c + r <= 1000));
|
|
assert!(s.bb_overcall.iter().chain(s.sb_vs_jam.iter()).all(|f| *f <= 1000));
|
|
}
|
|
// The small blind as first actor has no small-blind rows.
|
|
for s in OPEN.iter().filter(|s| s.seat == Seat::SmallBlind) {
|
|
assert!(s.sb_defend.iter().all(|r| *r == [0, 0]) && s.bb_overcall.iter().all(|f| *f == 0));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_tables_hold_only_deck_classes_and_look_like_poker() {
|
|
use rechner::cfr::hand_class::class_exists;
|
|
use rechner::preflop::generated_charts_short as short;
|
|
use rechner::variant::{rules, Variant};
|
|
let deck = rules(Variant::ShortDeck).deck;
|
|
let missing: Vec<usize> = (0..CLASS_COUNT).filter(|c| !class_exists(deck, *c)).collect();
|
|
assert_eq!(missing.len(), 169 - 81);
|
|
let aa = id("AA");
|
|
for s in short::PUSH_FOLD.iter() {
|
|
assert!(missing.iter().all(|c| s.push[*c] == 0 && s.call[*c] == 0 && s.sb_call[*c] == 0));
|
|
assert_eq!((s.push[aa], s.call[aa]), (1000, 1000));
|
|
}
|
|
for s in short::OPEN.iter() {
|
|
assert!(missing.iter().all(|c| s.open[*c] == 0 && s.defend[*c] == [0, 0]));
|
|
assert_eq!(s.open[aa], 1000);
|
|
assert!(s.meta.exploitability_micro_bb < 10_000);
|
|
}
|
|
// Later seats open wider; shorter stacks jam wider.
|
|
let open = |seat: Seat| width(&short::OPEN.iter().find(|s| s.seat == seat && s.depth_bb == 100).expect("spot").open);
|
|
assert!(open(Seat::Early) <= open(Seat::Cutoff) && open(Seat::Cutoff) <= open(Seat::Button));
|
|
let push = |depth: u8| width(&short::PUSH_FOLD.iter().find(|s| s.seat == Seat::Button && s.depth_bb == depth).expect("spot").push);
|
|
assert!(push(5) >= push(10) && push(10) >= push(25));
|
|
}
|