Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
151 lines
5.7 KiB
Rust
151 lines
5.7 KiB
Rust
//! Property: a bluff (or semibluff) is only ever chosen when both branches of its
|
|
//! expected value are accounted for and the total pays:
|
|
//!
|
|
//! EV = P(all fold) * pot + (1 - P(all fold)) * (called share * final pot - added)
|
|
//!
|
|
//! with a strictly positive fold branch, EV > 0 and EV above the best passive line.
|
|
//! Never against an opponent who never folds; pure bluffs heads-up only.
|
|
|
|
mod spot_fixture;
|
|
|
|
use rechner::engine::bluff::{branches, NEVER_FOLDS, PURE_BLUFF_MIN_FOLD};
|
|
use rechner::engine::called::Called;
|
|
use rechner::engine::effective::effective;
|
|
use rechner::engine::multiway::realized_share;
|
|
use rechner::engine::options::passive_ev;
|
|
use rechner::engine::postflop::choose_postflop_with;
|
|
use rechner::exploit::profile::Profile;
|
|
use rechner::exploit::table_fold::table_fold;
|
|
use rechner::exploit::thresholds::Thresholds;
|
|
use rechner::game::{ActionKind, Choice, Spot, Street, Villain};
|
|
use rechner::read::draw::Draw;
|
|
use rechner::read::made::Made;
|
|
use rechner::read::suit_pattern::SuitPattern;
|
|
use rechner::rng::Rng;
|
|
use spot_fixture::*;
|
|
|
|
const MADES: [Made; 8] = [
|
|
Made::Air,
|
|
Made::Underpair,
|
|
Made::BottomPair,
|
|
Made::MiddlePair,
|
|
Made::TopPairWeakKicker,
|
|
Made::TwoPair,
|
|
Made::Set,
|
|
Made::Flush,
|
|
];
|
|
const DRAWS: [Draw; 5] = [Draw::None, Draw::Backdoor, Draw::Gutshot, Draw::OpenEnded, Draw::Flush];
|
|
|
|
struct Case {
|
|
spot: Spot,
|
|
share: f64,
|
|
called: f64,
|
|
made: Made,
|
|
draw: Draw,
|
|
outs: u8,
|
|
}
|
|
|
|
fn pick<T: Copy>(items: &[T], rng: Rng) -> (T, Rng) {
|
|
let (i, rng) = rng.below(items.len() as u64);
|
|
(items[i as usize], rng)
|
|
}
|
|
|
|
fn profile(rng: Rng) -> (Option<Profile>, Rng) {
|
|
let (kind, rng) = rng.below(4);
|
|
let (f, rng) = rng.unit();
|
|
let (a, rng) = rng.unit();
|
|
let p = match kind {
|
|
0 => None,
|
|
1 => Some(Profile { fold_to_bet: Some(f), ..Profile::default() }),
|
|
2 => Some(Profile { fold_to_bet: Some(f * 0.1), aggression: Some(a), ..Profile::default() }),
|
|
_ => Some(Profile { vpip: Some(f * 0.6), pfr: Some(f * 0.3), aggression: Some(a), ..Profile::default() }),
|
|
};
|
|
(p, rng)
|
|
}
|
|
|
|
fn case(rng: Rng) -> (Case, Rng) {
|
|
let (pot, rng) = rng.unit();
|
|
let (bet, rng) = rng.below(3);
|
|
let (street, rng) = pick(&[Street::Flop, Street::Turn, Street::River], rng);
|
|
let (n, rng) = rng.below(3);
|
|
let (share, rng) = rng.unit();
|
|
let (drop, rng) = rng.unit();
|
|
let (made, rng) = pick(&MADES, rng);
|
|
let (draw, rng) = pick(&DRAWS, rng);
|
|
let (outs, rng) = rng.below(13);
|
|
let pot = 2.0 + 40.0 * pot;
|
|
let to_call = [0.0, pot * 0.33, pot * 0.75][bet as usize];
|
|
let (villains, rng) = (0..=n).fold((Vec::new(), rng), |(mut vs, rng), i| {
|
|
let (p, rng) = profile(rng);
|
|
vs.push(Villain { seat: i as u8 + 1, stack: 200.0, folded: false, profile: p });
|
|
(vs, rng)
|
|
});
|
|
let legal = if to_call > 0.0 {
|
|
vec![ActionKind::Fold, ActionKind::Call, ActionKind::Raise]
|
|
} else {
|
|
vec![ActionKind::Check, ActionKind::Raise]
|
|
};
|
|
let spot = Spot {
|
|
street,
|
|
pot,
|
|
to_call,
|
|
hero_stack: 200.0,
|
|
min_raise_to: Some((to_call * 2.0).max(1.0)),
|
|
max_raise_to: Some(200.0),
|
|
legal,
|
|
villains,
|
|
..round_flop()
|
|
};
|
|
(Case { spot, share, called: share * (1.0 - drop * 0.8), made, draw, outs: outs as u8 }, rng)
|
|
}
|
|
|
|
#[test]
|
|
fn bluffs_only_with_a_paying_two_branch_ev() {
|
|
let th = Thresholds::BASE;
|
|
let (mut bluffs, mut rng) = (0, Rng::seeded(0xB1_0FF));
|
|
for _ in 0..4000 {
|
|
let (c, next) = case(rng);
|
|
rng = next;
|
|
let read = read_of(c.made, c.draw, c.outs, SuitPattern::Rainbow, 0.3);
|
|
let d = choose_postflop_with(&c.spot, &estimate(c.share, 0.002), &Called::flat(c.called), &th, &read);
|
|
let Choice::Raise { to } = d.choice else { continue };
|
|
if !d.reason.contains("bluff") {
|
|
continue;
|
|
}
|
|
bluffs += 1;
|
|
let live = c.spot.live_villains().count();
|
|
let eff = effective(&c.spot, c.share, &th, &read);
|
|
let fold = table_fold(&c.spot, to, th.fold_equity_scale);
|
|
let b = branches(&c.spot, to, fold, realized_share(c.called, live));
|
|
let passive = passive_ev(&c.spot, eff.share).unwrap_or(f64::NEG_INFINITY);
|
|
assert!(fold > 0.0 && b.fold > 0.0, "{d:?} fold {fold}");
|
|
assert!(b.total > 0.0 && b.total > passive, "{d:?}: {b:?} vs passive {passive}");
|
|
assert!((b.fold + b.called - b.total).abs() < 1e-9);
|
|
assert!(
|
|
c.spot.live_villains().all(|v| v.profile.and_then(|p| p.fold_to_bet).is_none_or(|f| f > NEVER_FOLDS)),
|
|
"bluffed a never-folder: {d:?}"
|
|
);
|
|
if !d.reason.contains("semibluff") {
|
|
assert_eq!(live, 1, "pure bluff multiway: {d:?}");
|
|
assert!(fold >= PURE_BLUFF_MIN_FOLD, "{d:?} fold {fold}");
|
|
}
|
|
if c.spot.street == Street::River {
|
|
assert!(!d.reason.contains("semibluff"), "{d:?}");
|
|
}
|
|
}
|
|
assert!(bluffs > 50, "the generator must reach bluffs: {bluffs}");
|
|
}
|
|
|
|
#[test]
|
|
fn the_called_branch_matters() {
|
|
// Same spot, same overall equity: when the calls come from a much stronger range,
|
|
// the raise loses its edge and the passive line wins.
|
|
let spot = Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..round_flop() };
|
|
let read = read_of(Made::TopPairWeakKicker, Draw::None, 0, SuitPattern::Rainbow, 0.2);
|
|
let th = Thresholds::BASE;
|
|
let loose = choose_postflop_with(&spot, &estimate(0.75, 0.002), &Called::flat(0.75), &th, &read);
|
|
let tight = choose_postflop_with(&spot, &estimate(0.75, 0.002), &Called::flat(0.2), &th, &read);
|
|
assert!(matches!(loose.choice, Choice::Raise { .. }), "{loose:?}");
|
|
assert_eq!(tight.choice, Choice::Check, "{tight:?}");
|
|
}
|