Files
pokerfreak/tests/exploit_range_guess.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

165 lines
4.3 KiB
Rust

use rechner::exploit::profile::Profile;
use rechner::exploit::range_guess::top_fraction;
use rechner::game::{ActionKind, Spot, Street, Villain};
use rechner::variant::Variant;
fn villain(profile: Option<Profile>) -> Villain {
Villain {
seat: 1,
stack: 100.0,
folded: false,
profile,
}
}
fn vpip(value: f64) -> Option<Profile> {
Some(Profile {
vpip: Some(value),
..Profile::default()
})
}
fn spot(street: Street, pot: f64, to_call: f64, villains: Vec<Villain>) -> Spot {
Spot {
variant: Variant::Nlhe,
big_blind: 1.0,
seats: 6,
hero_seat: 0,
button_seat: Some(3),
hero_cards: vec![],
board: vec![],
street,
pot,
to_call,
hero_stack: 100.0,
min_raise_to: None,
max_raise_to: None,
legal: vec![ActionKind::Fold, ActionKind::Call, ActionKind::Raise],
allowed_sizes: None,
villains,
seed: 1,
history: Vec::new(),
}
}
fn guess(street: Street, pot: f64, to_call: f64, profile: Option<Profile>) -> f64 {
let v = villain(profile);
top_fraction(&spot(street, pot, to_call, vec![v.clone()]), &v)
}
#[test]
fn always_in_the_half_open_unit_interval() {
let profiles = [
None,
vpip(0.0),
vpip(1.0),
vpip(f64::NAN),
vpip(5.0),
vpip(-2.0),
];
for street in Street::ALL {
for (pot, to_call) in [
(0.0, 0.0),
(10.0, 0.0),
(10.0, 10.0),
(1.0, 50.0),
(f64::NAN, 3.0),
(-4.0, -1.0),
] {
for p in profiles {
let f = guess(street, pot, to_call, p);
assert!(f > 0.0 && f <= 1.0, "{street:?} {pot} {to_call}: {f}");
}
}
}
}
#[test]
fn unknown_profile_uses_a_documented_default() {
let f = guess(Street::Preflop, 1.5, 0.0, None);
assert!((f - 0.30).abs() < 1e-9, "{f}");
}
#[test]
fn looser_players_hold_wider_ranges() {
let fractions: Vec<f64> = (1..=10)
.map(|i| guess(Street::Flop, 10.0, 0.0, vpip(i as f64 / 10.0)))
.collect();
assert!(fractions.windows(2).all(|w| w[0] <= w[1]), "{fractions:?}");
assert!(fractions[9] > fractions[0]);
}
#[test]
fn bigger_bets_mean_narrower_ranges() {
let fractions: Vec<f64> = [0.0, 2.5, 5.0, 10.0, 20.0]
.iter()
.map(|c| guess(Street::Flop, 10.0, *c, vpip(0.4)))
.collect();
assert!(fractions.windows(2).all(|w| w[0] > w[1]), "{fractions:?}");
}
#[test]
fn later_streets_mean_narrower_ranges() {
let fractions: Vec<f64> = Street::ALL
.iter()
.map(|s| guess(*s, 10.0, 5.0, vpip(0.4)))
.collect();
assert!(fractions.windows(2).all(|w| w[0] > w[1]), "{fractions:?}");
}
#[test]
fn passive_multiway_pots_are_wider_than_heads_up() {
let v = villain(vpip(0.3));
let heads_up = top_fraction(&spot(Street::Flop, 10.0, 0.0, vec![v.clone()]), &v);
let three_way = top_fraction(
&spot(
Street::Flop,
10.0,
0.0,
vec![v.clone(), villain(None), villain(None)],
),
&v,
);
assert!(three_way > heads_up);
// once somebody bets, the multiway bonus is gone.
let bet_hu = top_fraction(&spot(Street::Flop, 10.0, 5.0, vec![v.clone()]), &v);
let bet_mw = top_fraction(
&spot(
Street::Flop,
10.0,
5.0,
vec![v.clone(), villain(None), villain(None)],
),
&v,
);
assert_eq!(bet_hu, bet_mw);
}
#[test]
fn folded_villains_do_not_count_as_multiway() {
let v = villain(vpip(0.3));
let folded = Villain {
folded: true,
..villain(None)
};
let a = top_fraction(&spot(Street::Flop, 10.0, 0.0, vec![v.clone()]), &v);
let b = top_fraction(&spot(Street::Flop, 10.0, 0.0, vec![v.clone(), folded]), &v);
assert_eq!(a, b);
}
#[test]
fn sticky_players_hold_wider_ranges_than_foldy_ones() {
let with_ftb = |ftb: f64| {
Some(Profile {
vpip: Some(0.3),
pfr: None,
fold_to_bet: Some(ftb),
aggression: None,
})
};
assert!(
guess(Street::Turn, 10.0, 5.0, with_ftb(0.1))
> guess(Street::Turn, 10.0, 5.0, with_ftb(0.9))
);
}