Files
pokerfreak/src/cfr/render_charts.rs
T
mmintelandClaude Opus 5.5 ba7b933a55 Mikro-Tabellen (keine Antes + Mikro-Rake, ein chartgen --mikro Lauf) eingebaut
Schalter aus: bit-identisch zum Live-Kern eb6275a6 auf allen 2776 echten Spots.
PREFLOP_VOLL+PREFLOP_MIKRO: 368/2776 kippen (13,3 %), gegen VOLL allein 243 (BB-Verteidigung enger).
Lange Leiter PREFLOP_VOLL am Mikro-Tisch (alte Tabellen): +3,95 +-1,04, kein Verlierer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:49:01 +01:00

226 lines
10 KiB
Rust

//! Rust source text of `preflop/generated_charts.rs` / `generated_charts_short.rs`: header,
//! convergence table, data.
use super::chart_deck::ChartDeck;
use super::frozen_spot::{OpenSpot, PushFoldSpot, SpotMeta};
use super::render_equity::wrapped;
use super::run_plan::{CFR_SEED, OPEN_DEPTHS, PUSH_FOLD_DEPTHS};
use super::spot_params::{
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 super::{generated_equity, generated_equity_short};
fn deck_lines(deck: ChartDeck) -> &'static str {
match deck {
ChartDeck::Full => "//! - 169 hold'em classes of the 52-card deck.\n",
ChartDeck::Short => {
"//! - Short deck: 81 classes of the 36-card deck (six to ace), short deck hand order. The other\n\
//! cells of the 13 x 13 grid are not in the deck and stay 0.\n"
}
}
}
fn header(deck: ChartDeck) -> String {
format!(
"\
//! GENERATED by `cargo run --release --bin chartgen -- charts{arg} > {charts}`.
//! Do not edit. Frozen output of `crate::cfr`; the equity table is `{equity}`
//! (`chartgen equity{arg} > {equity}`).
//!
//! Frequencies are permille (0..=1000) per hand class, indexed by `ClassId` of
//! `cfr::hand_class` (13 x 13 grid; pairs on the diagonal, suited above, offsuit below).
//! Layout and meaning of every field: `cfr::frozen_spot`.
//!
//! Abstraction (details in the `cfr` module docs; all numbers in `cfr::spot_params`):
{deck}\
//! - Exact combo weights with card removal between two players; for three players the deal
//! weight is the product of the three pairwise compatibilities (`cfr::tree3`).
//! - Class-vs-class all-in equity: seeded Monte Carlo, `hand::showdown::judge`. Three-way pots
//! split by the weaker pairwise equity of each hand, normalised (`cfr::three_way`).
{rake_note}//! - Blinds 0.5 / 1, 6-max. EP, MP, CO and BTN face BOTH blinds as players (three-player games);
//! the small blind as first actor faces the big blind. Players between the first actor and the
//! small blind are a multiway tax: each holds a continuing hand (top {wake:.0} % of combos) with
//! probability {wake_p:.2}; if one does, the first actor is simply called by that range.
//! - Push/fold: jam the effective stack or fold; the small blind calls or folds, then the big
//! blind calls or folds (separately after a small-blind fold and call). AOF is the same game
//! (`AOF_PUSH_FOLD` aliases `PUSH_FOLD`).
//! - Open/call/3-bet: open to {open} bb ({sb_open} bb from the small blind). The small blind folds,
//! calls or 3-bets to {sb_three_bet} bb; after its fold the big blind folds, calls or 3-bets to
//! {three_bet} bb, the opener folds, calls or jams, the big blind calls or folds the jam. After
//! the small blind's call the big blind folds or calls (no squeeze); after its 3-bet the big
//! blind folds and the opener folds, calls or jams. Lines that leave chips behind pay pot x
//! realised share: equity stretched by {spread} around the even share, then split by position
//! (out of position realises {oop} of its equity, {oop3} in 3-bet pots); all-in lines pay raw
//! equity.
//! - Solver: full-width CFR+ (regret floor 0, alternating players, average strategy weighted by
//! iteration). Exploitability is that of the permille strategy printed here, in micro-bb
//! (1e-6 bb): the sum of every player's best-response gain, as a share of every deal.
//! - The field behind only calls, so EP / MP still open wider than 6-max solver charts: read the
//! tables as abstraction-internal equilibria, not as solver output.
//!
//! Convergence per spot (`iterations`, `stable_since` = argmax chart final from that iteration,
//! exploitability in micro-bb at N/100, N/20, N/5, N/2, N):
//!
",
arg = deck.deck_argument(),
charts = deck.charts_file(),
equity = deck.equity_file(),
deck = deck_lines(deck),
rake_note = rake_lines(deck),
wake = WAKE_FRACTION * 100.0,
wake_p = WAKE_FRACTION,
open = OPEN_SIZE,
sb_open = SMALL_BLIND_OPEN_SIZE,
sb_three_bet = SMALL_BLIND_THREE_BET_SIZE,
three_bet = THREE_BET_SIZE,
spread = REALIZATION_SPREAD,
oop = REALIZATION_OOP_SINGLE_RAISED,
oop3 = REALIZATION_OOP_THREE_BET,
)
}
/// The default full-deck source text relabelled as the live micro rake set (`chartgen charts --rake
/// mikro` -> `preflop/generated_charts_mikro.rs`): the command line and the rake paragraph change,
/// nothing else (the data was solved with `ChartRake::Micro`).
pub fn as_micro(text: &str) -> String {
text.replacen(
"`cargo run --release --bin chartgen -- charts > src/preflop/generated_charts.rs`",
"`cargo run --release --bin chartgen -- charts --rake mikro > src/preflop/generated_charts_mikro.rs`",
1,
)
.replacen(
rake_lines(ChartDeck::Full),
"//! - Rake: the LIVE MICRO rule (`crate::rake::RakeRule::MICRO_BB`, NL 0.01/0.02, `ChartRake::Micro`):
//! an all-in 5 % of the pot rounded to half a big blind, capped at 10 bb; a pot with chips behind the
//! mean final rake of such flop pots at that stake. A pot won by a fold pays it on the matched pot
//! (uncalled chips go back; a 3-bet/fold pot of 5.5 bb pays 0.5 bb, `ChartRake::fold`). Used only under `RAKE_LIVE` (`preflop::generated_lookup`).
//! Antes of six seats are dead money in every pot, as in the default tables (rake is the only change).
",
1,
)
}
fn rake_lines(deck: ChartDeck) -> &'static str {
match deck {
ChartDeck::Full => "\
//! - 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.
",
ChartDeck::Short => "",
}
}
fn meta_line(label: &str, meta: &SpotMeta) -> String {
let curve: Vec<String> = meta.checkpoints.iter().map(|(_, e)| e.to_string()).collect();
format!(
"//! {label:<10} iterations {:>6} stable_since {:>6} exploitability {}\n",
meta.iterations,
meta.stable_since,
curve.join(" / ")
)
}
fn meta_source(meta: &SpotMeta) -> String {
let points: Vec<String> = meta.checkpoints.iter().map(|(t, e)| format!("({t}, {e})")).collect();
format!(
"SpotMeta {{ iterations: {}, stable_since: {}, checkpoints: [{}], exploitability_micro_bb: {} }}",
meta.iterations,
meta.stable_since,
points.join(", "),
meta.exploitability_micro_bb
)
}
fn row(name: &str, values: &[u16]) -> String {
format!(" {name}: [\n{} ],\n", wrapped(values, 24).lines().map(|l| format!(" {l}\n")).collect::<String>())
}
fn pair_row(name: &str, values: &[[u16; 2]]) -> String {
let flat: Vec<u16> = values.iter().flat_map(|p| p.iter().copied()).collect();
let lines: String = flat
.chunks(24)
.map(|c| {
let items: Vec<String> = c.chunks(2).map(|p| format!("[{}, {}]", p[0], p[1])).collect();
format!(" {},\n", items.join(", "))
})
.collect();
format!(" {name}: [\n{lines} ],\n")
}
fn push_spot_source(s: &PushFoldSpot) -> String {
format!(
" PushFoldSpot {{\n seat: Seat::{:?},\n depth_bb: {},\n{}{}{}{} meta: {},\n }},\n",
s.seat,
s.depth_bb,
row("push", &s.push),
row("call", &s.call),
row("sb_call", &s.sb_call),
row("bb_overcall", &s.bb_overcall),
meta_source(&s.meta)
)
}
fn open_spot_source(s: &OpenSpot) -> String {
format!(
" OpenSpot {{\n seat: Seat::{:?},\n depth_bb: {},\n{}{}{}{}{}{}{}{} meta: {},\n }},\n",
s.seat,
s.depth_bb,
row("open", &s.open),
pair_row("defend", &s.defend),
pair_row("vs_three_bet", &s.vs_three_bet),
row("vs_jam", &s.vs_jam),
pair_row("sb_defend", &s.sb_defend),
row("bb_overcall", &s.bb_overcall),
pair_row("vs_sb_three_bet", &s.vs_sb_three_bet),
row("sb_vs_jam", &s.sb_vs_jam),
meta_source(&s.meta)
)
}
fn equity_source(deck: ChartDeck) -> (u64, u32) {
match deck {
ChartDeck::Full => (generated_equity::SEED, generated_equity::SAMPLES),
ChartDeck::Short => (generated_equity_short::SEED, generated_equity_short::SAMPLES),
}
}
pub fn render_charts(deck: ChartDeck, push: &[PushFoldSpot], open: &[OpenSpot]) -> String {
let convergence: String = push
.iter()
.map(|s| meta_line(&format!("push {} {}", s.seat.label(), s.depth_bb), &s.meta))
.chain(open.iter().map(|s| meta_line(&format!("open {} {}", s.seat.label(), s.depth_bb), &s.meta)))
.collect();
let push_body: String = push.iter().map(push_spot_source).collect();
let open_body: String = open.iter().map(open_spot_source).collect();
let aof = match deck {
ChartDeck::Full => "\n/// All-in-or-fold has no other choice than push or fold: the same game, the same tables.\n\
pub static AOF_PUSH_FOLD: &[PushFoldSpot] = &PUSH_FOLD;\n",
ChartDeck::Short => "",
};
let (eq_seed, eq_samples) = equity_source(deck);
format!(
"{header}{convergence}//!\n\
//! Equity table: seed {eq_seed}, {eq_samples} samples per class pair. CFR seed {cfr_seed}.\n\n\
use crate::cfr::frozen_spot::{{OpenSpot, PushFoldSpot, SpotMeta}};\n\
use crate::cfr::seat::Seat;\n\n\
pub const EQUITY_SEED: u64 = {eq_seed};\n\
pub const EQUITY_SAMPLES: u32 = {eq_samples};\n\
pub const CFR_SEED: u64 = {cfr_seed};\n\
pub const PUSH_FOLD_DEPTHS: [u8; {nd}] = {push_depths:?};\n\
pub const OPEN_DEPTHS: [u8; {nod}] = {open_depths:?};\n\n\
pub static PUSH_FOLD: [PushFoldSpot; {np}] = [\n{push_body}];\n\n\
pub static OPEN: [OpenSpot; {no}] = [\n{open_body}];\n{aof}",
header = header(deck),
nd = PUSH_FOLD_DEPTHS.len(),
nod = OPEN_DEPTHS.len(),
push_depths = PUSH_FOLD_DEPTHS,
open_depths = OPEN_DEPTHS,
cfr_seed = CFR_SEED,
np = push.len(),
no = open.len(),
)
}