Files
pokerfreak/src/exploit/brett_floor.rs
T
mmintelandClaude Opus 5.5 6b3b3d501e Flussleck: zwei River-Fehler aus dem Live-Lauf 16.11. abends im Kern behoben (Schalter, aus = bitgleich)
RUF_ALLIN=1: called_equity simuliert die All-in-Groesse mit, die REST_STACK hinzufuegt
(vorher fiel der Call-Anteil des Jams auf den Anteil gegen die ganze Range zurueck, 0,678).
RUF_OBEN=river: am River zahlt die staerkste (1-Fold)-Spitze statt Boden plus Zufall.
WERT_BRETT=river: River-Boden der Wett-Range als Staerke-Perzentil auf dem echten Brett
(exploit/brett_floor.rs) statt Handklasse; Vierflush-Brett: Strasse 0,35 -> 0,16 Equity.

Pflichtfaelle: Live 10/16, Kandidat 12/16, 178854100443 CHECK und 178870300411 FOLD behoben,
kein alter Fall verloren. BEKANNTE_SCHALTER ergaenzt. Volles Tor fl-* laeuft gg. ps2-*-an.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 17:50:46 +01:00

169 lines
6.0 KiB
Rust

//! Board-relative river floor (`WERT_BRETT=river`): a river bet claims the same RELATIVE strength on
//! every board.
//!
//! The continuation floors of `street_continuation` are absolute made classes (a river bet keeps top
//! pair good kicker or better). On a dry board that is roughly the top fifth of all holdings; on a
//! paired four-flush board every pocket pair and every hand with a board rank "is" two pair or trips,
//! and every club is a flush, so the same class admits most of the deck and a straight looks like 56 %
//! against a passive river bettor (live 16.11. hand 178870300411, J-high straight on 9c9hTc8c2c).
//!
//! The floor is translated through its REFERENCE SHARE: the average share of all two-card holdings at
//! or above that class over random river boards. On the actual board the floor rises to the weakest
//! class whose share of all holdings does not exceed the reference share. On a dry board nothing
//! moves; on a flush or paired board the floor climbs to flushes and full houses. Hold'em only.
use crate::card::{deck, Card};
use crate::hand::showdown::judge;
use crate::hand::strength::Strength;
use crate::read::glance::glance;
use crate::read::made::Made;
use crate::rng::Rng;
use crate::variant::rules::Rules;
/// Every class, weakest first (`Made` is ordered).
const ALL: [Made; 16] = [
Made::Air,
Made::BoardOnly,
Made::Underpair,
Made::BottomPair,
Made::MiddlePair,
Made::TopPairWeakKicker,
Made::TopPairGoodKicker,
Made::Overpair,
Made::TwoPair,
Made::Set,
Made::Trips,
Made::Straight,
Made::Flush,
Made::FullHouse,
Made::Quads,
Made::StraightFlush,
];
/// Random river boards behind the reference shares (fixed seed: deterministic per binary).
const REFERENCE_BOARDS: usize = 160;
const REFERENCE_SEED: u64 = 0xB0A2_D5EE_D001;
/// Messschalter (einmal gelesen) `WERT_BRETT=river`: river bet/raise floors are board-relative.
pub fn enabled() -> bool {
use std::sync::OnceLock;
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var("WERT_BRETT").as_deref() == Ok("river"))
}
/// Share of all two-card holdings (outside the board) per class at or above it: `out[i]` for `ALL[i]`.
fn shares_at_least(rules: &Rules, board: &[Card]) -> Option<[f64; 16]> {
if rules.hole_cards != 2 {
return None;
}
let pool = deck::without_in(rules.deck, board);
let mut count = [0usize; 16];
let mut total = 0usize;
for i in 0..pool.len() {
for j in i + 1..pool.len() {
let Ok((made, _)) = glance(rules, &[pool[i], pool[j]], board) else { continue };
total += 1;
count[ALL.iter().position(|m| *m == made)?] += 1;
}
}
if total == 0 {
return None;
}
let mut out = [0.0; 16];
let mut acc = 0usize;
for i in (0..16).rev() {
acc += count[i];
out[i] = acc as f64 / total as f64;
}
Some(out)
}
/// Average `shares_at_least` over random river boards (Hold'em), computed once.
fn reference(rules: &Rules) -> Option<&'static [f64; 16]> {
use std::sync::OnceLock;
static REF: OnceLock<Option<[f64; 16]>> = OnceLock::new();
REF.get_or_init(|| {
let full = deck::without_in(rules.deck, &[]);
let mut rng = Rng::seeded(REFERENCE_SEED);
let mut sum = [0.0; 16];
let mut n = 0usize;
for _ in 0..REFERENCE_BOARDS {
let (board, next) = deck::draw(&full, 5, rng)?;
rng = next;
if let Some(s) = shares_at_least(rules, &board) {
for (a, b) in sum.iter_mut().zip(s) {
*a += b;
}
n += 1;
}
}
(n > 0).then(|| sum.map(|a| a / n as f64))
})
.as_ref()
}
/// The board-relative floor as a showdown-strength cut: the strength of the `ceil(q * n)`-th
/// strongest of all `n` holdings on this board, `q` the reference share of `floor` (its share of all
/// holdings on an average river). `None` when the class floor already admits no more than `q` here
/// (dry board: nothing changes), or without a full Hold'em river board.
pub fn strength_cut(rules: &Rules, board: &[Card], floor: Made) -> Option<Strength> {
if board.len() != 5 || rules.hole_cards != 2 {
return None;
}
let reference = reference(rules)?;
let here = shares_at_least(rules, board)?;
let i = ALL.iter().position(|m| *m == floor)?;
let q = reference[i];
if here[i] <= q + 1e-12 {
return None;
}
let pool = deck::without_in(rules.deck, board);
let mut all: Vec<Strength> = Vec::new();
for a in 0..pool.len() {
for b in a + 1..pool.len() {
if let Ok(s) = judge(rules, &[pool[a], pool[b]], board) {
all.push(s);
}
}
}
all.sort_unstable_by(|x, y| y.cmp(x));
let k = ((q * all.len() as f64).ceil() as usize).clamp(1, all.len().max(1));
all.get(k - 1).copied()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::variant::kind::Variant;
use crate::variant::rules::rules;
fn cards(s: &str) -> Vec<Card> {
Card::parse_list(s).unwrap()
}
fn strength(hole: &str, board: &str) -> Strength {
judge(&rules(Variant::Nlhe), &cards(hole), &cards(board)).unwrap()
}
#[test]
fn dry_board_keeps_the_class_floor() {
let r = rules(Variant::Nlhe);
assert_eq!(strength_cut(&r, &cards("Kd 7s 2c 9h 4d"), Made::TopPairGoodKicker), None);
}
#[test]
fn paired_four_flush_board_puts_a_straight_below_the_cut() {
let r = rules(Variant::Nlhe);
let b = "9c 9h Tc 8c 2c";
let cut = strength_cut(&r, &cards(b), Made::TopPairGoodKicker).expect("cut");
assert!(strength("Jd 7d", b) < cut, "J-high straight must be below the board-relative floor");
assert!(strength("Ac 3d", b) >= cut, "the nut flush stays value");
}
#[test]
fn no_cut_before_the_river() {
let r = rules(Variant::Nlhe);
assert_eq!(strength_cut(&r, &cards("9c 9h Tc 8c"), Made::TopPairGoodKicker), None);
}
}