Files
pokerfreak/src/bin/engine_lbr.rs
T
mmintelandClaude Opus 5.5 08ad181f13 Merge claude/engine-lecks-angreifen-de7b88 (c205a05, Rake live) in exploit-live; BEKANNTE_SCHALTER + RERAISE_TIEFE/RERAISE_BLUFF (Spec)
Konflikte: table.rs (LBR6 choose() + HERO=gto), decide.rs (ICM push/fold + Light-3-Bet-Read +
Diag), advise.rs (scale_for mit steal, ICM-Pfad None), zaehler.py (riverBluffShown + Steal/Raise),
decide.py (Schalter vereinigt). Bit-identisch: Merge-Binary mit MDF_UNREAD=0, TURN_SPIEL=grund,
OPEN_JAM=1, RAKE_LIVE=1 reproduziert rake-live-leiter/-micro (7 Zeilen x 4, 300 Deals) exakt.
eichung_spec: riverBluffShown ist Showdown-Zaehler, kein Prior.

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

113 lines
6.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! LBR against the live engine on scenario S1 (plan M4, Messregel 1a): how much the best local counter
//! wins against the engine's default play, flop to river, button vs big blind in a single-raised pot.
//!
//! Exact range tracking (subsampling was measured biased: k=48 −112, k=96 −35 bb/100 against the exact
//! value on the real blueprint, `lbr::tests::bias_on_the_real_blueprint`). One hand costs ~27 s, so the
//! run is resumable: hand `i` is deterministic (`lbr::lbr_hand`), every result is appended to the out
//! file as `i value_bb` at once, and a restart computes only the missing hands.
//!
//! Run: `engine_lbr <out-file> <hands> [seed]`, threads from `POKERBENCH_THREADS` (default 1).
//! The engine runs with its default switches; the one env arm is `TURN_SPIEL=grund` (turn game, E3).
use rechner::blueprint::abstraktion::river_cuts;
use rechner::blueprint::engine_gegner::EngineGegner;
use rechner::blueprint::lbr::lbr_hand;
use rechner::blueprint::s1::{Abstraktion, S1};
use std::io::Write;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() < 3 {
eprintln!("engine_lbr <out-file> <hands> [seed]");
std::process::exit(2);
}
let out = std::path::PathBuf::from(&args[1]);
let haende: u64 = args[2].parse().expect("hands");
let seed: u64 = args.get(3).map(|x| x.parse().expect("seed")).unwrap_or(7);
let threads: usize = std::env::var("POKERBENCH_THREADS").ok().and_then(|x| x.parse().ok()).unwrap_or(1).max(1);
// TURN_SPIEL=grund (plan E3): the turn+river game with blueprint ranges plays the engine's turn
// where the blueprint recognises the spot (needs GRUNDSTRATEGIE: tables and checkpoint).
if std::env::var("TURN_SPIEL").as_deref() == Ok("grund") {
rechner::engine::turn_game::set_turn_player(rechner::engine::turn_game::TurnPlayer::Grund);
assert!(rechner::blueprint::ranges::grundstrategie().is_some(), "TURN_SPIEL=grund needs GRUNDSTRATEGIE with tables and checkpoint");
}
// SOLVER_RIVER=1|modell (stage A): the river solver plays the engine's heads-up river.
rechner::engine::river_spieler::set_river_spieler(rechner::engine::river_spieler::from_env());
rechner::engine::turn_game::set_turn_ueberall(rechner::engine::turn_game::turn_ueberall_from_env());
rechner::engine::flop_spieler::set_flop_spieler(rechner::engine::flop_spieler::from_env());
rechner::engine::river3_spieler::set_river3(rechner::engine::river3_spieler::from_env());
let (turn3, flop3) = rechner::engine::multi3_spieler::from_env();
rechner::engine::multi3_spieler::set_turn3(turn3);
rechner::engine::multi3_spieler::set_flop3(flop3);
if rechner::engine::river_spieler::river_spieler() == rechner::engine::river_spieler::RiverSpieler::An {
assert!(rechner::blueprint::ranges::grundstrategie().is_some(), "SOLVER_RIVER=1 on LBR needs GRUNDSTRATEGIE (else it measures the model path)");
}
let mut fertig = vec![None; haende as usize];
if let Ok(t) = std::fs::read_to_string(&out) {
for z in t.lines() {
let mut f = z.split_whitespace();
if let (Some(i), Some(v)) = (f.next().and_then(|x| x.parse::<usize>().ok()), f.next().and_then(|x| x.parse::<f64>().ok())) {
if i < fertig.len() {
fertig[i] = Some(v);
}
}
}
}
let offen: Vec<u64> = (0..haende).filter(|i| fertig[*i as usize].is_none()).collect();
eprintln!("{} of {haende} hands done, {} to go, {threads} threads", haende as usize - offen.len(), offen.len());
// The engine never sees the blueprint's classes, so the tables are not needed (flop/turn unclassed).
let s = S1::neu(Abstraktion { flop: None, turn: None, river: river_cuts(50, 1) });
// LBR_PROFIL (plan D1b): the engine holds this read on its LBR opponent, as a live request would
// carry it (`villains[].profile`, wire form). Unset = no read (the M4 baseline).
let g = match std::env::var("LBR_PROFIL") {
Ok(p) if !p.trim().is_empty() => {
let g = EngineGegner::mit_profil(&p).expect("LBR_PROFIL: wire profile");
eprintln!("engine read on LBR: {:?}", g.profil());
g
}
_ => EngineGegner::default(),
};
let next = AtomicUsize::new(0);
let datei = Mutex::new(std::fs::OpenOptions::new().create(true).append(true).open(&out).expect("out file"));
let werte = Mutex::new(fertig);
let t0 = std::time::Instant::now();
std::thread::scope(|sc| {
for _ in 0..threads {
sc.spawn(|| loop {
let j = next.fetch_add(1, Ordering::Relaxed);
let Some(&i) = offen.get(j) else { break };
let v = lbr_hand(&s, &g, i, seed, None);
writeln!(datei.lock().unwrap(), "{i} {v}").expect("write");
let mut w = werte.lock().unwrap();
w[i as usize] = Some(v);
let n = j + 1;
if n % 20 == 0 || n == offen.len() {
let (m, ci, k) = bericht(&w);
eprintln!("{n}/{} new, {k} total: LBR {m:+.1} ±{ci:.1} bb/100, {:.1} s/hand", offen.len(), t0.elapsed().as_secs_f64() * threads as f64 / n as f64);
}
});
}
});
let (m, ci, k) = bericht(&werte.lock().unwrap());
println!("LBR gegen Engine (S1, exakt): {m:+.1} ±{ci:.1} bb/100 ueber {k} Haende");
}
/// Mean over both seats and its 95 % half-width, in bb/100, over the hands done.
fn bericht(w: &[Option<f64>]) -> (f64, f64, usize) {
let mut t = [(0.0, 0.0, 0usize); 2];
for (i, v) in w.iter().enumerate() {
if let Some(v) = v {
t[i % 2].0 += v;
t[i % 2].1 += v * v;
t[i % 2].2 += 1;
}
}
let mean = |x: (f64, f64, usize)| x.0 / x.2.max(1) as f64;
let var = |x: (f64, f64, usize)| (x.1 / x.2.max(1) as f64 - mean(x).powi(2)) / x.2.max(1) as f64;
(50.0 * (mean(t[0]) + mean(t[1])), 98.0 * (var(t[0]) + var(t[1])).sqrt(), t[0].2 + t[1].2)
}