Files
pokerfreak/src/bin/nemesis.rs
T

44 lines
2.4 KiB
Rust

//! Stufe 5 of the synthetic lab: find the engine's NEMESIS — the worst-case individual opponent.
//!
//! Runs the diagonal CMA-ES (`sim::optimize`) over the 6-dim ruleset space to find the realistic
//! opponent the engine does worst against, an empirical best response in opponent-space. This is a
//! tighter robustness probe than the twin gate's "worst of six archetypes" floor: it searches the
//! whole continuous neighbourhood. The same optimizer tunes the engine's own hyperparameters once they
//! are exposed as a vector — that is the "polish, last" step the architecture names.
//!
//! Run: `cargo run --release --bin nemesis [deals] [generations] [seed]`.
use rechner::sim::optimize::worst_case_opponent;
const SEED: u64 = 0x5EED_0001;
// Higher budget now that the λ-evaluations run in parallel: more deals per evaluation tightens the
// nemesis EV, more generations let the CMA-ES converge further into the worst-case region. Overridable
// from argv (`nemesis [deals] [generations]`) for a fast scan before the full-budget confirmation.
const DEALS: u32 = 1000;
const GENERATIONS: u32 = 14;
fn main() {
// Same engine as the ladder: the live switches come from the environment (`sim::arm_env`).
rechner::sim::arm_env::apply_env();
let deals: u32 = std::env::args().nth(1).and_then(|s| s.parse().ok()).unwrap_or(DEALS);
let generations: u32 = std::env::args().nth(2).and_then(|s| s.parse().ok()).unwrap_or(GENERATIONS);
// Optional third argument: the search seed (hex with 0x, or decimal), for several independent searches.
let seed: u64 = std::env::args()
.nth(3)
.and_then(|s| match s.strip_prefix("0x") {
Some(h) => u64::from_str_radix(h, 16).ok(),
None => s.parse().ok(),
})
.unwrap_or(SEED);
println!("=== Stufe 5: der Nemesis — schlechtester Gegner der Engine (CMA-ES ueber den Regelraum) ===");
println!("{deals} Austeilungen je Auswertung, {generations} Generationen, Memory-Read.\n");
let (r, ev) = worst_case_opponent(deals, generations, seed);
println!("Nemesis-Regelwerk (realistische Schranken):");
println!(" call_margin {:.3} raise_at {:.3} bet_at {:.3}", r.call_margin, r.raise_at, r.bet_at);
println!(" open_at {:.3} bluff {:.3} size {:.3}", r.open_at, r.bluff, r.size);
println!("\nEngine-EV gegen den Nemesis: {ev:+.2} bb/100");
println!("(> 0 = die Engine schlaegt selbst ihren schlechtesten realistischen Gegner.)");
}