Wire: optional history decoding. exploit::range_model: role band + postflop continuations. preflop::button / seat_position: button inference from blinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
5.5 KiB
Rust
144 lines
5.5 KiB
Rust
mod position_fixture;
|
|
|
|
use pokerfreak::game::{SeenAction, Spot, Street};
|
|
use pokerfreak::preflop::button::button_seat;
|
|
use position_fixture::{post_bb, post_sb, rec, spot};
|
|
|
|
fn with_button(s: Spot, button: Option<u8>) -> Spot {
|
|
Spot { button_seat: button, ..s }
|
|
}
|
|
|
|
#[test]
|
|
fn explicit_button_wins_over_history() {
|
|
let s = with_button(spot(6, 0, &[1, 2], vec![post_sb(4), post_bb(5)]), Some(2));
|
|
assert_eq!(button_seat(&s), Some(2));
|
|
}
|
|
|
|
#[test]
|
|
fn nothing_to_infer_from_is_none() {
|
|
assert_eq!(button_seat(&spot(6, 0, &[1, 2], vec![])), None);
|
|
assert_eq!(button_seat(&spot(6, 0, &[1, 2], vec![rec(3, SeenAction::Raise)])), None);
|
|
}
|
|
|
|
#[test]
|
|
fn button_is_one_before_the_small_blind() {
|
|
// 0-based, hero seat 0 pins the numbering.
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_sb(4)])), Some(3));
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_sb(1)])), Some(0));
|
|
// 1-based, seat 6 is present.
|
|
assert_eq!(button_seat(&spot(6, 6, &[], vec![post_sb(4)])), Some(3));
|
|
}
|
|
|
|
#[test]
|
|
fn small_blind_in_the_first_seat_wraps_to_the_last() {
|
|
assert_eq!(button_seat(&spot(6, 3, &[5], vec![post_sb(0)])), Some(5)); // 0-based
|
|
assert_eq!(button_seat(&spot(6, 3, &[6], vec![post_sb(1)])), Some(6)); // 1-based
|
|
}
|
|
|
|
#[test]
|
|
fn numbering_base_comes_from_every_seat_in_play() {
|
|
// Seat 0 only appears as a villain.
|
|
assert_eq!(button_seat(&spot(6, 3, &[0], vec![post_sb(1)])), Some(0));
|
|
// Seat 6 only appears in the history.
|
|
assert_eq!(
|
|
button_seat(&spot(6, 3, &[], vec![post_sb(1), rec(6, SeenAction::Fold)])),
|
|
Some(6)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn ambiguous_numbering_with_a_wrap_is_unknown() {
|
|
// Small blind on seat 1, nobody on seat 0 or 6: button is 0 (0-based) or 6 (1-based).
|
|
assert_eq!(button_seat(&spot(6, 3, &[2], vec![post_sb(1)])), None);
|
|
}
|
|
|
|
#[test]
|
|
fn ambiguous_numbering_without_a_wrap_is_fine() {
|
|
assert_eq!(button_seat(&spot(6, 3, &[2], vec![post_sb(4)])), Some(3));
|
|
}
|
|
|
|
#[test]
|
|
fn heads_up_the_small_blind_is_the_button() {
|
|
assert_eq!(button_seat(&spot(2, 0, &[1], vec![post_sb(0), post_bb(1)])), Some(0));
|
|
assert_eq!(button_seat(&spot(2, 1, &[2], vec![post_sb(1), post_bb(2)])), Some(1));
|
|
assert_eq!(button_seat(&spot(2, 1, &[0], vec![post_sb(1)])), Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn only_the_big_blind_known_puts_the_button_two_before() {
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_bb(5)])), Some(3));
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_bb(1)])), Some(5)); // wraps, 0-based
|
|
assert_eq!(button_seat(&spot(6, 6, &[], vec![post_bb(1)])), Some(5)); // wraps, 1-based
|
|
assert_eq!(button_seat(&spot(9, 0, &[], vec![post_bb(2)])), Some(0));
|
|
}
|
|
|
|
#[test]
|
|
fn heads_up_with_only_the_big_blind_the_other_seat_is_the_button() {
|
|
assert_eq!(button_seat(&spot(2, 0, &[1], vec![post_bb(1)])), Some(0));
|
|
assert_eq!(button_seat(&spot(2, 0, &[1], vec![post_bb(0)])), Some(1));
|
|
assert_eq!(button_seat(&spot(2, 1, &[2], vec![post_bb(1)])), Some(2));
|
|
assert_eq!(button_seat(&spot(2, 1, &[2], vec![post_bb(2)])), Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn both_blinds_that_agree_give_the_same_button() {
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_sb(4), post_bb(5)])), Some(3));
|
|
}
|
|
|
|
#[test]
|
|
fn conflicting_blinds_trust_the_small_blind() {
|
|
// Big blind two seats after the small blind: a dead seat between them.
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_sb(2), post_bb(4)])), Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn only_preflop_posts_count() {
|
|
let mut late = post_sb(4);
|
|
late.street = Street::Flop;
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![late])), None);
|
|
}
|
|
|
|
#[test]
|
|
fn the_first_post_of_each_kind_counts() {
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_sb(4), post_sb(2)])), Some(3));
|
|
}
|
|
|
|
#[test]
|
|
fn absurd_inputs_are_none() {
|
|
assert_eq!(button_seat(&spot(1, 0, &[], vec![post_sb(0)])), None);
|
|
assert_eq!(button_seat(&spot(11, 0, &[], vec![post_sb(4)])), None);
|
|
assert_eq!(button_seat(&spot(0, 0, &[], vec![post_sb(4)])), None);
|
|
assert_eq!(button_seat(&spot(6, 0, &[], vec![post_sb(9)])), None); // seat beyond table
|
|
assert_eq!(button_seat(&spot(6, 0, &[6], vec![post_sb(4)])), None); // both seat 0 and seat 6
|
|
assert_eq!(button_seat(&spot(6, 200, &[], vec![post_sb(4)])), None);
|
|
}
|
|
|
|
#[test]
|
|
fn inferred_button_agrees_with_every_explicit_layout() {
|
|
// Every table size and numbering, the button anywhere: derive the blinds, then check
|
|
// the inference returns the button. The edge seats are added as villains so that the
|
|
// numbering base is always visible.
|
|
for seats in 3u8..=10 {
|
|
for base in 0u8..=1 {
|
|
for button in base..base + seats {
|
|
let sb = base + (button - base + 1) % seats;
|
|
let bb = base + (button - base + 2) % seats;
|
|
let edges = [base, base + seats - 1];
|
|
let s = spot(seats, button, &edges, vec![post_sb(sb), post_bb(bb)]);
|
|
assert_eq!(button_seat(&s), Some(button), "seats {seats} base {base} button {button}");
|
|
let only_bb = spot(seats, button, &edges, vec![post_bb(bb)]);
|
|
assert_eq!(button_seat(&only_bb), Some(button), "bb only, seats {seats} base {base}");
|
|
}
|
|
}
|
|
}
|
|
for base in 0u8..=1 {
|
|
for button in base..base + 2 {
|
|
let other = if button == base { base + 1 } else { base };
|
|
let hu = spot(2, button, &[other], vec![post_sb(button), post_bb(other)]);
|
|
assert_eq!(button_seat(&hu), Some(button));
|
|
let only_bb = spot(2, button, &[other], vec![post_bb(other)]);
|
|
assert_eq!(button_seat(&only_bb), Some(button));
|
|
}
|
|
}
|
|
}
|