Files
pokerfreak/src/preflop/position.rs
T
mmintelandClaude Opus 5.5 9a9c6c946d Range narrowing from action history, position from inferred button
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>
2026-10-28 12:41:03 +01:00

77 lines
2.6 KiB
Rust

//! Seat position relative to the button.
/// Where hero sits. Offsets clockwise from the button: 0 = button, 1 = small blind,
/// 2 = big blind, then under-the-gun onwards; the last seat before the button is the cutoff.
/// Heads-up the button *is* the small blind and acts first preflop (`HeadsUpButton`).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Position {
Early,
Middle,
Cutoff,
Button,
SmallBlind,
BigBlind,
HeadsUpButton,
Unknown,
}
impl Position {
pub fn label(self) -> &'static str {
match self {
Position::Early => "EP",
Position::Middle => "MP",
Position::Cutoff => "CO",
Position::Button => "BTN",
Position::SmallBlind => "SB",
Position::BigBlind => "BB",
Position::HeadsUpButton => "BTN/SB",
Position::Unknown => "pos?",
}
}
}
const MIN_SEATS: u8 = 2;
const MAX_SEATS: u8 = 10;
/// Early/Middle split: of the `seats - 4` seats between the big blind and the cutoff, the first
/// half (rounded up) is `Early`, the rest `Middle`. 5 seats: 1E; 6: 1E 1M; 7: 2E 1M; 8: 2E 2M;
/// 9: 3E 2M; 10: 3E 3M. Tables of 3 or 4 seats have no such seats.
///
/// Position of `hero_seat` with the button on `button_seat`. Seat numbers may be 0- or
/// 1-based (only their difference matters); `Unknown` without a button, with fewer
/// than 2 or more than 10 seats, or with a seat number above `seats`.
pub fn position(seats: u8, hero_seat: u8, button_seat: Option<u8>) -> Position {
match button_seat {
Some(button)
if (MIN_SEATS..=MAX_SEATS).contains(&seats)
&& hero_seat <= seats
&& button <= seats =>
{
let offset = (hero_seat as i32 - button as i32).rem_euclid(seats as i32) as u8;
from_offset(seats, offset)
}
_ => Position::Unknown,
}
}
fn from_offset(seats: u8, offset: u8) -> Position {
match (seats, offset) {
(2, 0) => Position::HeadsUpButton,
(2, _) => Position::BigBlind,
(_, 0) => Position::Button,
(_, 1) => Position::SmallBlind,
(_, 2) => Position::BigBlind,
(_, o) if o == seats - 1 => Position::Cutoff,
(_, o) => {
// Seats between the big blind and the cutoff: the later half is "middle".
let before_cutoff = seats - 4;
let middle = before_cutoff / 2;
if o - 3 < before_cutoff - middle {
Position::Early
} else {
Position::Middle
}
}
}
}