Files
pokerfreak/src/bin/aivat_export.rs
T
mmintelandClaude Opus 5.5 59c8bc90b8 M5: AIVAT fuer echte Haende, als Linse in Runner/Statistik/Liveabgleich/Einblick
lesen/aivat.py: Kartenkorrektur je Street gegen ein Range-Modell (Vorflop-Stufe
+ VPIP/PFR, verengt durch fruehere Aktionen), gezeigte Karten nur nach All-in-
Sperre, Gegner-Aktionen unkorrigiert, eigene Aktion 0, beta = 1. Quelle: Rechnung
aus dem Client-Log, sonst Rueckfall aus den eigenen Zuegen.

Sim mit bekannter Wahrheit (src/bin/aivat_export.rs, 50 400 Haende):
AIVAT - roh +3,5 +-11,2 bb/100, Halbbreite -10,7 %. Echte Haende (2762 Cash):
AIVAT - roh -4,4 +-11,3, Halbbreite -7,0 % (volles Log -11,1 %), All-in-EV
allein -0,2 %. Z1 in 30 000 Haenden ab ~10,2-10,7 bb/100 wahrer Winrate.
Messung und Dateien: messung_aivat/ERGEBNIS.md. Specs tests/aivat_spec.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 23:04:01 +01:00

102 lines
4.7 KiB
Rust

//! Plan M5: hands with KNOWN truth for the live AIVAT estimator (`lesen/aivat.py`).
//!
//! The live estimator only sees what a real table shows: hero's cards, the board as far as it was
//! dealt, the action history, and opponents' cards when they were revealed at showdown. This binary
//! plays the real engine against the sim opponents and writes exactly that, one JSON line per hand,
//! plus hero's net and the sim's own board-luck term (`sim::luck`, which sees every hole card).
//! Over many hands the mean of `net - correction` must equal the mean of `net` (unbiasedness), and
//! the half-width shows the variance gain - both against the true expectation of the engine here.
//!
//! Run: `aivat_export <out.jsonl> <deals-per-opponent> [start-deal]` (hero in every seat, 6-max).
use rechner::game::{SeenAction, Street};
use rechner::rng::Rng;
use rechner::sim::opponent::Opponent;
use rechner::sim::reader::Style;
use rechner::sim::reads::opponent_profile;
use rechner::sim::table::{deal, play_hand_history, HandRead, HandSetup, TableCost};
use std::io::Write;
fn main() {
let a: Vec<String> = std::env::args().collect();
let out = &a[1];
let deals: u64 = a[2].parse().expect("deals");
let start: u64 = a.get(3).map(|s| s.parse().expect("start")).unwrap_or(0);
let mut f = std::io::BufWriter::new(std::fs::File::create(out).expect("out"));
let gegner = [
("reg", Opponent::Reader(Style::Reg)),
("fish", Opponent::Reader(Style::Fish)),
("station", Opponent::CallingStation),
("maniac", Opponent::Reader(Style::Maniac)),
];
for (name, opp) in gegner {
let prof = opponent_profile(opp);
for d in start..start + deals {
let (cards, _) = deal(6, Rng::seeded(0xA17A_0000 ^ d.wrapping_mul(0x9E37_79B9_7F4A_7C15)));
for seat in 1..=6u8 {
let hand = HandSetup {
deal: &cards,
hero_seat: seat,
opponent: opp,
stack_bb: 100.0,
seed: d.wrapping_mul(0xD1B5_4A32_D192_ED03) ^ seat as u64,
read: HandRead::Oracle,
};
let (r, hist) = play_hand_history(&hand, TableCost::FREE);
let mut folded = [false; 6];
let mut top = 0usize;
let mut verlauf = Vec::new();
for h in &hist {
if h.action == SeenAction::Fold {
folded[h.seat as usize - 1] = true;
}
top = top.max(h.street as usize);
let amt = h.amount.map(|x| format!("{x:.6}")).unwrap_or_else(|| "null".into());
verlauf.push(format!(
"{{\"street\":\"{}\",\"seat\":{},\"action\":\"{}\",\"amount\":{}}}",
h.street.name(),
h.seat,
h.action.name(),
amt
));
}
let live: Vec<usize> = (0..6).filter(|i| !folded[*i]).collect();
let board_len = if live.len() >= 2 { 5 } else { Street::ALL[top].board_len() };
let brett: Vec<String> = cards.board[..board_len].iter().map(|c| format!("\"{}\"", c.short())).collect();
let gezeigt: Vec<String> = if live.len() >= 2 {
live.iter()
.filter(|i| **i != seat as usize - 1)
.map(|i| {
let h = cards.holes[*i];
format!("\"{}\":[\"{}\",\"{}\"]", i + 1, h[0].short(), h[1].short())
})
.collect()
} else {
Vec::new()
};
let profil = match prof {
Some(p) => format!(
"{{\"vpip\":{},\"pfr\":{},\"hands\":1000}}",
p.vpip.unwrap_or(0.3),
p.pfr.unwrap_or(0.15)
),
None => "null".into(),
};
let h = cards.holes[seat as usize - 1];
writeln!(
f,
"{{\"id\":\"{name}-{d}-{seat}\",\"gegner\":\"{name}\",\"held\":{seat},\"hole\":[\"{}\",\"{}\"],\"brett\":[{}],\"verlauf\":[{}],\"gezeigt\":{{{}}},\"profil\":{profil},\"netto_bb\":{:.6},\"glueck_sim\":{:.6}}}",
h[0].short(),
h[1].short(),
brett.join(","),
verlauf.join(","),
gezeigt.join(","),
r.hero_net,
r.luck
)
.unwrap();
}
}
}
}