Echte Preflop-Spots 14.11. (2776): 63,5 % -> 94,5 % aus Loesungen. - cfr::teilspiel + teilspiel_plan: 2765 geloeste Teilspiele (vs raise mit 0-2 Callern, vs 3-bet, kalt vs 3-bet, vs 4-bet, Limp-Pots; 20-200 bb), exakte Exploitability je Zelle (Median 18-88 µbb). Ohne Antes wie live Micro (Ante 0). - preflop::teilspiel_lookup: Linie -> Zellfamilie, pseudo-harmonische Uebersetzung der echten Raise-Groesse, Tabellenantwort + Groesseneffekt bei Opens != 2,5 bb. - multi_lookup: Multi-Tabellen ueber 100 bb (geklemmt; Deep-Datei vorbereitet). - Aus: bit-identisch zum Live-Kern auf allen 2776 Spots (tests/preflop_voll.rs). - Nachspiel an: 202 Aktionen (7,3 %) kippen; Leiter-Pilot +16,26 +-5,55 bb/100, kein Profil verliert; LBR S1 identisch (beginnt am Flop). - decide.py / roentgen.py kennen PREFLOP_VOLL; Schalter-Diff in messung_preflop/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
325 lines
14 KiB
Rust
325 lines
14 KiB
Rust
//! Rust source text of `preflop/generated_charts_multi.rs`: header with every assumption, the
|
|
//! evidence table (deviation from the one-defender charts, Gegenprobe), data.
|
|
//!
|
|
//! The renderer works on records with integer metrics only, so the frozen tables can be turned
|
|
//! back into records and re-rendered byte for byte (`tests/cfr_multi.rs`).
|
|
|
|
use super::defenders::{Lineup, MAX_DEFENDERS};
|
|
use super::environment::Environment;
|
|
use super::frozen_multi::{encode, BaselineSpot, MultiSpot};
|
|
use super::multi_solve::{mean_abs_difference, width, SolvedMulti, CHECK_SEED};
|
|
use super::run_plan::{CFR_SEED, MULTI_CHECK_SAMPLES, MULTI_ITERATIONS, OPEN_DEPTHS};
|
|
use super::seat::Seat;
|
|
use super::spot_params::{
|
|
IN_POSITION_THREE_BET_SIZE, OPEN_SIZE, REALIZATION_OOP_SINGLE_RAISED, REALIZATION_OOP_THREE_BET,
|
|
REALIZATION_SPREAD, SMALL_BLIND_OPEN_SIZE, SMALL_BLIND_THREE_BET_SIZE, THREE_BET_SIZE, WAKE_FRACTION,
|
|
};
|
|
use crate::fault::Fault;
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct MultiRecord {
|
|
pub seat: Seat,
|
|
pub defenders: usize,
|
|
pub depth_bb: u8,
|
|
pub iterations: u32,
|
|
pub open_drift_permille: u32,
|
|
pub check_samples: u32,
|
|
pub in_sample_micro_bb: i32,
|
|
pub holdout_micro_bb: i32,
|
|
pub exact_micro_bb: Option<u32>,
|
|
pub rows: Vec<(String, u8, Vec<u16>)>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct BaselineRecord {
|
|
pub seat: Seat,
|
|
pub depth_bb: u8,
|
|
pub iterations: u32,
|
|
pub open: Vec<u16>,
|
|
}
|
|
|
|
fn micro(x: f64) -> i32 {
|
|
(x * 1e6).round().clamp(i32::MIN as f64, i32::MAX as f64) as i32
|
|
}
|
|
|
|
pub fn record(solved: &SolvedMulti) -> MultiRecord {
|
|
MultiRecord {
|
|
seat: solved.seat,
|
|
defenders: solved.defenders,
|
|
depth_bb: solved.depth_bb,
|
|
iterations: solved.iterations,
|
|
open_drift_permille: solved.open_drift_permille,
|
|
check_samples: solved.check.samples,
|
|
in_sample_micro_bb: micro(solved.check.in_sample_total()),
|
|
holdout_micro_bb: micro(solved.check.holdout_total()),
|
|
exact_micro_bb: solved.exact.map(|e| micro(e).max(0) as u32),
|
|
rows: solved.rows.clone(),
|
|
}
|
|
}
|
|
|
|
/// Records of the frozen tables.
|
|
pub fn records(spots: &[MultiSpot]) -> Result<Vec<MultiRecord>, Fault> {
|
|
spots
|
|
.iter()
|
|
.map(|s| {
|
|
Ok(MultiRecord {
|
|
seat: s.seat,
|
|
defenders: s.defenders as usize,
|
|
depth_bb: s.depth_bb,
|
|
iterations: s.iterations,
|
|
open_drift_permille: s.open_drift_permille,
|
|
check_samples: s.check_samples,
|
|
in_sample_micro_bb: s.in_sample_micro_bb,
|
|
holdout_micro_bb: s.holdout_micro_bb,
|
|
exact_micro_bb: s.exact_micro_bb,
|
|
rows: s
|
|
.rows
|
|
.iter()
|
|
.map(|r| Ok((r.name.to_string(), r.actions, super::frozen_multi::decode(r.data)?)))
|
|
.collect::<Result<_, Fault>>()?,
|
|
})
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
pub fn baseline_records(spots: &[BaselineSpot]) -> Result<Vec<BaselineRecord>, Fault> {
|
|
spots
|
|
.iter()
|
|
.map(|s| {
|
|
Ok(BaselineRecord {
|
|
seat: s.seat,
|
|
depth_bb: s.depth_bb,
|
|
iterations: s.iterations,
|
|
open: super::frozen_multi::decode(s.open)?,
|
|
})
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
/// Open permille of a record.
|
|
pub fn record_open(r: &MultiRecord) -> Vec<u16> {
|
|
r.rows.iter().find(|row| row.0 == "open").map(|row| row.2.clone()).unwrap_or_default()
|
|
}
|
|
|
|
/// The evidence of one spot, in permille of all combos (widths and differences) and micro-bb.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct Evidence {
|
|
pub seat: Seat,
|
|
pub defenders: usize,
|
|
pub depth_bb: u8,
|
|
pub width: u32,
|
|
pub one_defender_width: u32,
|
|
/// Combo-weighted mean |open frequency - one-defender open frequency|.
|
|
pub vs_one_defender: u32,
|
|
/// The same against the two-blind table `generated_charts::OPEN` (two defenders only).
|
|
pub vs_two_defender_table: Option<u32>,
|
|
}
|
|
|
|
fn permille(x: f64) -> u32 {
|
|
(x * 1000.0).round().max(0.0) as u32
|
|
}
|
|
|
|
/// `reference`: the open rows of `generated_charts::OPEN` by seat and depth.
|
|
pub fn evidence(
|
|
env: &Environment,
|
|
spots: &[MultiRecord],
|
|
baselines: &[BaselineRecord],
|
|
reference: &[(Seat, u8, Vec<u16>)],
|
|
) -> Vec<Evidence> {
|
|
spots
|
|
.iter()
|
|
.map(|s| {
|
|
let open = record_open(s);
|
|
let base = baselines
|
|
.iter()
|
|
.find(|b| b.seat == s.seat && b.depth_bb == s.depth_bb)
|
|
.map(|b| b.open.clone())
|
|
.unwrap_or_default();
|
|
let two = (s.defenders == 2)
|
|
.then(|| reference.iter().find(|(seat, d, _)| *seat == s.seat && *d == s.depth_bb))
|
|
.flatten()
|
|
.map(|(_, _, row)| permille(mean_abs_difference(env, &open, row)));
|
|
Evidence {
|
|
seat: s.seat,
|
|
defenders: s.defenders,
|
|
depth_bb: s.depth_bb,
|
|
width: permille(width(env, &open)),
|
|
one_defender_width: permille(width(env, &base)),
|
|
vs_one_defender: permille(mean_abs_difference(env, &open, &base)),
|
|
vs_two_defender_table: two,
|
|
}
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn evidence_line(e: &Evidence, r: &MultiRecord) -> String {
|
|
let lineup = Lineup::new(e.seat, e.defenders).map(|l| {
|
|
let d: Vec<&str> = l.defenders.iter().map(|p| p.label()).collect();
|
|
d.join("+")
|
|
});
|
|
let exact = r.exact_micro_bb.map_or(" -".to_string(), |x| format!("{x:>6}"));
|
|
let two = e.vs_two_defender_table.map_or(" -".to_string(), |x| format!("{x:>3}"));
|
|
format!(
|
|
"//! {:<3} {:>3} {:<14} {:>4} {:>4} {:>+5} {:>4} {two} {exact} {:>6} {:>6} {:>3}\n",
|
|
e.seat.label(),
|
|
e.depth_bb,
|
|
lineup.unwrap_or_default(),
|
|
e.width,
|
|
e.one_defender_width,
|
|
e.width as i64 - e.one_defender_width as i64,
|
|
e.vs_one_defender,
|
|
r.in_sample_micro_bb,
|
|
r.holdout_micro_bb,
|
|
r.open_drift_permille
|
|
)
|
|
}
|
|
|
|
fn header(evidence: &[Evidence], spots: &[MultiRecord]) -> String {
|
|
let lines: String = evidence.iter().zip(spots).map(|(e, r)| evidence_line(e, r)).collect();
|
|
format!(
|
|
"\
|
|
//! GENERATED by `cargo run --release --bin chartgen -- multi > src/preflop/generated_charts_multi.rs`.
|
|
//! Do not edit. Frozen output of `crate::cfr` (`multi_tree`, `multi_walk`, `multi_solve`);
|
|
//! equity table `src/cfr/generated_equity.rs`. Layout of the rows: `cfr::frozen_multi`.
|
|
//!
|
|
//! Open / call / 3-bet with ONE TO FOUR modelled defenders behind the first actor (full deck).
|
|
//! Every assumption (numbers in `cfr::spot_params`):
|
|
//! - Players: the first actor and the last k places behind it (k = 1..{max}; the big blind is
|
|
//! always one of them, k = 1 is the one-defender game of `open_game`, k = 2 the two-blind game
|
|
//! of `open3_game`). Places before the first defender are the wake field: each continues with
|
|
//! probability {wake:.2} holding a top-{wake_pct:.0} % hand, independently, its cards block
|
|
//! nothing; if one does it calls and the defenders take no decision.
|
|
//! - Tree: the opener raises to {open} bb ({sb_open} from the small blind) or folds. Each defender
|
|
//! in turn folds, calls or 3-bets while nobody has entered; after a call the defenders behind
|
|
//! only fold or overcall (no squeeze); after a 3-bet everybody behind folds (no cold 4-bet or
|
|
//! cold call) and the opener folds, calls or jams, the 3-bettor calls or folds the jam.
|
|
//! 3-bet sizes: big blind {three_bet}, small blind {sb_three_bet}, a defender who is not a blind
|
|
//! {ip_three_bet} bb.
|
|
//! - Hands: the 169 classes; every deal is real disjoint combos for all players (exact card
|
|
//! removal between all of them).
|
|
//! - Payoffs: net bb incl. posted blinds; the field's small blind is dead money. All-in pots pay
|
|
//! raw equity; pots with chips behind pay pot x realised share: each hand's raw share is its
|
|
//! weakest pairwise equity, normalised (`cfr::multi_shares`, two hands: the equity itself),
|
|
//! stretched by {spread} around the even share, the player last to act postflop weighted 1.0,
|
|
//! everybody else {oop} ({oop3} in 3-bet pots), normalised again.
|
|
//! - Rake (`crate::rake`, measured at the table 1000/2000, ante 0.16 bb): a fold pays none, an
|
|
//! all-in 5 % of the pot with the antes, capped at 1 bb; a pot with chips behind the mean rake of
|
|
//! such flop pots at that table. The pot is split after the rake, so the games are not zero-sum.
|
|
//! Antes of six seats are dead money in every pot; the winner of a fold takes them too.
|
|
//! - Solver: chance-sampled CFR+ (one deal per iteration, every player traverses with its own
|
|
//! class open over all 169 classes, the others' actions weighted by their strategy), regrets
|
|
//! floored at 0, average weighted by iteration; {iterations} iterations from seed {cfr_seed}.
|
|
//! Output: the average strategy rounded to permille.
|
|
//! - Gegenprobe: every player's best response to the others' frozen permille strategy, found
|
|
//! bottom-up over {samples} seeded deals (seed {check_seed}) and re-measured on {samples}
|
|
//! independent ones; the sum of the gains is the exploitability (micro-bb per deal). The first
|
|
//! is biased up, the second down. With one and two defenders the frozen strategy is also mapped
|
|
//! into the exact full-width game (`open_game` / `open3_game`) and its exact exploitability is
|
|
//! given.
|
|
//! - Baseline: the one-defender chart of each seat (opener against the big blind alone,
|
|
//! `open_game`), full-width CFR+ as in `generated_charts` (`BASELINE`).
|
|
//!
|
|
//! Evidence per spot. Widths and differences in permille of all 1326 combos (combo-weighted);
|
|
//! `1-def` the baseline's width, `diff` the change, `|d|` the mean absolute difference of the open
|
|
//! frequency against the baseline, `2-tab` against the two-blind table of `generated_charts`
|
|
//! (two defenders only: the same game, solved full width there); exploitability in micro-bb:
|
|
//! `exact` (k <= 2), `in`/`out` sampled; `drift` = mean change of the open chart between N/2 and N.
|
|
//!
|
|
//! seat bb defenders width 1-def diff |d| 2-tab exact in out drift
|
|
{lines}",
|
|
max = MAX_DEFENDERS,
|
|
wake = WAKE_FRACTION,
|
|
wake_pct = WAKE_FRACTION * 100.0,
|
|
open = OPEN_SIZE,
|
|
sb_open = SMALL_BLIND_OPEN_SIZE,
|
|
three_bet = THREE_BET_SIZE,
|
|
sb_three_bet = SMALL_BLIND_THREE_BET_SIZE,
|
|
ip_three_bet = IN_POSITION_THREE_BET_SIZE,
|
|
spread = REALIZATION_SPREAD,
|
|
oop = REALIZATION_OOP_SINGLE_RAISED,
|
|
oop3 = REALIZATION_OOP_THREE_BET,
|
|
iterations = spots.first().map_or(MULTI_ITERATIONS, |r| r.iterations),
|
|
cfr_seed = CFR_SEED,
|
|
samples = spots.first().map_or(MULTI_CHECK_SAMPLES, |r| r.check_samples),
|
|
check_seed = CHECK_SEED,
|
|
)
|
|
}
|
|
|
|
fn row_source(name: &str, actions: u8, values: &[u16]) -> String {
|
|
format!(" MultiRow {{ name: {name:?}, actions: {actions}, data: \"{}\" }},\n", encode(values))
|
|
}
|
|
|
|
fn spot_source(r: &MultiRecord) -> String {
|
|
let rows: String = r.rows.iter().map(|(n, a, v)| row_source(n, *a, v)).collect();
|
|
let exact = r.exact_micro_bb.map_or("None".to_string(), |x| format!("Some({x})"));
|
|
format!(
|
|
" MultiSpot {{\n seat: Seat::{:?},\n defenders: {},\n depth_bb: {},\n iterations: {},\n open_drift_permille: {},\n check_samples: {},\n in_sample_micro_bb: {},\n holdout_micro_bb: {},\n exact_micro_bb: {exact},\n rows: &[\n{rows} ],\n }},\n",
|
|
r.seat, r.defenders, r.depth_bb, r.iterations, r.open_drift_permille, r.check_samples, r.in_sample_micro_bb, r.holdout_micro_bb
|
|
)
|
|
}
|
|
|
|
fn baseline_source(b: &BaselineRecord) -> String {
|
|
format!(
|
|
" BaselineSpot {{ seat: Seat::{:?}, depth_bb: {}, iterations: {}, open: \"{}\" }},\n",
|
|
b.seat,
|
|
b.depth_bb,
|
|
b.iterations,
|
|
encode(&b.open)
|
|
)
|
|
}
|
|
|
|
/// The whole file. `spots` in plan order (seat, defenders, depth), `baselines` in (seat, depth).
|
|
pub fn render_multi(
|
|
env: &Environment,
|
|
spots: &[MultiRecord],
|
|
baselines: &[BaselineRecord],
|
|
reference: &[(Seat, u8, Vec<u16>)],
|
|
) -> String {
|
|
let evidence = evidence(env, spots, baselines, reference);
|
|
let base: String = baselines.iter().map(baseline_source).collect();
|
|
let body: String = spots.iter().map(spot_source).collect();
|
|
format!(
|
|
"{header}\n\
|
|
use crate::cfr::frozen_multi::{{BaselineSpot, MultiRow, MultiSpot}};\n\
|
|
use crate::cfr::seat::Seat;\n\n\
|
|
pub const MULTI_ITERATIONS: u32 = {iterations};\n\
|
|
pub const CHECK_SAMPLES: u32 = {samples};\n\
|
|
pub const OPEN_DEPTHS: [u8; {nd}] = {depths:?};\n\n\
|
|
pub static BASELINE: [BaselineSpot; {nb}] = [\n{base}];\n\n\
|
|
pub static MULTI: [MultiSpot; {ns}] = [\n{body}];\n",
|
|
header = header(&evidence, spots),
|
|
iterations = spots.first().map_or(MULTI_ITERATIONS, |r| r.iterations),
|
|
samples = spots.first().map_or(MULTI_CHECK_SAMPLES, |r| r.check_samples),
|
|
nd = OPEN_DEPTHS.len(),
|
|
depths = OPEN_DEPTHS,
|
|
nb = baselines.len(),
|
|
ns = spots.len(),
|
|
)
|
|
}
|
|
|
|
/// Tiefen der zweiten Multi-Datei (`generated_charts_multi_deep`, Schalter `PREFLOP_VOLL`).
|
|
pub const DEEP_DEPTHS: [u8; 2] = [150, 200];
|
|
|
|
/// Die Datei `generated_charts_multi_deep.rs`: dasselbe Format wie `render_multi`, eigene Namen
|
|
/// (`DEEP_DEPTHS`, `BASELINE_DEEP`, `MULTI_DEEP`), kein Vergleich mit den Zwei-Blind-Tabellen (die
|
|
/// gibt es nur bis 100 bb).
|
|
pub fn render_multi_deep(env: &Environment, spots: &[MultiRecord], baselines: &[BaselineRecord]) -> String {
|
|
let text = render_multi(env, spots, baselines, &[]);
|
|
let alt = format!("pub const OPEN_DEPTHS: [u8; {}] = {:?};", OPEN_DEPTHS.len(), OPEN_DEPTHS);
|
|
let neu = format!("pub const DEEP_DEPTHS: [u8; {}] = {:?};", DEEP_DEPTHS.len(), DEEP_DEPTHS);
|
|
text.replacen("chartgen -- multi > src/preflop/generated_charts_multi.rs", "chartgen -- multi-deep > src/preflop/generated_charts_multi_deep.rs", 1)
|
|
.replacen(&alt, &neu, 1)
|
|
.replacen("pub static BASELINE:", "pub static BASELINE_DEEP:", 1)
|
|
.replacen("pub static MULTI:", "pub static MULTI_DEEP:", 1)
|
|
}
|
|
|
|
/// `(seat, defenders, depth)` of every multi spot, seat-major.
|
|
pub fn multi_plan() -> Vec<(Seat, usize, u8)> {
|
|
Seat::ALL
|
|
.iter()
|
|
.flat_map(|s| {
|
|
(1..=super::defenders::max_defenders(*s)).flat_map(move |k| OPEN_DEPTHS.iter().map(move |d| (*s, k, *d)))
|
|
})
|
|
.collect()
|
|
}
|