Files
pokerfreak/tests/range_model_postflop.rs
T
mmintel 04d5251acf Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete
Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
2026-11-01 23:37:11 +01:00

282 lines
9.2 KiB
Rust

mod range_model_fixture;
use rechner::game::SeenAction::{AllIn, Bet, Call, Check, Fold, Raise};
use rechner::game::{ActionRecord, SeenAction, Street};
use rechner::read::made::Made;
use range_model_fixture::*;
const FLOP: Street = Street::Flop;
const TURN: Street = Street::Turn;
const RIVER: Street = Street::River;
/// Cutoff opens, everybody else folds except the big blind: no amounts, so no size effect.
fn preflop() -> Vec<ActionRecord> {
hand(vec![pre(CUTOFF, Raise), pre(BIG_BLIND, Call)])
}
fn with(rest: Vec<ActionRecord>) -> Vec<ActionRecord> {
[preflop(), rest].concat()
}
fn only(board_len: usize, rest: Vec<ActionRecord>) -> rechner::exploit::range_spec::RangeSpec {
let s = spot(board_len, with(rest), None);
let r = spec(&s, CUTOFF);
assert!(well_formed(&r, board_len), "{r:?}");
r
}
#[test]
fn checks_and_calls_add_no_continuation() {
let r = only(
5,
vec![
post(FLOP, CUTOFF, Check),
post(FLOP, CUTOFF, Call),
post(TURN, CUTOFF, Check),
post(RIVER, CUTOFF, Call),
post(RIVER, CUTOFF, Fold),
],
);
assert!(r.continues.is_empty(), "{r:?}");
}
#[test]
fn flop_bet_keeps_middle_pair_and_draws() {
let c = continuation(&only(3, vec![post(FLOP, CUTOFF, Bet)]), 3).unwrap();
assert_eq!((c.min_made, c.draws_continue), (Made::MiddlePair, true));
}
#[test]
fn flop_raise_keeps_top_pair_good_kicker_and_draws() {
let c = continuation(&only(3, vec![post(FLOP, CUTOFF, Raise)]), 3).unwrap();
assert_eq!((c.min_made, c.draws_continue), (Made::TopPairGoodKicker, true));
}
#[test]
fn turn_bet_and_raise() {
let bet = continuation(&only(4, vec![post(TURN, CUTOFF, Bet)]), 4).unwrap();
assert_eq!((bet.min_made, bet.draws_continue), (Made::TopPairWeakKicker, true));
let raise = continuation(&only(4, vec![post(TURN, CUTOFF, Raise)]), 4).unwrap();
assert_eq!((raise.min_made, raise.draws_continue), (Made::Overpair, true));
}
#[test]
fn river_bet_and_raise_keep_only_made_hands() {
let bet = continuation(&only(5, vec![post(RIVER, CUTOFF, Bet)]), 5).unwrap();
assert_eq!((bet.min_made, bet.draws_continue), (Made::TopPairGoodKicker, false));
let raise = continuation(&only(5, vec![post(RIVER, CUTOFF, Raise)]), 5).unwrap();
assert_eq!((raise.min_made, raise.draws_continue), (Made::TwoPair, false));
}
#[test]
fn all_in_counts_as_a_raise() {
for (len, street) in [(3, FLOP), (4, TURN), (5, RIVER)] {
let jam = continuation(&only(len, vec![post(street, CUTOFF, AllIn)]), len).unwrap();
let raise = continuation(&only(len, vec![post(street, CUTOFF, Raise)]), len).unwrap();
assert_eq!(jam, raise);
}
}
#[test]
fn later_streets_are_stricter_for_the_same_action() {
for action in [Bet, Raise, AllIn] {
let mins: Vec<Made> = [(3, FLOP), (4, TURN), (5, RIVER)]
.iter()
.map(|(len, street)| {
continuation(&only(*len, vec![post(*street, CUTOFF, action)]), *len).unwrap().min_made
})
.collect();
assert!(mins[0] <= mins[1] && mins[1] <= mins[2] && mins[0] < mins[2], "{action:?} {mins:?}");
}
}
#[test]
fn a_raise_is_stricter_than_a_bet_on_every_street() {
for (len, street) in [(3, FLOP), (4, TURN), (5, RIVER)] {
let bet = continuation(&only(len, vec![post(street, CUTOFF, Bet)]), len).unwrap();
let raise = continuation(&only(len, vec![post(street, CUTOFF, Raise)]), len).unwrap();
assert!(raise.min_made > bet.min_made, "street {street:?}");
}
}
#[test]
fn every_street_the_villain_bet_gets_an_entry_sorted_by_board_length() {
let r = only(
5,
vec![
post(RIVER, CUTOFF, Bet),
post(FLOP, CUTOFF, Bet),
post(TURN, CUTOFF, Bet),
],
);
let lens: Vec<usize> = r.continues.iter().map(|c| c.board_len).collect();
assert_eq!(lens, vec![3, 4, 5]);
}
#[test]
fn streets_that_were_not_dealt_yet_are_dropped() {
let r = only(3, vec![post(FLOP, CUTOFF, Bet), post(TURN, CUTOFF, Bet), post(RIVER, CUTOFF, Bet)]);
assert_eq!(r.continues.len(), 1);
assert_eq!(r.continues[0].board_len, 3);
}
#[test]
fn bet_followed_by_a_raise_on_the_same_street_counts_as_the_raise() {
let r = only(3, vec![post(FLOP, CUTOFF, Bet), post(FLOP, CUTOFF, Raise)]);
assert_eq!(r.continues.len(), 1);
assert_eq!(r.continues[0].min_made, Made::TopPairGoodKicker);
}
#[test]
fn other_players_aggression_does_not_narrow_this_villain() {
let r = only(3, vec![post(FLOP, BIG_BLIND, Bet), post(FLOP, CUTOFF, Call)]);
assert!(r.continues.is_empty());
}
#[test]
fn preflop_spot_has_no_continuations_even_with_later_records() {
let s = spot(0, with(vec![post(FLOP, CUTOFF, Bet)]), None);
assert!(spec(&s, CUTOFF).continues.is_empty());
}
// --- bet size relative to the pot -------------------------------------------------
/// Posts 0.5 + 1, cutoff raises to 3, small blind folds, big blind calls: pot 6.5.
fn sized_preflop() -> Vec<ActionRecord> {
hand(vec![
pre_amt(CUTOFF, Raise, 3.0),
pre(SMALL_BLIND, Fold),
pre_amt(BIG_BLIND, Call, 3.0),
])
}
fn bet_of(amount: f64, action: SeenAction) -> Made {
let history = [sized_preflop(), vec![at(FLOP, CUTOFF, action, Some(amount))]].concat();
let s = spot(3, history, None);
continuation(&spec(&s, CUTOFF), 3).unwrap().min_made
}
#[test]
fn bigger_bets_are_stricter_and_smaller_ones_looser() {
let small = bet_of(2.0, Bet); // 0.31 pot
let normal = bet_of(4.5, Bet); // 0.69 pot
let pot = bet_of(6.5, Bet); // 1.0 pot
let overbet = bet_of(13.0, Bet); // 2.0 pots
assert_eq!(small, Made::BottomPair);
assert_eq!(normal, Made::MiddlePair);
assert_eq!(pot, Made::TopPairWeakKicker);
assert_eq!(overbet, Made::TopPairGoodKicker);
}
#[test]
fn size_effect_is_monotone() {
for action in [Bet, Raise] {
let mins: Vec<Made> = [0.5, 1.0, 2.0, 3.25, 4.5, 6.5, 9.0, 13.0, 30.0, 300.0]
.iter()
.map(|a| bet_of(*a, action))
.collect();
assert!(mins.windows(2).all(|w| w[0] <= w[1]), "{action:?} {mins:?}");
}
}
#[test]
fn unknown_bet_amount_or_unknown_pot_means_no_size_effect() {
let base = continuation(&only(3, vec![post(FLOP, CUTOFF, Bet)]), 3).unwrap();
assert_eq!(base.min_made, Made::MiddlePair);
// A preflop call without an amount makes the pot unknowable.
let history = hand(vec![
pre_amt(CUTOFF, Raise, 3.0),
pre(BIG_BLIND, Call),
at(FLOP, CUTOFF, Bet, Some(13.0)),
]);
let s = spot(3, history, None);
assert_eq!(continuation(&spec(&s, CUTOFF), 3).unwrap().min_made, Made::MiddlePair);
}
#[test]
fn later_streets_use_the_pot_built_so_far() {
// Flop: bet 6.5 called (pot 6.5 -> 19.5). Turn bet 6.5 is a third of that pot: smaller.
let history = [
sized_preflop(),
vec![
at(FLOP, CUTOFF, Bet, Some(6.5)),
at(FLOP, BIG_BLIND, Call, Some(6.5)),
at(TURN, CUTOFF, Bet, Some(6.5)),
],
]
.concat();
let s = spot(4, history, None);
let r = spec(&s, CUTOFF);
assert_eq!(continuation(&r, 3).unwrap().min_made, Made::TopPairWeakKicker);
assert_eq!(continuation(&r, 4).unwrap().min_made, Made::MiddlePair);
}
// --- calling a big bet -----------------------------------------------------------
fn calling(bet: Option<f64>, call_street: Street, len: usize) -> rechner::exploit::range_spec::RangeSpec {
let history = [
sized_preflop(),
vec![
at(call_street, BIG_BLIND, Bet, bet),
at(call_street, CUTOFF, Call, bet),
],
]
.concat();
let s = spot(len, history, None);
spec(&s, CUTOFF)
}
#[test]
fn calling_a_big_bet_leaves_a_mild_floor() {
let r = calling(Some(6.5), FLOP, 3);
let c = continuation(&r, 3).expect("floor");
assert_eq!((c.min_made, c.draws_continue), (Made::BottomPair, true));
}
#[test]
fn calling_a_big_river_bet_wants_a_made_hand() {
let history = [
sized_preflop(),
vec![
at(FLOP, BIG_BLIND, Check, None),
at(FLOP, CUTOFF, Check, None),
at(RIVER, BIG_BLIND, Bet, Some(6.5)),
at(RIVER, CUTOFF, Call, Some(6.5)),
],
]
.concat();
let s = spot(5, history, None);
let c = continuation(&spec(&s, CUTOFF), 5).expect("floor");
assert_eq!((c.min_made, c.draws_continue), (Made::MiddlePair, false));
}
#[test]
fn calling_a_small_or_unsized_bet_adds_nothing() {
assert!(calling(Some(2.0), FLOP, 3).continues.is_empty());
assert!(calling(None, FLOP, 3).continues.is_empty());
}
#[test]
fn the_call_floor_is_always_looser_than_the_bet_floor() {
let floor = continuation(&calling(Some(6.5), FLOP, 3), 3).unwrap().min_made;
let bet = continuation(&only(3, vec![post(FLOP, CUTOFF, Bet)]), 3).unwrap().min_made;
assert!(floor < bet);
}
#[test]
fn bet_and_call_on_one_street_keep_the_stricter_floor() {
let history = [
sized_preflop(),
vec![
at(FLOP, CUTOFF, Bet, Some(6.5)),
at(FLOP, BIG_BLIND, Raise, Some(20.0)),
at(FLOP, CUTOFF, Call, Some(20.0)),
],
]
.concat();
let s = spot(3, history, None);
let r = spec(&s, CUTOFF);
assert_eq!(r.continues.len(), 1);
assert_eq!(r.continues[0].min_made, Made::TopPairWeakKicker);
}