Files
pokerfreak/tests/preflop_cfr_advice.rs
T
mmintel 04d5251acf Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete
Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
2026-11-01 23:37:11 +01:00

131 lines
5.0 KiB
Rust

//! The CFR tables behind `advise`: which table answers which history (`preflop::cfr_advice`).
//!
//! Six-max, button on seat 3: EP 0, MP 1, CO 2, BTN 3, SB 4, BB 5. Big blind = 1.0.
use rechner::card::Card;
use rechner::exploit::thresholds::Thresholds;
use rechner::game::{ActionKind, ActionRecord, SeenAction, Spot, Street, Villain};
use rechner::preflop::advise::advise;
use rechner::preflop::plan::ChartAction;
use rechner::variant::Variant;
const MIDDLE: u8 = 1;
const SMALL_BLIND: u8 = 4;
const BIG_BLIND: u8 = 5;
fn record(seat: u8, action: SeenAction, amount: Option<f64>) -> ActionRecord {
ActionRecord { street: Street::Preflop, seat, action, amount }
}
fn blinds() -> Vec<ActionRecord> {
vec![record(4, SeenAction::PostSmallBlind, Some(0.5)), record(5, SeenAction::PostBigBlind, Some(1.0))]
}
fn spot(variant: Variant, hole: &str, hero_seat: u8, history: Vec<ActionRecord>, pot: f64, to_call: f64) -> Spot {
Spot {
variant,
big_blind: 1.0,
seats: 6,
hero_seat,
button_seat: Some(3),
hero_cards: Card::parse_list(hole).expect("cards"),
board: vec![],
street: Street::Preflop,
pot,
to_call,
hero_stack: 40.0,
min_raise_to: Some(2.0 * to_call + 1.0),
max_raise_to: Some(40.0),
legal: vec![ActionKind::Fold, ActionKind::Call, ActionKind::Raise],
allowed_sizes: None,
villains: (0..6)
.filter(|s| *s != hero_seat)
.map(|seat| Villain { seat, stack: 40.0, folded: false, profile: None })
.collect(),
seed: 1,
history,
}
}
/// MP opens to 2.5, CO and BTN fold.
fn middle_opens() -> Vec<ActionRecord> {
let mut h = blinds();
h.extend([
record(0, SeenAction::Fold, None),
record(1, SeenAction::Raise, Some(2.5)),
record(2, SeenAction::Fold, None),
record(3, SeenAction::Fold, None),
]);
h
}
fn reason(s: &Spot) -> String {
advise(s, &Thresholds::BASE).reason
}
#[test]
fn the_small_blind_facing_an_open_reads_its_own_table() {
let s = spot(Variant::Nlhe, "Ah Ad", SMALL_BLIND, middle_opens(), 4.0, 2.0);
assert!(reason(&s).contains("CFR SB vs open"), "{}", reason(&s));
assert_eq!(advise(&s, &Thresholds::BASE).action, ChartAction::Raise);
let trash = spot(Variant::Nlhe, "7c 2d", SMALL_BLIND, middle_opens(), 4.0, 2.0);
assert_eq!(advise(&trash, &Thresholds::BASE).action, ChartAction::Fold);
}
#[test]
fn the_big_blind_after_a_small_blind_fold_or_call_reads_different_tables() {
let mut folded = middle_opens();
folded.push(record(4, SeenAction::Fold, None));
let s = spot(Variant::Nlhe, "Kh Qh", BIG_BLIND, folded, 4.0, 1.5);
assert!(reason(&s).contains("CFR vs open "), "{}", reason(&s));
let mut called = middle_opens();
called.push(record(4, SeenAction::Call, Some(2.5)));
let s = spot(Variant::Nlhe, "Kh Qh", BIG_BLIND, called, 6.0, 1.5);
assert!(reason(&s).contains("CFR vs open + SB call"), "{}", reason(&s));
// There is no squeeze in the model: the big blind only folds or calls.
assert!(matches!(advise(&s, &Thresholds::BASE).action, ChartAction::Call | ChartAction::Fold));
}
#[test]
fn the_opener_facing_a_small_blind_three_bet_reads_its_own_table() {
let mut h = middle_opens();
h.extend([record(4, SeenAction::Raise, Some(11.0)), record(5, SeenAction::Fold, None)]);
let s = spot(Variant::Nlhe, "Ah Ad", MIDDLE, h, 14.5, 8.5);
assert!(reason(&s).contains("CFR vs SB 3-bet"), "{}", reason(&s));
assert_eq!(advise(&s, &Thresholds::BASE).action, ChartAction::Jam);
}
#[test]
fn the_small_blind_facing_a_jam_with_the_big_blind_behind_reads_its_own_table() {
let mut h = blinds();
h.extend([
record(0, SeenAction::Fold, None),
record(1, SeenAction::Fold, None),
record(2, SeenAction::AllIn, Some(12.0)),
record(3, SeenAction::Fold, None),
]);
let mut s = spot(Variant::Nlhe, "Ah Ad", SMALL_BLIND, h, 13.5, 11.5);
s.hero_stack = 11.5; // 12 bb minus the posted small blind: the call takes the stack
s.villains.iter_mut().for_each(|v| v.stack = 12.0);
assert!(reason(&s).contains("CFR SB vs jam"), "{}", reason(&s));
assert_eq!(advise(&s, &Thresholds::BASE).action, ChartAction::Call);
}
#[test]
fn short_deck_unopened_pots_use_the_short_deck_tables() {
let s = spot(Variant::ShortDeck, "Ah Ad", 0, blinds(), 1.5, 1.0);
let plan = advise(&s, &Thresholds::BASE);
assert!(plan.reason.contains("CFR open"), "{}", plan.reason);
assert_eq!(plan.action, ChartAction::Raise);
let trash = spot(Variant::ShortDeck, "7c 6d", 0, blinds(), 1.5, 1.0);
assert_eq!(advise(&trash, &Thresholds::BASE).action, ChartAction::Fold);
}
#[test]
fn a_caller_other_than_the_small_blind_leaves_the_tables() {
let mut h = middle_opens();
h[4] = record(2, SeenAction::Call, Some(2.5));
h.push(record(4, SeenAction::Fold, None));
let s = spot(Variant::Nlhe, "Kh Qh", BIG_BLIND, h, 6.5, 1.5);
assert!(!reason(&s).contains("CFR"), "{}", reason(&s));
}