EP, MP, CO and BTN now play three-player games against small and big blind (push/fold and open/call/3-bet trees, CFR+ for three players, exploitability summed over all three best responses). Deal weights and three-way shares are documented approximations. Short deck gets its own equity table and charts from the same generator (--deck short). Open width shrinks in EP/MP (e.g. EP 100bb 0.291 -> 0.249, MP 40bb 0.357 -> 0.293); frozen exploitability stays at 0-4 micro-bb (full) and 0-9 micro-bb (short). Lookup and advice cover SB vs open/jam, BB after an SB call and the opener vs an SB 3-bet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
246 lines
10 KiB
Rust
246 lines
10 KiB
Rust
//! Pure lookup over the frozen CFR charts (`generated_charts`). No allocation, no I/O.
|
|
//!
|
|
//! Depth rule: the frequencies of the two grid depths around `depth_bb` are interpolated
|
|
//! linearly in the stack size; below the shallowest or above the deepest grid depth the nearest
|
|
//! table is used unchanged (clamping -- see `push_depth_range` / `open_depth_range` for the
|
|
//! covered range). Non-finite or non-positive depths, unknown classes and variants without a
|
|
//! chart give `None`.
|
|
//!
|
|
//! Every function answers for the *seat that acts* in that situation (`seat` / `pusher` /
|
|
//! `opener` is always the first actor of the spot):
|
|
//! - `push_frequency`: the first actor jams (raise = jam) or folds.
|
|
//! - `sb_call_vs_push`: the small blind facing that jam, the big blind still behind.
|
|
//! - `call_vs_push`: the big blind facing that jam after the small blind folded.
|
|
//! - `bb_overcall_vs_push`: the big blind facing that jam after the small blind called.
|
|
//! - `open_frequency`: the first actor raises or folds.
|
|
//! - `sb_vs_open`: the small blind facing the open: fold / call / 3-bet.
|
|
//! - `vs_open`: the big blind facing the open after the small blind folded: fold / call / 3-bet.
|
|
//! - `bb_vs_open_and_call`: the big blind facing the open and the small blind's call: fold / call.
|
|
//! - `vs_three_bet`: the opener facing the big blind's 3-bet: fold / call / jam.
|
|
//! - `vs_sb_three_bet`: the opener facing the small blind's 3-bet: fold / call / jam.
|
|
//! - `vs_jam`: the big blind facing the opener's jam over its 3-bet: fold / call.
|
|
//!
|
|
//! The small-blind and overcall tables exist only for first actors EP to BTN (the small blind as
|
|
//! first actor faces the big blind alone): for `SmallBlind` they answer `None`.
|
|
//! Tables: NLHE and AOF share the full-deck file, short deck has its own (`generated_charts_short`);
|
|
//! AOF has push / fold only.
|
|
//!
|
|
//! Class ids are those of `crate::cfr::hand_class` (`class_of(card, card)`).
|
|
|
|
use super::generated_charts::{AOF_PUSH_FOLD, OPEN, OPEN_DEPTHS, PUSH_FOLD, PUSH_FOLD_DEPTHS};
|
|
use super::generated_charts_short as short;
|
|
use super::position::Position;
|
|
use crate::cfr::frozen_spot::{OpenSpot, PushFoldSpot};
|
|
use crate::cfr::hand_class::{ClassId, CLASS_COUNT};
|
|
use crate::cfr::seat::Seat;
|
|
use crate::variant::Variant;
|
|
|
|
/// Action probabilities; `raise` is the aggressive action of the node (raise / 3-bet / jam).
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
pub struct Frequencies {
|
|
pub fold: f64,
|
|
pub call: f64,
|
|
pub raise: f64,
|
|
}
|
|
|
|
impl Frequencies {
|
|
fn aggressive(permille: u16) -> Frequencies {
|
|
let p = permille as f64 / 1000.0;
|
|
Frequencies { fold: 1.0 - p, call: 0.0, raise: p }
|
|
}
|
|
|
|
fn passive(permille: u16) -> Frequencies {
|
|
let p = permille as f64 / 1000.0;
|
|
Frequencies { fold: 1.0 - p, call: p, raise: 0.0 }
|
|
}
|
|
|
|
fn split(call_raise: [u16; 2]) -> Frequencies {
|
|
let (call, raise) = (call_raise[0] as f64 / 1000.0, call_raise[1] as f64 / 1000.0);
|
|
Frequencies { fold: (1.0 - call - raise).max(0.0), call, raise }
|
|
}
|
|
|
|
fn blend(self, other: Frequencies, t: f64) -> Frequencies {
|
|
let mix = |a: f64, b: f64| a * (1.0 - t) + b * t;
|
|
Frequencies {
|
|
fold: mix(self.fold, other.fold),
|
|
call: mix(self.call, other.call),
|
|
raise: mix(self.raise, other.raise),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Chart seat for a table position; `None` for the big blind (it never acts first in these
|
|
/// charts). An unknown position uses the tightest (early) row, like the heuristic charts do.
|
|
pub fn seat_of(position: Position) -> Option<Seat> {
|
|
match position {
|
|
Position::Middle => Some(Seat::Middle),
|
|
Position::Cutoff => Some(Seat::Cutoff),
|
|
Position::Button => Some(Seat::Button),
|
|
Position::SmallBlind | Position::HeadsUpButton => Some(Seat::SmallBlind),
|
|
Position::BigBlind => None,
|
|
_ => Some(Seat::Early),
|
|
}
|
|
}
|
|
|
|
/// Covered stack range in bb for the push / fold charts.
|
|
pub fn push_depth_range() -> (f64, f64) {
|
|
range(&PUSH_FOLD_DEPTHS)
|
|
}
|
|
|
|
/// Covered stack range in bb for the open / call / 3-bet charts.
|
|
pub fn open_depth_range() -> (f64, f64) {
|
|
range(&OPEN_DEPTHS)
|
|
}
|
|
|
|
fn range(depths: &[u8]) -> (f64, f64) {
|
|
let lo = depths.iter().copied().min().unwrap_or(0) as f64;
|
|
let hi = depths.iter().copied().max().unwrap_or(0) as f64;
|
|
(lo, hi)
|
|
}
|
|
|
|
trait Placed {
|
|
fn seat(&self) -> Seat;
|
|
fn depth(&self) -> u8;
|
|
}
|
|
|
|
impl Placed for PushFoldSpot {
|
|
fn seat(&self) -> Seat {
|
|
self.seat
|
|
}
|
|
fn depth(&self) -> u8 {
|
|
self.depth_bb
|
|
}
|
|
}
|
|
|
|
impl Placed for OpenSpot {
|
|
fn seat(&self) -> Seat {
|
|
self.seat
|
|
}
|
|
fn depth(&self) -> u8 {
|
|
self.depth_bb
|
|
}
|
|
}
|
|
|
|
/// The two grid spots around `depth` (both the same one when clamped or on the grid) and the
|
|
/// weight of the deeper one.
|
|
fn bracket<T: Placed>(spots: &[T], seat: Seat, depth: f64) -> Option<(&T, &T, f64)> {
|
|
let mine = || spots.iter().filter(|s| s.seat() == seat);
|
|
let below = mine().filter(|s| s.depth() as f64 <= depth).max_by_key(|s| s.depth());
|
|
let above = mine().filter(|s| s.depth() as f64 >= depth).min_by_key(|s| s.depth());
|
|
match (below, above) {
|
|
(Some(lo), Some(hi)) if lo.depth() != hi.depth() => {
|
|
let t = (depth - lo.depth() as f64) / (hi.depth() as f64 - lo.depth() as f64);
|
|
Some((lo, hi, t))
|
|
}
|
|
(Some(lo), Some(_)) => Some((lo, lo, 0.0)),
|
|
(Some(lo), None) => Some((lo, lo, 0.0)),
|
|
(None, Some(hi)) => Some((hi, hi, 0.0)),
|
|
(None, None) => None,
|
|
}
|
|
}
|
|
|
|
fn lookup<T: Placed>(
|
|
spots: &[T],
|
|
seat: Seat,
|
|
depth_bb: f64,
|
|
class: ClassId,
|
|
read: impl Fn(&T, ClassId) -> Frequencies,
|
|
) -> Option<Frequencies> {
|
|
if !depth_bb.is_finite() || depth_bb <= 0.0 || class >= CLASS_COUNT {
|
|
return None;
|
|
}
|
|
let (lo, hi, t) = bracket(spots, seat, depth_bb)?;
|
|
Some(read(lo, class).blend(read(hi, class), t))
|
|
}
|
|
|
|
fn non_empty<T>(spots: &'static [T]) -> Option<&'static [T]> {
|
|
(!spots.is_empty()).then_some(spots)
|
|
}
|
|
|
|
fn push_chart(variant: Variant) -> Option<&'static [PushFoldSpot]> {
|
|
match variant {
|
|
Variant::Nlhe => non_empty(&PUSH_FOLD),
|
|
Variant::Aof => non_empty(AOF_PUSH_FOLD),
|
|
Variant::ShortDeck => non_empty(&short::PUSH_FOLD),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn open_chart(variant: Variant) -> Option<&'static [OpenSpot]> {
|
|
match variant {
|
|
Variant::Nlhe => non_empty(&OPEN),
|
|
Variant::ShortDeck => non_empty(&short::OPEN),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
/// True when CFR charts exist for `variant` (NLHE, AOF, short deck).
|
|
pub fn has_charts(variant: Variant) -> bool {
|
|
push_chart(variant).is_some()
|
|
}
|
|
|
|
/// The small blind and the overcall are players only when somebody else acted first.
|
|
fn facing_both_blinds(first_actor: Seat) -> Option<()> {
|
|
(first_actor != Seat::SmallBlind).then_some(())
|
|
}
|
|
|
|
/// The first actor's jam frequency (`raise`) or fold.
|
|
pub fn push_frequency(variant: Variant, seat: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
lookup(push_chart(variant)?, seat, depth_bb, class, |s, c| Frequencies::aggressive(s.push[c]))
|
|
}
|
|
|
|
/// The big blind's response to a jam from `pusher` after the small blind folded.
|
|
pub fn call_vs_push(variant: Variant, pusher: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
lookup(push_chart(variant)?, pusher, depth_bb, class, |s, c| Frequencies::passive(s.call[c]))
|
|
}
|
|
|
|
/// The small blind's response to a jam from `pusher`, the big blind still to act.
|
|
pub fn sb_call_vs_push(variant: Variant, pusher: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
facing_both_blinds(pusher)?;
|
|
lookup(push_chart(variant)?, pusher, depth_bb, class, |s, c| Frequencies::passive(s.sb_call[c]))
|
|
}
|
|
|
|
/// The big blind's response to a jam from `pusher` that the small blind called.
|
|
pub fn bb_overcall_vs_push(variant: Variant, pusher: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
facing_both_blinds(pusher)?;
|
|
lookup(push_chart(variant)?, pusher, depth_bb, class, |s, c| Frequencies::passive(s.bb_overcall[c]))
|
|
}
|
|
|
|
/// The first actor's raise frequency or fold.
|
|
pub fn open_frequency(variant: Variant, seat: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
lookup(open_chart(variant)?, seat, depth_bb, class, |s, c| Frequencies::aggressive(s.open[c]))
|
|
}
|
|
|
|
/// The small blind facing the open of `opener`: fold / call / 3-bet.
|
|
pub fn sb_vs_open(variant: Variant, opener: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
facing_both_blinds(opener)?;
|
|
lookup(open_chart(variant)?, opener, depth_bb, class, |s, c| Frequencies::split(s.sb_defend[c]))
|
|
}
|
|
|
|
/// The big blind facing the open of `opener` (the small blind folded): fold / call / 3-bet.
|
|
pub fn vs_open(variant: Variant, opener: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
lookup(open_chart(variant)?, opener, depth_bb, class, |s, c| Frequencies::split(s.defend[c]))
|
|
}
|
|
|
|
/// The big blind facing the open of `opener` and the small blind's call: fold / call.
|
|
pub fn bb_vs_open_and_call(variant: Variant, opener: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
facing_both_blinds(opener)?;
|
|
lookup(open_chart(variant)?, opener, depth_bb, class, |s, c| Frequencies::passive(s.bb_overcall[c]))
|
|
}
|
|
|
|
/// The opener facing the big blind's 3-bet: fold / call / jam.
|
|
pub fn vs_three_bet(variant: Variant, opener: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
lookup(open_chart(variant)?, opener, depth_bb, class, |s, c| Frequencies::split(s.vs_three_bet[c]))
|
|
}
|
|
|
|
/// The opener facing the small blind's 3-bet: fold / call / jam.
|
|
pub fn vs_sb_three_bet(variant: Variant, opener: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
facing_both_blinds(opener)?;
|
|
lookup(open_chart(variant)?, opener, depth_bb, class, |s, c| Frequencies::split(s.vs_sb_three_bet[c]))
|
|
}
|
|
|
|
/// The big blind facing the opener's jam over the 3-bet: fold / call.
|
|
pub fn vs_jam(variant: Variant, opener: Seat, depth_bb: f64, class: ClassId) -> Option<Frequencies> {
|
|
lookup(open_chart(variant)?, opener, depth_bb, class, |s, c| Frequencies::passive(s.vs_jam[c]))
|
|
}
|