Files
pokerfreak/tests/reraise_narrowing.rs
T
mmintelandClaude Opus 5.5 6eb2aa1a7a Merge claude/engine-lecks-angreifen-de7b88 (engine-roentgen 0923eca2, UEBERSCHUSS) in claude/gedaechtnis-kern
Konflikte: BEKANNTE_SCHALTER vereinigt; range_filter Kept mit Accept + Klassen-Kipp; RAISE_FOLD_DECKEL in sized_fold_on.
Specs gruen (169 Test-Binaries).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 21:13:43 +01:00

100 lines
4.0 KiB
Rust

//! Spec: a re-raise narrows the villain's range by his measured raise frequency (`RERAISE_TIEFE`).
//!
//! The villain's second (third ...) bet or raise on one street used to get the same floor as his
//! first (`street_continuation::level` knew only bet / raise): against value-only raisers top pair
//! with a gutshot kept 0.64 equity through three raises and went all-in (diag_welt cbet-folder
//! 15.11., raise wars about -58 bb/100). Now each further aggression keeps the strongest share of
//! what was left - his raise-facing-bet frequency `r` per level (Bayes per line), shrunk to the pool
//! value without hands - via `Continuation::top_share` in `engine::range_filter`.
mod spot_fixture;
use rechner::card::{deck, Card};
use rechner::engine::range_filter::range_filter;
use rechner::exploit::profile::Profile;
use rechner::exploit::range_spec::{Continuation, RangeSpec};
use rechner::exploit::street_continuation::{reraise_share, RAISE_TO_BET_POOL};
use rechner::game::Villain;
use rechner::read::draw::Draw;
use rechner::read::glance::glance;
use rechner::read::made::Made;
use rechner::variant::{rules, Variant};
use spot_fixture::cards;
const BOARD: &str = "Kd 8h 3c";
fn spec(top_share: Option<f64>, bluff_share: f64) -> RangeSpec {
RangeSpec { class_target: None,
lo: 0.0,
hi: 1.0,
continues: vec![Continuation {
board_len: 3,
min_made: Made::BottomPair,
draws_continue: true,
min_draw: Draw::Gutshot,
bluff_share,
continue_share: None,
top_share,
min_strength: None,
likelihood: None,
}],
}
}
fn all_hands(board: &[Card]) -> Vec<[Card; 2]> {
let pool = deck::without(board);
(0..pool.len()).flat_map(|i| (i + 1..pool.len()).map(move |j| (i, j))).map(|(i, j)| [pool[i], pool[j]]).collect()
}
/// (share passing, weakest made hand passing, strongest made hand failing)
fn census(s: &RangeSpec) -> (f64, Made, Made) {
let board = cards(BOARD);
let r = rules(Variant::Nlhe);
let filter = range_filter(s, r, Variant::Nlhe, &board);
let hands = all_hands(&board);
let made = |h: &[Card; 2]| glance(&r, &h[..], &board).unwrap().0;
let pass: Vec<_> = hands.iter().filter(|h| filter(&h[..])).collect();
let weakest = pass.iter().map(|h| made(h)).min().unwrap();
let best_out = hands.iter().filter(|h| !filter(&h[..])).map(made).max().unwrap();
(pass.len() as f64 / hands.len() as f64, weakest, best_out)
}
#[test]
fn the_top_share_keeps_the_strongest_hands() {
for share in [0.05, 0.15, 0.3] {
let (passing, weakest, best_out) = census(&spec(Some(share), 0.0));
assert!((passing - share).abs() < 0.005, "share {share}: {passing:.3} pass");
assert!(weakest >= best_out, "share {share}: {weakest:?} passes while {best_out:?} is out");
}
}
#[test]
fn without_a_top_share_nothing_changes() {
let (alone, _, _) = census(&spec(None, 0.0));
let (all, _, _) = census(&spec(Some(1.0), 0.0));
assert_eq!(alone, all);
assert!(alone > 0.3, "the floor alone passes {alone:.3}");
}
#[test]
fn bluffs_are_admitted_below_the_cut() {
let (value, _, _) = census(&spec(Some(0.1), 0.0));
let (with_bluffs, _, _) = census(&spec(Some(0.1), 0.25));
assert!((with_bluffs - value / 0.75).abs() < 0.005, "{value:.3} value, {with_bluffs:.3} with bluffs");
}
#[test]
fn the_share_per_level_is_the_raise_frequency_and_the_pool_without_a_read() {
let read = |r: Option<f64>| Villain {
seat: 1,
stack: 100.0,
folded: false,
profile: Some(Profile { reraise_to_raise: r, ..Profile::default() }),
};
assert!((reraise_share(&read(Some(0.2)), 2) - 0.2).abs() < 1e-12);
assert!((reraise_share(&read(Some(0.2)), 3) - 0.04).abs() < 1e-12);
assert!((reraise_share(&read(None), 2) - RAISE_TO_BET_POOL).abs() < 1e-12);
let blind = Villain { seat: 1, stack: 100.0, folded: false, profile: None };
assert!((reraise_share(&blind, 2) - RAISE_TO_BET_POOL).abs() < 1e-12);
}