Die Hülle nummeriert jetzt nur die Sitze in der Hand (vorher zählten leere Sitze mit und verschoben die Position). Ein Cutoff am Vierertisch hat dieselbe Gegnerlinie hinter sich wie am Sechsertisch - unter sechs Plätzen antworten deshalb die Mehrgegner-Tabellen und das Blindduell, die Ein-Verteidiger-Tabellen der übrigen Plätze (sie setzen Sechser-Spieler dahinter voraus) bleiben draußen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
211 lines
9.6 KiB
Rust
211 lines
9.6 KiB
Rust
//! The live advice reads the multi-defender tables (`preflop::cfr_advice`, `multi_lookup`): the
|
|
//! table is chosen by how many opponents behind the attacker are still in the hand, and the
|
|
//! recommendation changes with that number. Where the tables do not reach, the old answer stays.
|
|
//!
|
|
//! Six-max, button on seat 3: EP 0, MP 1, CO 2, BTN 3, SB 4, BB 5. Big blind = 1.0. A seat left
|
|
//! out of `present` has nobody sitting there.
|
|
use pokerfreak::card::Card;
|
|
use pokerfreak::engine::decide::decide;
|
|
use pokerfreak::exploit::thresholds::Thresholds;
|
|
use pokerfreak::game::{ActionKind, ActionRecord, SeenAction, Spot, Street, Villain};
|
|
use pokerfreak::preflop::advise::advise;
|
|
use pokerfreak::preflop::plan::{ChartAction, PreflopPlan};
|
|
use pokerfreak::variant::Variant;
|
|
|
|
const EARLY: u8 = 0;
|
|
const BUTTON: u8 = 3;
|
|
|
|
fn record(seat: u8, action: SeenAction, amount: Option<f64>) -> ActionRecord {
|
|
ActionRecord { street: Street::Preflop, seat, action, amount }
|
|
}
|
|
|
|
/// Blinds of the seats that are present, then folds of `folds`.
|
|
fn history(present: &[u8], folds: &[u8]) -> Vec<ActionRecord> {
|
|
let mut h = Vec::new();
|
|
if present.contains(&4) {
|
|
h.push(record(4, SeenAction::PostSmallBlind, Some(0.5)));
|
|
}
|
|
h.push(record(5, SeenAction::PostBigBlind, Some(1.0)));
|
|
h.extend(folds.iter().map(|s| record(*s, SeenAction::Fold, None)));
|
|
h
|
|
}
|
|
|
|
fn spot(hole: &str, hero_seat: u8, present: &[u8], history: Vec<ActionRecord>, to_call: f64, depth: f64) -> Spot {
|
|
let pot = history.iter().filter_map(|r| r.amount).sum();
|
|
Spot {
|
|
variant: Variant::Nlhe,
|
|
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: depth,
|
|
min_raise_to: Some(2.0 * to_call.max(1.0) + 1.0),
|
|
max_raise_to: Some(depth),
|
|
legal: vec![ActionKind::Fold, ActionKind::Call, ActionKind::Raise],
|
|
allowed_sizes: None,
|
|
villains: present
|
|
.iter()
|
|
.filter(|s| **s != hero_seat)
|
|
.map(|seat| Villain { seat: *seat, stack: depth, folded: false, profile: None })
|
|
.collect(),
|
|
seed: 1,
|
|
history,
|
|
}
|
|
}
|
|
|
|
fn plan(s: &Spot) -> PreflopPlan {
|
|
advise(s, &Thresholds::BASE)
|
|
}
|
|
|
|
/// The button first in, with only the big blind behind (the small blind seat is empty) or with
|
|
/// both blinds behind.
|
|
fn button_first_in(hole: &str, with_small_blind: bool) -> Spot {
|
|
let present: Vec<u8> = if with_small_blind { vec![0, 1, 2, 3, 4, 5] } else { vec![0, 1, 2, 3, 5] };
|
|
let h = history(&present, &[0, 1, 2]);
|
|
spot(hole, BUTTON, &present, h, 1.0, 40.0)
|
|
}
|
|
|
|
#[test]
|
|
fn a_second_defender_changes_the_button_open() {
|
|
// Q8o opens against the big blind alone and folds once the small blind sits behind too.
|
|
let one = plan(&button_first_in("Qh 8d", false));
|
|
let two = plan(&button_first_in("Qh 8d", true));
|
|
assert_eq!(one.action, ChartAction::Raise, "{}", one.reason);
|
|
assert_eq!(two.action, ChartAction::Fold, "{}", two.reason);
|
|
assert!(one.reason.contains("CFR open 40bb vs 1 defender"), "{}", one.reason);
|
|
assert!(two.reason.contains("CFR open 40bb vs 2 defenders"), "{}", two.reason);
|
|
// Hands at both ends do not move: aces open, seven-deuce folds.
|
|
for with_small_blind in [false, true] {
|
|
assert_eq!(plan(&button_first_in("Ah Ad", with_small_blind)).action, ChartAction::Raise);
|
|
assert_eq!(plan(&button_first_in("7h 2d", with_small_blind)).action, ChartAction::Fold);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_full_table_opens_tighter_from_early_position() {
|
|
// EP with five players behind reads the four-defender table (MP is the wake field); with
|
|
// only the blinds behind, the two-defender one.
|
|
let full = spot("Kh Td", EARLY, &[0, 1, 2, 3, 4, 5], history(&[0, 1, 2, 3, 4, 5], &[]), 1.0, 40.0);
|
|
let blinds = spot("Kh Td", EARLY, &[0, 4, 5], history(&[0, 4, 5], &[]), 1.0, 40.0);
|
|
let (full, blinds) = (plan(&full), plan(&blinds));
|
|
assert_eq!(blinds.action, ChartAction::Raise, "{}", blinds.reason);
|
|
assert_eq!(full.action, ChartAction::Fold, "{}", full.reason);
|
|
assert!(full.reason.contains("vs 4 defenders"), "{}", full.reason);
|
|
assert!(blinds.reason.contains("vs 2 defenders"), "{}", blinds.reason);
|
|
}
|
|
|
|
#[test]
|
|
fn a_defender_that_is_not_a_blind_now_reads_the_table() {
|
|
// EP opens, MP and CO fold: the button defends with the blinds still behind it.
|
|
let mut h = history(&[0, 1, 2, 3, 4, 5], &[]);
|
|
h.extend([record(0, SeenAction::Raise, Some(2.5)), record(1, SeenAction::Fold, None), record(2, SeenAction::Fold, None)]);
|
|
let s = spot("7h 7d", BUTTON, &[0, 1, 2, 3, 4, 5], h, 2.5, 40.0);
|
|
let p = plan(&s);
|
|
assert!(p.reason.contains("CFR BTN vs open 40bb vs 4 defenders"), "{}", p.reason);
|
|
assert_eq!(p.action, ChartAction::Call, "{}", p.reason);
|
|
}
|
|
|
|
#[test]
|
|
fn where_the_multi_tables_do_not_reach_the_old_answer_stays() {
|
|
let full = [0, 1, 2, 3, 4, 5];
|
|
let unopened = |depth: f64| spot("Kh Td", EARLY, &full, history(&full, &[]), 1.0, depth);
|
|
// Deeper than the grid (100 bb): the old tables, which clamp to 100 bb.
|
|
let deep = plan(&unopened(150.0));
|
|
assert!(deep.reason.contains("CFR open 100bb") || deep.reason.contains("CFR open 150bb"), "{}", deep.reason);
|
|
assert!(!deep.reason.contains("defender"), "{}", deep.reason);
|
|
// Push / fold depth: the push / fold table.
|
|
let short = plan(&unopened(12.0));
|
|
assert!(short.reason.contains("CFR push/fold"), "{}", short.reason);
|
|
assert!(!short.reason.contains("defender"), "{}", short.reason);
|
|
// Between push / fold and the grid (15 to 20 bb): the old open table.
|
|
assert!(!plan(&unopened(18.0)).reason.contains("defender"));
|
|
// Other variants: the short deck keeps its own one table.
|
|
let mut s = unopened(40.0);
|
|
s.variant = Variant::ShortDeck;
|
|
s.hero_cards = Card::parse_list("Ah Ad").expect("cards");
|
|
let p = plan(&s);
|
|
assert!(p.reason.contains("CFR open") && !p.reason.contains("defender"), "{}", p.reason);
|
|
// A spot without villains carries no count: the old two-blind table.
|
|
let mut s = unopened(40.0);
|
|
s.villains.clear();
|
|
let p = plan(&s);
|
|
assert!(p.reason.contains("CFR open 40bb") && !p.reason.contains("defender"), "{}", p.reason);
|
|
// The small blind first in: its own table, already the one-defender game.
|
|
let s = spot("Kh Td", 4, &full, history(&full, &[0, 1, 2, 3]), 0.5, 40.0);
|
|
assert!(!plan(&s).reason.contains("defender"), "{}", plan(&s).reason);
|
|
// A gap among the last places: EP with four players behind but the small blind seat empty
|
|
// is not a modelled lineup (the last four places are CO, BTN, SB, BB).
|
|
let gap = [0, 1, 2, 3, 5];
|
|
let s = spot("Kh Td", EARLY, &gap, history(&gap, &[]), 1.0, 40.0);
|
|
assert!(!plan(&s).reason.contains("defender"), "{}", plan(&s).reason);
|
|
}
|
|
|
|
#[test]
|
|
fn postflop_never_reads_the_preflop_tables() {
|
|
let full = [0, 1, 2, 3, 4, 5];
|
|
let mut s = spot("Kh Td", EARLY, &full, history(&full, &[]), 0.0, 40.0);
|
|
s.street = Street::Flop;
|
|
s.board = Card::parse_list("2c 7d 9s").expect("board");
|
|
s.legal = vec![ActionKind::Check, ActionKind::Raise];
|
|
s.pot = 6.0;
|
|
s.min_raise_to = Some(1.0);
|
|
let d = decide(&s);
|
|
assert!(!format!("{d:?}").contains("CFR"), "{d:?}");
|
|
}
|
|
|
|
|
|
/// The same lineup at a four-handed table: CO 1, BTN 2, SB 3, BB 4 (button on seat 2).
|
|
fn four_handed(hole: &str, hero_seat: u8) -> Spot {
|
|
let mut s = spot(hole, hero_seat, &[1, 2, 3, 4], Vec::new(), 1.0, 40.0);
|
|
s.seats = 4;
|
|
s.button_seat = Some(2);
|
|
s.history = vec![record(3, SeenAction::PostSmallBlind, Some(0.5)), record(4, SeenAction::PostBigBlind, Some(1.0))];
|
|
s.pot = 1.5;
|
|
s
|
|
}
|
|
|
|
#[test]
|
|
fn a_four_handed_cutoff_reads_the_six_max_cutoff_lineup() {
|
|
// Four players: the first to act is the cutoff with three behind - the six-max cutoff after
|
|
// EP and MP folded. Same table, same answer; before, short tables never reached the tables.
|
|
let six = spot("Kd 9c", 2, &[0, 1, 2, 3, 4, 5], history(&[0, 1, 2, 3, 4, 5], &[0, 1]), 1.0, 40.0);
|
|
for hole in ["Kd 9c", "Qh 8d", "7s 6s", "Ac 2d", "Jh 5h"] {
|
|
let mut six = six.clone();
|
|
six.hero_cards = pokerfreak::card::Card::parse_list(hole).expect("cards");
|
|
let (a, b) = (plan(&six), plan(&four_handed(hole, 1)));
|
|
assert_eq!(a.action, b.action, "{hole}: {} / {}", a.reason, b.reason);
|
|
assert!(b.reason.starts_with("CO open, CFR open 40bb vs 3 defenders"), "{}", b.reason);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_short_table_keeps_lineups_and_the_blind_battle_only() {
|
|
// Small blind first in at four-handed: its own one-defender table, as at six-max.
|
|
let mut sb = four_handed("Kd 9c", 3);
|
|
sb.history.push(record(1, SeenAction::Fold, None));
|
|
sb.history.push(record(2, SeenAction::Fold, None));
|
|
sb.to_call = 0.5;
|
|
sb.villains.iter_mut().filter(|v| v.seat <= 2).for_each(|v| v.folded = true);
|
|
let p = plan(&sb);
|
|
assert!(p.reason.contains("CFR"), "{}", p.reason);
|
|
// Button facing the cutoff's open: a lineup (button and both blinds defend).
|
|
let mut btn = four_handed("Kd 9c", 2);
|
|
btn.history.push(record(1, SeenAction::Raise, Some(2.5)));
|
|
btn.to_call = 2.5;
|
|
let p = plan(&btn);
|
|
assert!(p.reason.contains("CFR BTN vs open 40bb vs 3 defenders"), "{}", p.reason);
|
|
// Small blind facing that open with the button calling: no lineup, and the six-max
|
|
// one-defender tables do not apply at four-handed - no CFR answer.
|
|
let mut sb = four_handed("Kd 9c", 3);
|
|
sb.history.push(record(1, SeenAction::Raise, Some(2.5)));
|
|
sb.history.push(record(2, SeenAction::Call, Some(2.5)));
|
|
sb.to_call = 2.0;
|
|
let p = plan(&sb);
|
|
assert!(!p.reason.contains("CFR"), "{}", p.reason);
|
|
}
|