Files
pokerfreak/src/preflop/multi_lookup.rs
T
mmintel 836c16c9a4 Sprechweise geputzt: kein echt/live/Mensch mehr in Kommentaren und Texten
Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht,
live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s,
echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings
angefasst, damit keine Einrueckung faellt.
2026-11-01 22:11:05 +01:00

76 lines
3.4 KiB
Rust

//! Lookup over the frozen multi-defender tables (`generated_charts_multi`): one decision node of
//! the game "first actor `seat` against `defenders` modelled players behind it", for every class.
//!
//! - Full deck only (NLHE); the short deck has no multi-defender table.
//! - Depth rule: the two grid depths around `depth_bb` are interpolated linearly, like
//! `generated_lookup`, but there is no clamping: outside the grid (`OPEN_DEPTHS`, 20 to 100 bb)
//! the answer is `None` and the caller keeps its old tables.
//! - Node names are those of `cfr::multi_tree` (`open`, `{D}_defend`, `vs_{D}_three_bet`,...).
//! Two-action nodes are fold / aggressive (`open`) or fold / call (`{D}_vs_jam`, overcalls),
//! three-action nodes fold / call / aggressive.
//!
//! The rows are decoded once per call; the result covers all `CLASS_COUNT` classes.
use super::generated_charts_multi::{MULTI, OPEN_DEPTHS};
use super::generated_lookup::Frequencies;
use crate::cfr::frozen_multi::{permille_rows, MultiRow, MultiSpot};
use crate::cfr::seat::Seat;
/// Covered stack range in bb.
pub fn multi_depth_range() -> (f64, f64) {
let lo = OPEN_DEPTHS.iter().copied().min().unwrap_or(0) as f64;
let hi = OPEN_DEPTHS.iter().copied().max().unwrap_or(0) as f64;
(lo, hi)
}
fn spot(seat: Seat, defenders: usize, depth: u8) -> Option<&'static MultiSpot> {
MULTI.iter().find(|s| s.seat == seat && s.defenders as usize == defenders && s.depth_bb == depth)
}
/// Frequencies of `node` per class; `aggressive_two`: a two-action node's second action is the
/// aggressive one (open) rather than a call.
fn row(row: &MultiRow, aggressive_two: bool) -> Option<Vec<Frequencies>> {
let permille = permille_rows(row).ok()?;
permille
.iter()
.map(|p| {
let f = |i: usize| p.get(i).copied().unwrap_or(0) as f64 / 1000.0;
match p.len() {
2 if aggressive_two => Some(Frequencies { fold: f(0), call: 0.0, raise: f(1) }),
2 => Some(Frequencies { fold: f(0), call: f(1), raise: 0.0 }),
3 => Some(Frequencies { fold: f(0), call: f(1), raise: f(2) }),
_ => None,
}
})
.collect()
}
fn node_row(spot: &MultiSpot, node: &str) -> Option<Vec<Frequencies>> {
let found = spot.rows.iter().find(|r| r.name == node)?;
row(found, node == "open")
}
/// `node` of the game `seat` against `defenders` at `depth_bb`, per class; `None` outside the
/// depth grid, for an unknown lineup or node.
pub fn multi_node(seat: Seat, defenders: usize, depth_bb: f64, node: &str) -> Option<Vec<Frequencies>> {
let (lo, hi) = multi_depth_range();
if !depth_bb.is_finite() || depth_bb < lo || depth_bb > hi {
return None;
}
let below = OPEN_DEPTHS.iter().copied().filter(|d| *d as f64 <= depth_bb).max()?;
let above = OPEN_DEPTHS.iter().copied().filter(|d| *d as f64 >= depth_bb).min()?;
let low = node_row(spot(seat, defenders, below)?, node)?;
if below == above {
return Some(low);
}
let high = node_row(spot(seat, defenders, above)?, node)?;
let t = (depth_bb - below as f64) / (above as f64 - below as f64);
let mix = |a: f64, b: f64| a * (1.0 - t) + b * t;
Some(
low.iter()
.zip(high.iter())
.map(|(a, b)| Frequencies { fold: mix(a.fold, b.fold), call: mix(a.call, b.call), raise: mix(a.raise, b.raise) })
.collect(),
)
}