- exploit::fold_chance: documented foldToBet -> P(fold) map by bet size, per villain - engine: two-branch EV for every raise (fold branch, called branch vs calling range) - semibluffs first, pure bluffs heads-up above a fold and EV threshold - betting ranges keep a bluff share (size, street, style or new profile.aggression) - guards: no bluffs vs never-folders, no bluff catch vs ranges without bluffs - steal width in unopened pots from how often the blinds fold - combo-list sampling for narrow two-card ranges Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
157 lines
5.2 KiB
Rust
157 lines
5.2 KiB
Rust
mod range_model_fixture;
|
|
|
|
use pokerfreak::exploit::profile::Profile;
|
|
use pokerfreak::exploit::range_model::range_spec;
|
|
use pokerfreak::game::{ActionRecord, SeenAction, Street, Villain};
|
|
use pokerfreak::rng::Rng;
|
|
use range_model_fixture::*;
|
|
|
|
const FLOP: Street = Street::Flop;
|
|
|
|
#[test]
|
|
fn unknown_seats_are_ignored() {
|
|
let s = spot(
|
|
3,
|
|
hand(vec![pre(99, SeenAction::Raise), post(FLOP, 77, SeenAction::Bet)]),
|
|
None,
|
|
);
|
|
for seat in [1u8, 2, 3, 99, 200] {
|
|
assert!(well_formed(&spec(&s, seat), 3));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn actions_out_of_order_stay_well_formed() {
|
|
let history = vec![
|
|
post(FLOP, CUTOFF, SeenAction::Bet),
|
|
pre(CUTOFF, SeenAction::Raise),
|
|
post(Street::River, CUTOFF, SeenAction::Raise),
|
|
pre(CUTOFF, SeenAction::Fold),
|
|
pre(CUTOFF, SeenAction::PostBigBlind),
|
|
post(Street::Turn, CUTOFF, SeenAction::Call),
|
|
pre(CUTOFF, SeenAction::Check),
|
|
];
|
|
for len in [0usize, 3, 4, 5] {
|
|
let s = spot(len, history.clone(), None);
|
|
assert!(well_formed(&spec(&s, CUTOFF), len), "board {len}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn board_and_street_that_disagree_stay_well_formed() {
|
|
let mut s = spot(3, hand(vec![post(FLOP, CUTOFF, SeenAction::Bet)]), None);
|
|
s.board.clear(); // flop street, no board cards
|
|
let r = spec(&s, CUTOFF);
|
|
assert!(well_formed(&r, 0));
|
|
assert!(r.continues.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn hero_and_duplicate_blinds_are_harmless() {
|
|
let history = vec![
|
|
pre(HERO, SeenAction::PostBigBlind),
|
|
pre(HERO, SeenAction::PostSmallBlind),
|
|
pre(BIG_BLIND, SeenAction::PostBigBlind),
|
|
pre(BIG_BLIND, SeenAction::PostBigBlind),
|
|
];
|
|
let s = spot(0, history, None);
|
|
for seat in 0u8..8 {
|
|
assert!(well_formed(&spec(&s, seat), 0));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn nonsense_amounts_and_table_sizes_stay_well_formed() {
|
|
for amount in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, -5.0, 0.0, 1e300] {
|
|
for seats in [0u8, 1, 2, 11, 255] {
|
|
let history = vec![
|
|
at(Street::Preflop, CUTOFF, SeenAction::PostBigBlind, Some(amount)),
|
|
at(Street::Preflop, MIDDLE, SeenAction::Raise, Some(amount)),
|
|
at(Street::Preflop, CUTOFF, SeenAction::Call, Some(amount)),
|
|
at(FLOP, CUTOFF, SeenAction::Bet, Some(amount)),
|
|
at(FLOP, MIDDLE, SeenAction::Raise, Some(amount)),
|
|
at(FLOP, CUTOFF, SeenAction::Call, Some(amount)),
|
|
];
|
|
let mut s = spot(3, history, None);
|
|
s.seats = seats;
|
|
s.big_blind = amount;
|
|
s.pot = amount;
|
|
for seat in [MIDDLE, CUTOFF] {
|
|
assert!(well_formed(&spec(&s, seat), 3), "amount {amount} seats {seats}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn pick<T: Copy>(rng: Rng, items: &[T]) -> (T, Rng) {
|
|
let (i, rng) = rng.below(items.len() as u64);
|
|
(items[i as usize], rng)
|
|
}
|
|
|
|
fn random_record(rng: Rng) -> (ActionRecord, Rng) {
|
|
let (street, rng) = pick(rng, &Street::ALL);
|
|
let (seat, rng) = rng.below(12);
|
|
let (action, rng) = pick(rng, &SeenAction::ALL);
|
|
let (present, rng) = rng.below(4);
|
|
let (unit, rng) = rng.unit();
|
|
let (odd, rng) = rng.below(20);
|
|
let amount = match (present, odd) {
|
|
(0, _) => None,
|
|
(_, 0) => Some(f64::NAN),
|
|
(_, 1) => Some(-unit),
|
|
_ => Some(unit * 60.0),
|
|
};
|
|
(ActionRecord { street, seat: seat as u8, action, amount }, rng)
|
|
}
|
|
|
|
fn random_frequency(rng: Rng) -> (Option<f64>, Rng) {
|
|
let (kind, rng) = rng.below(8);
|
|
let (unit, rng) = rng.unit();
|
|
let value = match kind {
|
|
0 | 1 => None,
|
|
2 => Some(f64::NAN),
|
|
3 => Some(unit * 3.0 - 1.0),
|
|
_ => Some(unit),
|
|
};
|
|
(value, rng)
|
|
}
|
|
|
|
#[test]
|
|
fn property_random_histories_always_give_a_well_formed_spec() {
|
|
let mut rng = Rng::seeded(0xBADC0FFEE);
|
|
for case in 0..4000 {
|
|
let (len, r) = rng.below(12);
|
|
rng = r;
|
|
let mut history = Vec::new();
|
|
for _ in 0..len {
|
|
let (rec, r) = random_record(rng);
|
|
rng = r;
|
|
history.push(rec);
|
|
}
|
|
let (board, r) = pick(rng, &[0usize, 3, 4, 5]);
|
|
rng = r;
|
|
let (vpip, r) = random_frequency(rng);
|
|
let (pfr, r) = random_frequency(r);
|
|
let (fold, r) = random_frequency(r);
|
|
rng = r;
|
|
let (seats, r) = rng.below(13);
|
|
rng = r;
|
|
let (button, r) = rng.below(14);
|
|
rng = r;
|
|
let (seat, r) = rng.below(12);
|
|
rng = r;
|
|
let mut s = spot(board, history, Some(Profile { vpip, pfr, fold_to_bet: fold, aggression: None }));
|
|
s.seats = seats as u8;
|
|
s.button_seat = if button == 13 { None } else { Some(button as u8) };
|
|
let v = Villain { seat: seat as u8, stack: 50.0, folded: false, profile: s.villains[0].profile };
|
|
let r = range_spec(&s, &v);
|
|
assert!(well_formed(&r, board), "case {case}: {r:?} for {s:?}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn property_spec_is_deterministic() {
|
|
let s = spot(4, hand(vec![pre(CUTOFF, SeenAction::Raise), post(Street::Turn, CUTOFF, SeenAction::Bet)]), None);
|
|
assert_eq!(spec(&s, CUTOFF), spec(&s, CUTOFF));
|
|
}
|