Files
pokerfreak/tests/bluff_property.rs
T
mmintelandClaude Opus 5.5 1ad6f76088 Bluffing and bluff catching driven by opponent frequencies
- 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>
2026-10-28 13:11:38 +01:00

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 pokerfreak::engine::bluff::{branches, NEVER_FOLDS, PURE_BLUFF_MIN_FOLD};
use pokerfreak::engine::called::Called;
use pokerfreak::engine::effective::effective;
use pokerfreak::engine::multiway::realized_share;
use pokerfreak::engine::options::passive_ev;
use pokerfreak::engine::postflop::choose_postflop_with;
use pokerfreak::exploit::profile::Profile;
use pokerfreak::exploit::table_fold::table_fold;
use pokerfreak::exploit::thresholds::Thresholds;
use pokerfreak::game::{ActionKind, Choice, Spot, Street, Villain};
use pokerfreak::read::draw::Draw;
use pokerfreak::read::made::Made;
use pokerfreak::read::suit_pattern::SuitPattern;
use pokerfreak::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:?}");
}