diff --git a/src/preflop/cfr_advice.rs b/src/preflop/cfr_advice.rs index 85195dd8..96f9dd82 100644 --- a/src/preflop/cfr_advice.rs +++ b/src/preflop/cfr_advice.rs @@ -33,7 +33,13 @@ //! 20 to 100 bb, callers, 4-bets, a lineup with a gap among the last `k` places, an unknown //! position. Postflop never reaches this module. //! -//! Only for 6-max tables (the size the generator modelled) and the variants with tables (NLHE, +//! **Short tables.** With fewer than six players the positions are those of the six-max table +//! from the cutoff (or earlier) on, so a lineup behind the attacker is a six-max lineup: below six +//! seats only the multi-defender tables answer, plus the blind battle (small blind first in, big +//! blind against the small blind's open), which is the one-defender game at any table size. The +//! one-defender tables of the other seats assume six-max players behind and stay out. +//! +//! Only up to 6-max tables (the size the generator modelled) and the variants with tables (NLHE, //! AOF, short deck). Everything else (other variants and table sizes, callers other than the //! small blind, 4-bets, 3-bets from players that are not in the blinds, unknown openers) has no //! answer here and stays with the heuristic charts. The action is the most frequent one; ties keep the @@ -295,8 +301,21 @@ fn multi(spot: &Spot, situation: Situation, depth: f64) -> Option<(Node, usize)> } } +/// Small blind first in, or the big blind against the small blind's open: one opponent behind, +/// the same game at every table size. +fn blind_battle(spot: &Spot, situation: Situation, pos: Position) -> bool { + match (situation, pos) { + (Situation::Unopened, Position::SmallBlind) => true, + (Situation::FacingOpen, Position::BigBlind) => { + sole_raiser(spot).is_some_and(|s| seat_position(spot, s) == Position::SmallBlind) + && callers(spot) == Callers::None + } + _ => false, + } +} + pub fn cfr_advice(spot: &Spot, situation: Situation, pos: Position, depth: f64) -> Option { - if !has_charts(spot.variant) || spot.seats != CHART_SEATS { + if !has_charts(spot.variant) || spot.seats > CHART_SEATS { return None; } let class = match spot.hero_cards.as_slice() { @@ -305,6 +324,7 @@ pub fn cfr_advice(spot: &Spot, situation: Situation, pos: Position, depth: f64) }; let ((read, aggressive, table, widen_to), defenders) = match multi(spot, situation, depth) { Some((node, k)) => (node, Some(k)), + None if spot.seats < CHART_SEATS && !blind_battle(spot, situation, pos) => return None, None => (node(spot, situation, pos, depth)?, None), }; let frequencies = read(class)?; diff --git a/tests/preflop_multi_advice.rs b/tests/preflop_multi_advice.rs index 3c58caed..caa54fdb 100644 --- a/tests/preflop_multi_advice.rs +++ b/tests/preflop_multi_advice.rs @@ -157,3 +157,54 @@ fn postflop_never_reads_the_preflop_tables() { 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); +}