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

94 lines
4.0 KiB
Rust

mod spot_fixture;
use pokerfreak::engine::postflop::choose_postflop;
use pokerfreak::engine::uncertainty::{abstain_confidence, MAX_UNCERTAIN_CONFIDENCE, MIN_UNCERTAIN_CONFIDENCE};
use pokerfreak::exploit::thresholds::Thresholds;
use pokerfreak::game::Choice;
use pokerfreak::read::draw::Draw;
use pokerfreak::read::made::Made;
use pokerfreak::read::suit_pattern::SuitPattern;
use spot_fixture::*;
const BASE: Thresholds = Thresholds::BASE;
fn close(a: f64, b: f64) -> bool {
(a - b).abs() < 1e-9
}
#[test]
fn confidence_rises_linearly_from_the_edge_to_the_rim_of_the_band() {
assert!(close(abstain_confidence(0.0, 0.04), 0.05));
assert!(close(abstain_confidence(0.02, 0.04), 0.175));
assert!(close(abstain_confidence(0.04, 0.04), 0.30));
assert_eq!(MIN_UNCERTAIN_CONFIDENCE, 0.05);
assert_eq!(MAX_UNCERTAIN_CONFIDENCE, 0.30);
}
#[test]
fn confidence_never_leaves_its_range() {
for (d, w) in [(1.0, 0.04), (-1.0, 0.04), (0.01, 0.0), (f64::NAN, 0.1), (0.1, f64::NAN), (f64::INFINITY, 1.0)] {
let c = abstain_confidence(d, w);
assert!((0.05..=0.30).contains(&c), "{d} {w} -> {c}");
}
}
// round_flop: break-even 1/3, plain call margin 0.02 -> call breakpoint 0.3533.
#[test]
fn abstain_near_the_effective_breakpoint_carries_small_confidence() {
let d = choose_postflop(&round_flop(), &estimate(0.34, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Abstain);
let c = d.confidence.value();
assert!((0.05..=0.30).contains(&c), "{c}");
}
#[test]
fn closer_to_the_edge_means_less_confidence() {
let near = choose_postflop(&round_flop(), &estimate(0.352, 0.005), &BASE, &neutral_read());
let rim = choose_postflop(&round_flop(), &estimate(0.335, 0.005), &BASE, &neutral_read());
assert_eq!((near.choice, rim.choice), (Choice::Abstain, Choice::Abstain));
assert!(near.confidence < rim.confidence, "{near:?} {rim:?}");
}
#[test]
fn the_band_applies_to_the_texture_adjusted_breakpoint() {
// Medium pair on a dry board: margin 0.02 + 0.01 + 0.004 = 0.034 -> breakpoint 0.3673.
// Share 0.38 is outside the band around the plain 0.3533 but inside the one around 0.3673.
let medium = read_of(Made::MiddlePair, Draw::None, 0, SuitPattern::Rainbow, 0.1);
let plain = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &neutral_read());
let shifted = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &medium);
assert_eq!(plain.choice, Choice::Call);
assert_eq!(shifted.choice, Choice::Abstain, "{shifted:?}");
}
#[test]
fn the_band_applies_to_the_multiway_adjusted_breakpoint() {
// Three-way: realized 0.38 * 0.9409 = 0.3575, breakpoint 0.3333 + 0.04 = 0.3733.
let spot = with_villains(round_flop(), 3);
let d = choose_postflop(&spot, &estimate(0.38, 0.001), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Abstain, "{d:?}");
}
#[test]
fn marginal_raise_versus_call_abstains_with_small_confidence() {
// Flush draw, share 0.40, fold-equity scale 0.85: P(fold) to a raise to 20 is
// 0.595 * 0.7 * 0.85 = 0.354, worth 3.54 - 0.646 * 2 = 2.25 against the call's 1.0.
// EV standard error = std_error * final pot (45): 2.25 noisy, 0.9 tight.
let th = Thresholds { fold_equity_scale: 0.85, ..BASE };
let noisy = choose_postflop(&round_flop(), &estimate(0.40, 0.05), &th, &flush_draw_read());
assert_eq!(noisy.choice, Choice::Abstain, "{noisy:?}");
let c = noisy.confidence.value();
assert!((0.05..=0.30).contains(&c), "{c}");
let tight = choose_postflop(&round_flop(), &estimate(0.40, 0.02), &th, &flush_draw_read());
assert!(matches!(tight.choice, Choice::Raise { .. }), "{tight:?}");
}
#[test]
fn invalid_equity_stays_at_zero_confidence() {
for share in [f64::NAN, -0.1, 1.5] {
let d = choose_postflop(&round_flop(), &estimate(share, 0.01), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Abstain);
assert_eq!(d.confidence.value(), 0.0);
}
}