SOLVER_ITER: feste Iterationszahl je Solver-Art (reine Messschalter), SOLVER_ITER_LOG zaehlt die Live-Iterationen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -131,14 +131,15 @@ pub fn solve_flop(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<C
|
||||
let nodes = game.nodes.len();
|
||||
let mut solver = TrSolver::new(game, hands, board, Some(cfg.turn_cards)).with_river_equity(board);
|
||||
let mut done = 0;
|
||||
while done < cfg.iterations {
|
||||
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::FsFlop, cfg.iterations) {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if crate::engine::frist::thread_cpu_ms() - cpu0 > cfg.budget_ms || crate::engine::frist::notbremse() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if done < MIN_ITERS {
|
||||
crate::engine::frist::iter_log(crate::engine::frist::Art::FsFlop, done as u64);
|
||||
if done < crate::engine::frist::iter_min(crate::engine::frist::Art::FsFlop, MIN_ITERS) {
|
||||
return None;
|
||||
}
|
||||
let strategy = solver.strategy();
|
||||
|
||||
+106
-1
@@ -65,7 +65,112 @@ pub fn left_ms(total_ms: f64) -> f64 {
|
||||
/// count, so ladder and LBR results do not depend on machine load (read once).
|
||||
pub fn fixed() -> bool {
|
||||
static FIXED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
FEST_HIER.with(Cell::get) || *FIXED.get_or_init(|| std::env::var("SOLVER_ZEIT").as_deref() == Ok("fest"))
|
||||
FEST_HIER.with(Cell::get) || *FIXED.get_or_init(|| std::env::var("SOLVER_ZEIT").as_deref() == Ok("fest")) || iter_aktiv()
|
||||
}
|
||||
|
||||
/// Measurement switch `SOLVER_ITER=<spec>` (NOT a live switch: not in `kern_schalter.txt`, not in `BEKANNTE_SCHALTER`): every
|
||||
/// postflop solve loop ignores time and the emergency brake (as `SOLVER_ZEIT=fest`: `fixed()` is true) and runs exactly the
|
||||
/// iterations the spec names for its kind, so the same engine state gives bit-identical answers at a fixed amount of work.
|
||||
/// Spec: `kind:N` pairs separated by `,`, e.g. `hu_river:100,hu_turn:40,mw_flop:3000`. A kind without a pair runs its own full
|
||||
/// cap (as `fest`); an empty spec or `1` is plain `fest`. N is counted on the solver's outer iteration counter (one `iterate()`
|
||||
/// call). An explicit N also lowers the solver's own floor (`MIN_ITERS`) to N, so a spot is never dropped for time. Staged
|
||||
/// multiway solves (`SOLVER3_ALLE`) always take their first, full stage (the live fallback to smaller stages is a time decision).
|
||||
/// Kinds: `hu_river`, `hu_turn`, `hu_turn_breit` (the second turn solve of `tgstark=breit`), `hu_flop` (the `solver_kern`
|
||||
/// core); `rs_river` (`river_spieler`), `tg_turn` (`turn_game`), `fs_flop` (`flop_spieler`); `mw_flop`, `mw_turn`
|
||||
/// (`multi3_spieler`), `mw_river` (`river3_spieler`).
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum Art {
|
||||
HuRiver,
|
||||
HuTurn,
|
||||
HuTurnBreit,
|
||||
HuFlop,
|
||||
RsRiver,
|
||||
TgTurn,
|
||||
FsFlop,
|
||||
MwFlop,
|
||||
MwTurn,
|
||||
MwRiver,
|
||||
}
|
||||
|
||||
impl Art {
|
||||
pub const ALLE: [Art; 10] = [Art::HuRiver, Art::HuTurn, Art::HuTurnBreit, Art::HuFlop, Art::RsRiver, Art::TgTurn, Art::FsFlop, Art::MwFlop, Art::MwTurn, Art::MwRiver];
|
||||
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
Art::HuRiver => "hu_river",
|
||||
Art::HuTurn => "hu_turn",
|
||||
Art::HuTurnBreit => "hu_turn_breit",
|
||||
Art::HuFlop => "hu_flop",
|
||||
Art::RsRiver => "rs_river",
|
||||
Art::TgTurn => "tg_turn",
|
||||
Art::FsFlop => "fs_flop",
|
||||
Art::MwFlop => "mw_flop",
|
||||
Art::MwTurn => "mw_turn",
|
||||
Art::MwRiver => "mw_river",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The parsed `SOLVER_ITER` (read once): `None` = switch unset.
|
||||
fn iter_spec() -> &'static Option<Vec<(Art, u32)>> {
|
||||
static SPEC: std::sync::OnceLock<Option<Vec<(Art, u32)>>> = std::sync::OnceLock::new();
|
||||
SPEC.get_or_init(|| {
|
||||
let v = std::env::var("SOLVER_ITER").ok()?;
|
||||
Some(
|
||||
v.split(',')
|
||||
.filter_map(|t| {
|
||||
let (k, n) = t.trim().split_once(':')?;
|
||||
let art = Art::ALLE.into_iter().find(|a| a.name() == k.trim())?;
|
||||
Some((art, n.trim().parse::<u32>().ok().filter(|n| *n > 0)?))
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// `SOLVER_ITER` is set: deterministic measurement mode (see `Art`).
|
||||
pub fn iter_aktiv() -> bool {
|
||||
iter_spec().is_some()
|
||||
}
|
||||
|
||||
/// The iteration count `SOLVER_ITER` names for `art`, if any.
|
||||
pub fn iter_vorgabe(art: Art) -> Option<u32> {
|
||||
iter_spec().as_ref()?.iter().find(|(a, _)| *a == art).map(|(_, n)| *n)
|
||||
}
|
||||
|
||||
/// Iteration cap of a solve loop: the spec's N for `art`, else `standard` (the unchanged cap).
|
||||
pub fn iter_cap(art: Art, standard: u32) -> u32 {
|
||||
iter_vorgabe(art).unwrap_or(standard)
|
||||
}
|
||||
|
||||
/// Fewest iterations a solve may rest on: `standard`, but never above an explicit N.
|
||||
pub fn iter_min(art: Art, standard: u32) -> u32 {
|
||||
iter_vorgabe(art).map_or(standard, |n| n.min(standard))
|
||||
}
|
||||
|
||||
/// Diagnostic `SOLVER_ITER_LOG=1`: one stderr line per finished solve loop with its kind and the iterations it ran.
|
||||
pub fn iter_log(art: Art, done: u64) {
|
||||
static LOG: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
if *LOG.get_or_init(|| std::env::var("SOLVER_ITER_LOG").is_ok_and(|v| !v.is_empty() && v != "0")) {
|
||||
eprintln!("SOLVER_ITER_LOG\t{}\t{done}", art.name());
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static BREIT: Cell<bool> = const { Cell::new(false) };
|
||||
}
|
||||
|
||||
/// Runs `f` marked as the second turn solve of `tgstark=breit` (its own kind `hu_turn_breit`).
|
||||
pub fn breit_dabei<R>(f: impl FnOnce() -> R) -> R {
|
||||
let vorher = BREIT.with(|b| b.replace(true));
|
||||
let r = f();
|
||||
BREIT.with(|b| b.set(vorher));
|
||||
r
|
||||
}
|
||||
|
||||
/// Inside `breit_dabei`.
|
||||
pub fn breit_hier() -> bool {
|
||||
BREIT.with(Cell::get)
|
||||
}
|
||||
|
||||
/// While the guard lives, solvers on THIS thread run their full iteration count whatever the load (as
|
||||
|
||||
@@ -682,8 +682,9 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
let cpu_stufe = crate::engine::frist::thread_cpu_ms();
|
||||
let mut done = 0u32;
|
||||
let mut zu_gross = false;
|
||||
let min_iter = if alle() && letzte { MIN_ITERS_KLEIN } else { MIN_ITERS };
|
||||
while done < ITERS {
|
||||
let art = if spot.street == Street::Turn { crate::engine::frist::Art::MwTurn } else { crate::engine::frist::Art::MwFlop };
|
||||
let min_iter = crate::engine::frist::iter_min(art, if alle() && letzte { MIN_ITERS_KLEIN } else { MIN_ITERS });
|
||||
while done < crate::engine::frist::iter_cap(art, ITERS) {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
let jetzt = crate::engine::frist::thread_cpu_ms();
|
||||
@@ -712,6 +713,7 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
if zu_gross {
|
||||
continue;
|
||||
}
|
||||
crate::engine::frist::iter_log(art, done as u64);
|
||||
// The smallest game under ALLE may rest on fewer iterations: a coarse solve still beats the heuristic.
|
||||
if done < min_iter {
|
||||
return weg("mw zu wenig iterationen");
|
||||
|
||||
@@ -220,14 +220,15 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
}
|
||||
}
|
||||
let mut done = 0u32;
|
||||
while done < ITERS {
|
||||
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::MwRiver, ITERS) {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if done % 200 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget || crate::engine::frist::notbremse() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if done < MIN_ITERS {
|
||||
crate::engine::frist::iter_log(crate::engine::frist::Art::MwRiver, done as u64);
|
||||
if done < crate::engine::frist::iter_min(crate::engine::frist::Art::MwRiver, MIN_ITERS) {
|
||||
return crate::engine::multi3_spieler::weg("mw zu wenig iterationen");
|
||||
}
|
||||
if std::env::var("KERN_REGRET").is_ok() {
|
||||
|
||||
@@ -172,14 +172,15 @@ pub fn solve_river(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<
|
||||
lock_villain(&mut solver, r, pot, dead, &villain_weights);
|
||||
}
|
||||
let mut done = 0;
|
||||
while done < ITERS {
|
||||
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::RsRiver, ITERS) {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if done % 10 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget || crate::engine::frist::notbremse() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if done < MIN_ITERS {
|
||||
crate::engine::frist::iter_log(crate::engine::frist::Art::RsRiver, done as u64);
|
||||
if done < crate::engine::frist::iter_min(crate::engine::frist::Art::RsRiver, MIN_ITERS) {
|
||||
return None;
|
||||
}
|
||||
let strategy = solver.strategy();
|
||||
|
||||
@@ -816,7 +816,7 @@ fn setzer_index(spot: &Spot) -> usize {
|
||||
/// Rückfall-Antwort für diesen Spot; `None` bei ausgeschaltetem Schalter oder ausserhalb der Scheibe (Omaha, keine Gegner-Range).
|
||||
pub fn entscheide(spot: &Spot, lists: &[Option<List>], lage: Option<&Turnierlage>) -> Option<Decision> {
|
||||
let c = cfg()?;
|
||||
if c.nur_zeit && !(crate::engine::frist::notbremse() || crate::engine::frist::elapsed_ms() >= ZEIT_AB_MS) {
|
||||
if c.nur_zeit && !(crate::engine::frist::notbremse() || (crate::engine::frist::elapsed_ms() >= ZEIT_AB_MS && !crate::engine::frist::iter_aktiv())) {
|
||||
return None;
|
||||
}
|
||||
entscheide_mit(spot, lists, c, lage)
|
||||
|
||||
@@ -1092,14 +1092,15 @@ pub fn solve(spot: &Spot, c: &Cfg) -> Option<Geloest> {
|
||||
}
|
||||
}
|
||||
let mut done = 0;
|
||||
while done < c.iters {
|
||||
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::HuRiver, c.iters) {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if !ohne_uhr && done % 5 == 0 && (crate::engine::frist::thread_cpu_ms() - cpu0 > BUDGET_MS || crate::engine::frist::elapsed_ms() > NOTFALL_MS || crate::engine::frist::notbremse()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if done < MIN_ITERS {
|
||||
crate::engine::frist::iter_log(crate::engine::frist::Art::HuRiver, done as u64);
|
||||
if done < crate::engine::frist::iter_min(crate::engine::frist::Art::HuRiver, MIN_ITERS) {
|
||||
return None;
|
||||
}
|
||||
let strat = solver.strategy();
|
||||
@@ -1579,9 +1580,10 @@ fn solve_frueh_roh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
|
||||
let mut locks = Locks::default();
|
||||
lege_fest(&mut solver, &m, root, [0.0, 0.0], None, &villain_weights, c.w, &mut locks, "");
|
||||
let (iters, kappe) = if flop { (c.flop_iters, FLOP_BUDGET_MS) } else { (c.turn_iters, TURN_BUDGET_MS) };
|
||||
let art = if flop { crate::engine::frist::Art::HuFlop } else if crate::engine::frist::breit_hier() { crate::engine::frist::Art::HuTurnBreit } else { crate::engine::frist::Art::HuTurn };
|
||||
let mut done = 0;
|
||||
let cpu_iter0 = crate::engine::frist::thread_cpu_ms();
|
||||
while done < iters {
|
||||
while done < crate::engine::frist::iter_cap(art, iters) {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if c.eng && !ohne_uhr && done == 2 {
|
||||
@@ -1595,7 +1597,8 @@ fn solve_frueh_roh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
|
||||
break;
|
||||
}
|
||||
}
|
||||
if done < MIN_TURN_ITERS {
|
||||
crate::engine::frist::iter_log(art, done as u64);
|
||||
if done < crate::engine::frist::iter_min(art, MIN_TURN_ITERS) {
|
||||
return weg("zu wenig iterationen");
|
||||
}
|
||||
let strat = solver.strategy();
|
||||
@@ -1741,7 +1744,7 @@ fn turn_decision_neu(raw: &Spot, c: &'static Cfg) -> Option<Decision> {
|
||||
} else if c.turn_gegen_stark_breit && stark_fold {
|
||||
// halbe River-Karten und 25 Iterationen: die zweite Rechnung kostet nicht noch einmal die volle Zeit (Latenz)
|
||||
let c2 = Cfg { linie_modell: false, karten: (c.karten / 2).max(4), turn_iters: c.turn_iters.min(MIN_TURN_ITERS + 5), ..c.clone() };
|
||||
if let Some(g2) = solve_frueh(&gated, &c2, gated.street) {
|
||||
if let Some(g2) = crate::engine::frist::breit_dabei(|| solve_frueh(&gated, &c2, gated.street)) {
|
||||
let (draw, _) = Rng::seeded(gated.seed).unit();
|
||||
let (mut acc, mut k2) = (0.0, g2.acts.len().saturating_sub(1));
|
||||
for (k, p) in g2.row.iter().enumerate() {
|
||||
|
||||
@@ -255,14 +255,15 @@ fn solve_core(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<Card>
|
||||
let mut solver = TrSolver::new(game, hands, board, Some(cfg.river_cards));
|
||||
if cfg.budget_ms > 0.0 {
|
||||
let mut done = 0;
|
||||
while done < cfg.iterations {
|
||||
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::TgTurn, cfg.iterations) {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if crate::engine::frist::thread_cpu_ms() - cpu0 > cfg.budget_ms || crate::engine::frist::notbremse() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if done < MIN_ITERS {
|
||||
crate::engine::frist::iter_log(crate::engine::frist::Art::TgTurn, done as u64);
|
||||
if done < crate::engine::frist::iter_min(crate::engine::frist::Art::TgTurn, MIN_ITERS) {
|
||||
return None;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user