Files
pokerfreak/src/engine/called_equity.rs
T
mmintel 9c79d8236b Acceptance 5.11.: channel play without AFK, quiet focus, working Cockpit, stronger play
- Practice tables: 20-min session 54/54 turns at the server, control session 28 turns,
  0 timeouts; stage: 3 tables, two rounds each, clean teardown.
- Never let the clock run: an engine abstention becomes check or fold (nie_verstreichen).
- Mittler join in a fixed order (kill the duplicate, then announce), a mittler ends with its
  game, the laufwache opens no tables, stop waits for the runner to stand up.
- Focus: no lobby connections from HUD, probes or layout; "Focus Window on Turn" off.
- Tables: disconnected or sitting-out opponents do not count; a table without channel is
  closed and avoided after 45 s; the join event keeps the writer's pid (strict invariants).
- Geldwache: same room list as the runner, the table's own report, stand up before closing.
- Engine: the small blind completes the top 65 % against limpers (price per fair share);
  the calling range of a bet is as wide as the villain calls - value bets into stations.
- Cockpit: the source tree never comes from SHELL; one operating set for laufwache and
  Cockpit (sicht/start.py --client, ServerStart).
- Project lives in ~/Projects/pokerfreak (kern was a detour).
2026-11-05 16:10:43 +01:00

72 lines
2.9 KiB
Rust

use super::called::Called;
use super::range_combos::{as_ranges, combos};
use super::range_filter::{range_filter, HandFilter};
use crate::card::Card;
use crate::equity::monte_carlo::estimate;
use crate::equity::query::Query;
use crate::equity::villain_range::VillainRange;
use crate::exploit::call_floor::call_continuation;
use crate::exploit::range_model::range_spec;
use crate::exploit::size_notch::size_notch;
use crate::exploit::table_fold::pressure_ratio;
use crate::game::{ActionKind, Spot};
use crate::rng::Rng;
use crate::sizing::candidates::candidates;
/// Trials per calling-range simulation (one per size notch, so a few per decision).
const CALLED_TRIALS: u32 = 1000;
/// Hero's share against the hands that call a raise to each candidate size.
///
/// Each villain keeps their modelled range (`range_spec`) plus the calling floor
/// for that pressure (`exploit::call_floor`). Sizes in the same `size_notch` share one
/// simulation. A size whose simulation fails is left out (the engine then falls back
/// to the overall share). No legal raise: nothing to compute.
pub fn called_equity(spot: &Spot) -> Called {
if !spot.is_legal(ActionKind::Raise) {
return Called::sized(Vec::new());
}
let notched: Vec<(f64, i32, f64)> = candidates(spot)
.into_iter()
.map(|to| {
let ratio = pressure_ratio(spot.pot, spot.to_call, to);
(to, size_notch(Some(ratio)), ratio)
})
.collect();
let shares: Vec<(i32, Option<f64>)> = notched.iter().fold(Vec::new(), |mut done, (_, notch, ratio)| {
if !done.iter().any(|(n, _)| n == notch) {
done.push((*notch, simulate(spot, *notch, *ratio)));
}
done
});
Called::sized(
notched
.into_iter()
.filter_map(|(to, notch, _)| {
shares.iter().find(|(n, _)| *n == notch).and_then(|(_, s)| *s).map(|s| (to, s))
})
.collect(),
)
}
fn simulate(spot: &Spot, notch: i32, ratio: f64) -> Option<f64> {
let rules = spot.rules();
let filters: Vec<HandFilter> = spot
.live_villains()
.map(|v| {
let mut spec = range_spec(spot, v);
spec.continues.push(call_continuation(v, spot.street, ratio, spot.to_call > 0.0));
range_filter(&spec, rules, spot.variant, &spot.board)
})
.collect();
if filters.is_empty() {
return None;
}
let dead: Vec<Card> = spot.hero_cards.iter().chain(&spot.board).copied().collect();
let lists: Vec<_> = filters.iter().map(|f| combos(&rules, f, &dead)).collect();
let ranges: Vec<VillainRange> = as_ranges(&filters, &lists);
let query = Query { rules, hero: &spot.hero_cards, board: &spot.board, villains: &ranges, trials: CALLED_TRIALS };
let seed = spot.seed ^ (0xCA11_0000_u64 + (notch + 8).clamp(0, 64) as u64);
estimate(&query, Rng::seeded(seed)).ok().map(|(e, _)| e.share)
}