#![allow(dead_code)] //! Builders for range-model tests. Table: 6 seats, 0-based, button on seat 3: //! seat 3 BTN, 4 SB, 5 BB, 0 UTG (early), 1 MP (middle), 2 CO. Hero sits on seat 0. use rechner::card::Card; use rechner::exploit::profile::Profile; use rechner::exploit::range_spec::{Continuation, RangeSpec}; use rechner::game::{ActionKind, ActionRecord, SeenAction, Spot, Street, Villain}; use rechner::variant::Variant; pub const HERO: u8 = 0; pub const MIDDLE: u8 = 1; pub const CUTOFF: u8 = 2; pub const BUTTON: u8 = 3; pub const SMALL_BLIND: u8 = 4; pub const BIG_BLIND: u8 = 5; pub fn at(street: Street, seat: u8, action: SeenAction, amount: Option) -> ActionRecord { ActionRecord { street, seat, action, amount } } pub fn pre(seat: u8, action: SeenAction) -> ActionRecord { at(Street::Preflop, seat, action, None) } pub fn pre_amt(seat: u8, action: SeenAction, amount: f64) -> ActionRecord { at(Street::Preflop, seat, action, Some(amount)) } pub fn post(street: Street, seat: u8, action: SeenAction) -> ActionRecord { at(street, seat, action, None) } pub fn blinds() -> Vec { vec![pre_amt(4, SeenAction::PostSmallBlind, 0.5), pre_amt(5, SeenAction::PostBigBlind, 1.0)] } /// Blinds followed by `rest`. pub fn hand(rest: Vec) -> Vec { [blinds(), rest].concat() } pub fn villain(seat: u8, profile: Option) -> Villain { Villain { seat, stack: 100.0, folded: false, profile } } pub fn profile(vpip: Option, pfr: Option, fold: Option) -> Option { Some(Profile { vpip, pfr, fold_to_bet: fold, aggression: None }) } pub fn vpip(value: f64) -> Option { profile(Some(value), None, None) } pub fn board_of(len: usize) -> Vec { Card::parse_list(&"Kc 7d 2s 9h 4c"[..len * 3 - usize::from(len > 0)]).unwrap() } fn street_of(len: usize) -> Street { match len { 0 => Street::Preflop, 3 => Street::Flop, 4 => Street::Turn, _ => Street::River, } } /// A spot on the street matching `board_len` with the given history; villains: all but hero. pub fn spot(board_len: usize, history: Vec, profile: Option) -> Spot { Spot { variant: Variant::Nlhe, big_blind: 1.0, seats: 6, hero_seat: HERO, button_seat: Some(3), hero_cards: Card::parse_list("Ah Qd").unwrap(), board: if board_len == 0 { vec![] } else { board_of(board_len) }, street: street_of(board_len), pot: 10.0, to_call: 0.0, hero_stack: 100.0, min_raise_to: None, max_raise_to: None, legal: vec![ActionKind::Check, ActionKind::Raise], allowed_sizes: None, villains: [1u8, 2, 3, 4, 5].iter().map(|s| villain(*s, profile)).collect(), seed: 1, history, } } pub fn spec(spot: &Spot, seat: u8) -> RangeSpec { let v = spot.villains.iter().find(|v| v.seat == seat).cloned().unwrap_or(villain(seat, None)); rechner::exploit::range_model::range_spec(spot, &v) } pub fn width(s: &RangeSpec) -> f64 { s.hi - s.lo } pub fn well_formed(s: &RangeSpec, board_len: usize) -> bool { let sorted = s.continues.windows(2).all(|w| w[0].board_len < w[1].board_len); s.lo.is_finite() && s.hi.is_finite() && s.lo >= 0.0 && s.hi <= 1.0 && s.hi - s.lo >= 0.03 - 1e-12 && sorted && s.continues.iter().all(|c: &Continuation| (3..=5).contains(&c.board_len) && c.board_len <= board_len) } pub fn continuation(s: &RangeSpec, board_len: usize) -> Option { s.continues.iter().find(|c| c.board_len == board_len).copied() }