Merge claude/budget-baum (1bddcac6) in Go-live-Buendel

Konflikte: decide.py (BEKANNTE_SCHALTER: ALLIN_KURVE + BUDGET), river3_spieler.rs/solver_kern.rs (zeit_stopp der Stuetzungs-Diagnose bleibt, BUDGET=baum-Schleife).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 02:45:12 +01:00
co-authored by Claude Opus 5.5
31 changed files with 835 additions and 16 deletions
+3
View File
@@ -64,4 +64,7 @@ fn main() {
};
println!("{lage}\t{grund}\t{}{ms}", d.reason.replace('\t', " "));
}
if rechner::engine::baum::aktiv() {
eprintln!("NOTBREMSE {}", rechner::engine::frist::NOTBREMSE_ZAEHLER.load(std::sync::atomic::Ordering::Relaxed));
}
}
+23
View File
@@ -377,6 +377,20 @@ fn matched_any(regret: &[f64], a: usize, out: &mut [f64]) {
}
}
/// `k` of the undealt cards as single-bit masks, balanced over ranks and suits: the deck sorted by rank (the suit order rotating
/// with the rank, so no suit leads), then evenly strided. Same board and `k` give the same cards in the same order.
pub fn karten_gleichmaessig(board: u64, k: usize) -> Vec<u64> {
let mut all: Vec<u64> = (0..4u32).flat_map(|s| (0..13u32).map(move |r| 1u64 << (16 * s + r))).filter(|b| b & board == 0).collect();
all.sort_by_key(|b| {
let t = b.trailing_zeros();
let (s, r) = (t / 16, t % 16);
(r, (s + r) % 4)
});
let n = all.len();
let k = k.clamp(1, n);
(0..k).map(|i| all[(((i as f64 + 0.5) * n as f64 / k as f64) as usize).min(n - 1)]).collect()
}
impl TrSolver {
/// `board`: the four turn cards as a mask; `river`: the river cards to enumerate (`None` = all 48 not
/// on the board, `Some(k)` = `k` of them, evenly strided). Combos must not touch the board.
@@ -395,6 +409,15 @@ impl TrSolver {
TrSolver::with_cards(game, hands, board, all, wr)
}
/// As `new` with `Some(k)`, but the `k` cards are chosen by `karten_gleichmaessig` (rank- and suit-balanced, a fixed function of
/// the board and `k`): `BUDGET=baum` uses it so a smaller card count is a coarser but unbiased sample of the same deck.
pub fn new_gleichmaessig(game: TrGame, hands: [Hands; 2], board: u64, k: usize) -> TrSolver {
let candidates = (0..52u32).filter(|i| board & (1u64 << (16 * (i / 13) + i % 13)) == 0).count();
let all = karten_gleichmaessig(board, k);
let wr = candidates as f64 / (all.len() as f64 * (candidates as f64 - 4.0));
TrSolver::with_cards(game, hands, board, all, wr)
}
/// As `new`, with explicit river cards (single-bit masks) and the deal weight of each.
pub fn with_cards(game: TrGame, hands: [Hands; 2], board: u64, all: Vec<u64>, wr: f64) -> TrSolver {
let n = [hands[0].masks.len(), hands[1].masks.len()];
+122
View File
@@ -0,0 +1,122 @@
//! `BUDGET=baum`: the work of every postflop solve is a deterministic function of its tree size, not of the clock.
//! (Calibration helpers: `BAUM_LOG=1` prints one stderr line per finished solve loop.)
/// `BUDGET=baum` is set (read once). Off: nothing in this module is consulted and every path is the clock's.
pub fn aktiv() -> bool {
static AN: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*AN.get_or_init(|| std::env::var("BUDGET").as_deref() == Ok("baum"))
}
/// Calibration log `BAUM_LOG=1`: `BAUM_LOG <kind> <size features> setup_ms loop_ms iters` on stderr.
pub fn log(art: &str, feats: &str, setup_ms: f64, loop_ms: f64, done: u64) {
static LOG: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
if *LOG.get_or_init(|| std::env::var("BAUM_LOG").is_ok_and(|v| !v.is_empty() && v != "0")) {
eprintln!("BAUM_LOG\t{art}\t{feats}\t{setup_ms:.1}\t{loop_ms:.1}\t{done}");
}
}
// ---------------------------------------------------------------------------------------------------------------------
// The work of a solve as a function of its tree size. Constants: least-squares fits of CPU ms per iteration over the 238
// fixture decisions, measured with fixed iterations (`SOLVER_ITER`, `BAUM_LOG=1`; messung/solver_kern/BUDGET_BAUM.md), relative
// error 12 to 16 % (HU) and 4 to 12 % (MW). A solve gets what the live clock would give it on an idle core
// (`TURN_BUDGET_MS` etc.), but the iterations, the river/turn cards and the multiway stage are computed from these predictions
// BEFORE the solve, so the same spot gets the same work whatever the machine load.
// ---------------------------------------------------------------------------------------------------------------------
use crate::engine::frist::Art;
use std::cell::Cell;
thread_local! {
/// Predicted CPU ms the solves of this decision have used so far (the deterministic stand-in of `frist::elapsed_ms`).
static KONTO: Cell<f64> = const { Cell::new(0.0) };
}
/// New decision (called by `frist::begin`).
pub fn neu() {
KONTO.with(|k| k.set(0.0));
}
/// Predicted CPU ms spent on solves in this decision so far.
pub fn konto() -> f64 {
KONTO.with(Cell::get)
}
/// Book predicted CPU ms.
pub fn buche(ms: f64) {
KONTO.with(|k| k.set(k.get() + ms));
}
/// Setup (ranges, tree, equity tables) of a heads-up flop/turn/river solve, CPU ms (the measured ticks are 0 to 60).
pub const HU_SETUP_MS: f64 = 15.0;
/// CPU ms of one heads-up river iteration.
pub fn hu_river_iter_ms(c0: usize, c1: usize, nodes: usize) -> f64 {
7.0e-6 * nodes as f64 * (c0 + c1) as f64
}
/// CPU ms of one heads-up turn iteration with `k` river cards.
pub fn hu_turn_iter_ms(c0: usize, c1: usize, nodes: usize, k: usize) -> f64 {
k as f64 * (3.8e-7 * (c0 * c1) as f64 + 6.4e-6 * nodes as f64 * (c0 + c1) as f64)
}
/// CPU ms of one heads-up flop iteration with `k` turn cards.
pub fn hu_flop_iter_ms(c0: usize, c1: usize, nodes: usize, k: usize) -> f64 {
k as f64 * 7.5e-6 * nodes as f64 * (c0 + c1) as f64
}
/// CPU ms of one multiway iteration (MCCFR samples one path: the cost follows players x combos, not the node count;
/// fit `ms = k x players x sum(combos)`, relative error ~20 %, the small solves are limited by the 15.6 ms clock tick).
pub fn mw_iter_ms(art: Art, players: usize, combos: &[usize]) -> f64 {
let k = match art {
Art::MwFlop => 4.2e-5,
Art::MwTurn => 4.8e-5,
_ => 1.75e-5,
};
k * players as f64 * combos.iter().sum::<usize>() as f64
}
/// CPU ms to set up a multiway solve of `nodes` tree nodes (locks and rows).
pub fn mw_setup_ms(nodes: usize) -> f64 {
1.6e-3 * nodes as f64
}
/// `x` rounded down to a multiple of `step`, between `lo` and `hi` (the live clock checks every `step` iterations too).
pub fn iters_aus(x: f64, step: u32, lo: u32, hi: u32) -> u32 {
let n = if x.is_finite() && x > 0.0 { (x as u32) / step * step } else { 0 };
n.clamp(lo, hi.max(lo))
}
/// Iterations of a solve that must fit `kappe` CPU ms with `setup` ms already gone and `p` ms per iteration.
pub fn iters_fuer(kappe: f64, setup: f64, p: f64, step: u32, lo: u32, hi: u32) -> u32 {
iters_aus((kappe - setup) / p.max(1e-9), step, lo, hi)
}
/// Cards of a heads-up turn/flop solve so that `min_iters` iterations (x 1.3 slack, as the live check) fit `kappe`:
/// the live `eng` rule (scale by `(kappe - setup) / (p x min_iters x 1.5)`, at most three times), with the predicted cost in
/// place of two measured iterations. `iter_ms(k)` = predicted ms per iteration with `k` cards.
pub fn karten_fuer(k0: usize, kmin: usize, kappe: f64, min_iters: u32, iter_ms: &dyn Fn(usize) -> f64) -> usize {
let mut k = k0;
for _ in 0..3 {
let p = iter_ms(k);
if p * min_iters as f64 * 1.3 <= kappe - HU_SETUP_MS || k <= kmin {
break;
}
let skala = ((kappe - HU_SETUP_MS) / (p * min_iters as f64 * 1.5)).clamp(0.05, 0.9);
k = ((k as f64 * skala) as usize).max(kmin);
}
k
}
/// Measurement only (`BAUM_KARTEN=<n>`, under `BUDGET=baum`): force the river/turn card count of every heads-up turn/flop solve
/// (48 = all), to compare the chosen count with the full one.
pub fn karten_vorgabe() -> Option<usize> {
static K: std::sync::OnceLock<Option<usize>> = std::sync::OnceLock::new();
*K.get_or_init(|| std::env::var("BAUM_KARTEN").ok().and_then(|v| v.trim().parse().ok()).filter(|n: &usize| *n > 0))
}
/// Measurement only (`BAUM_WAHL=schritt`, under `BUDGET=baum`): the old suit-sorted stride card selection instead of the balanced one,
/// to tell what a difference to the clock/`SOLVER_ITER` runs owes to the card choice.
pub fn wahl_schritt() -> bool {
static W: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*W.get_or_init(|| std::env::var("BAUM_WAHL").as_deref() == Ok("schritt"))
}
+17 -1
View File
@@ -15,8 +15,13 @@ thread_local! {
static WAND: Cell<Option<Instant>> = const { Cell::new(None) };
/// `fest_hier`: this thread ignores wall time like `SOLVER_ZEIT=fest` (tests, tools).
static FEST_HIER: Cell<bool> = const { Cell::new(false) };
/// `BUDGET=baum`: the emergency brake already fired in this decision (counted once per decision).
static GEFEUERT: Cell<bool> = const { Cell::new(false) };
}
/// How many decisions the emergency brake cut under `BUDGET=baum` (a safety net there: should stay 0).
pub static NOTBREMSE_ZAEHLER: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
/// Total wall time of one decision per street, in ms.
pub const RIVER_MS: f64 = 2000.0;
pub const TURN_MS: f64 = 1250.0;
@@ -28,6 +33,8 @@ pub const MARGIN_MS: f64 = 150.0;
pub fn begin() {
START.with(|s| s.set(Some(thread_cpu_ms())));
WAND.with(|s| s.set(Some(Instant::now())));
GEFEUERT.with(|g| g.set(false));
super::baum::neu();
}
/// Live emergency brake in wall time (`KERN_NOTBREMSE_MS`, set only by the live bridge
@@ -39,7 +46,11 @@ pub fn notbremse() -> bool {
let Some(ms) = *MS.get_or_init(|| std::env::var("KERN_NOTBREMSE_MS").ok().and_then(|v| v.trim().parse().ok()).filter(|x: &f64| *x > 0.0)) else {
return false;
};
!fixed() && wand_ueber(ms)
let an = !fest_streng() && wand_ueber(ms);
if an && super::baum::aktiv() && !GEFEUERT.with(|g| g.replace(true)) {
NOTBREMSE_ZAEHLER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
}
an
}
/// Wall time since `begin` exceeds `ms`.
@@ -64,6 +75,11 @@ pub fn left_ms(total_ms: f64) -> f64 {
/// Measurement switch `SOLVER_ZEIT=fest`: solvers ignore wall time and always run their full iteration
/// count, so ladder and LBR results do not depend on machine load (read once).
pub fn fixed() -> bool {
fest_streng() || super::baum::aktiv()
}
/// `fixed` without `BUDGET=baum`: the modes that also switch the emergency brake off.
fn fest_streng() -> 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")) || iter_aktiv()
}
+1
View File
@@ -14,6 +14,7 @@ pub mod double_board;
pub mod effective;
pub mod flop_spieler;
pub mod fortsetzung;
pub mod baum;
pub mod frist;
pub mod glaube;
pub mod glaube_linie;
+33 -6
View File
@@ -629,7 +629,12 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
if spot.board.len() != cards || spot.hero_cards.len() != 2 || villains < 2 {
return weg("mw lage");
}
let budget = crate::engine::frist::budget_ms(self::cap_ms(cap_ms), total);
let baum = crate::engine::baum::aktiv();
let budget = if baum {
self::cap_ms(cap_ms).min(total - crate::engine::frist::MARGIN_MS - crate::engine::baum::konto())
} else {
crate::engine::frist::budget_ms(self::cap_ms(cap_ms), total)
};
if budget <= 0.0 {
return weg("mw keine zeit");
}
@@ -660,6 +665,8 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
// Under SOLVER3_ALLE a game too big for the budget (fewer than MIN_ITERS iterations projected) is solved again
// smaller: fewer combos per player, fewer slots (a coarser abstraction beats the heuristic).
let stufen: Vec<(usize, usize)> = if alle() { vec![(MAX_COMBOS, slots), (100, (slots / 2).max(2)), (50, 2)] } else { vec![(MAX_COMBOS, slots)] };
// `BUDGET=baum`: predicted CPU ms already used by earlier stages of this solve (the stand-in of `jetzt - cpu0`).
let mut baum_vorher = 0.0;
for (lvl, (maxc, sl)) in stufen.iter().copied().enumerate() {
let letzte = lvl + 1 == stufen.len();
let erzwungen: Option<usize> = std::env::var("KERN_STUFE").ok().and_then(|v| v.trim().parse().ok());
@@ -687,6 +694,20 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
let nodes = game.nodes.len();
let combos: Vec<usize> = hands.iter().map(|h| h.masks.len()).collect();
let hero_index = hands[me].masks.iter().position(|m| *m == hero_mask)?;
// `BUDGET=baum`: the stage and its iterations come from the tree size, before anything is built on it.
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 });
let p_baum = crate::engine::baum::mw_iter_ms(art, order.len(), &combos);
let setup_baum = crate::engine::baum::mw_setup_ms(nodes);
let mut iters_eff = ITERS;
if baum {
let frei = budget - baum_vorher - setup_baum;
if !letzte && erzwungen.is_none() && p_baum * MIN_ITERS as f64 > frei - 30.0 * p_baum && !crate::engine::frist::iter_aktiv() {
baum_vorher += setup_baum + 30.0 * p_baum;
continue;
}
iters_eff = crate::engine::baum::iters_fuer(frei, 0.0, p_baum, 50, min_iter, ITERS);
}
let mut solver = SolverM::new(game, hands, board, spot.seed ^ 0x9e37_79b9_7f4a_7c15);
solver.werte_beobachten(at, hero_index);
if pool_w() > 0.0 || offen_w() > 0.0 {
@@ -727,19 +748,21 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
return weg("stuetzung-locks");
}
let cpu_stufe = crate::engine::frist::thread_cpu_ms();
let cpu_s0 = cpu_stufe;
let mut done = 0u32;
let mut zu_gross = false;
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) {
while done < crate::engine::frist::iter_cap(art, iters_eff) {
solver.iterate();
done += 1;
if baum && crate::engine::frist::notbremse() {
break;
}
let jetzt = crate::engine::frist::thread_cpu_ms();
if done == 30 && !letzte && erzwungen.is_none() && (jetzt - cpu_stufe) / 30.0 * MIN_ITERS as f64 > budget - (jetzt - cpu0) {
if !baum && done == 30 && !letzte && erzwungen.is_none() && (jetzt - cpu_stufe) / 30.0 * MIN_ITERS as f64 > budget - (jetzt - cpu0) {
zu_gross = true;
break;
}
if done % 50 == 0 && jetzt - cpu0 > budget {
if !baum && done % 50 == 0 && jetzt - cpu0 > budget {
// Over the budget: enough iterations end the solve; too few hand the spot to a smaller game, the
// smallest one runs on to its minimum.
if done >= min_iter {
@@ -761,6 +784,10 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
continue;
}
crate::engine::frist::iter_log(art, done as u64);
if baum {
crate::engine::baum::buche(setup_baum + done as f64 * p_baum);
}
crate::engine::baum::log(art.name(), &format!("{} {:?} {} {}", order.len(), combos, nodes, sl), cpu_s0 - cpu0, crate::engine::frist::thread_cpu_ms() - cpu_s0, 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");
+20 -3
View File
@@ -143,7 +143,12 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
if spot.street != Street::River || spot.board.len() != 5 || spot.hero_cards.len() != 2 || villains < 2 {
return weg("mw lage");
}
let budget = crate::engine::frist::budget_ms(crate::engine::multi3_spieler::cap_ms(BUDGET_MS), crate::engine::frist::RIVER_MS);
let baum = crate::engine::baum::aktiv();
let budget = if baum {
crate::engine::multi3_spieler::cap_ms(BUDGET_MS).min(crate::engine::frist::RIVER_MS - crate::engine::frist::MARGIN_MS - crate::engine::baum::konto())
} else {
crate::engine::frist::budget_ms(crate::engine::multi3_spieler::cap_ms(BUDGET_MS), crate::engine::frist::RIVER_MS)
};
if budget <= 0.0 {
return weg("mw keine zeit");
}
@@ -238,15 +243,27 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
}
let mut done = 0u32;
let mut zeit_stopp = false;
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::MwRiver, ITERS) {
let cpu_l0 = crate::engine::frist::thread_cpu_ms();
// `BUDGET=baum`: the iterations the cap allows on an idle core, from the tree size (never fewer than `MIN_ITERS`: no drop to the fallback for time).
let p_baum = crate::engine::baum::mw_iter_ms(crate::engine::frist::Art::MwRiver, order.len(), &combos);
let setup_baum = crate::engine::baum::mw_setup_ms(nodes);
let iters_eff = if baum { crate::engine::baum::iters_fuer(budget, setup_baum, p_baum, 200, MIN_ITERS, ITERS) } else { ITERS };
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::MwRiver, iters_eff) {
solver.iterate();
done += 1;
if done % 200 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget || crate::engine::frist::notbremse() {
if baum && crate::engine::frist::notbremse() {
break;
}
if !baum && done % 200 == 0 && crate::engine::frist::thread_cpu_ms() - cpu0 > budget || crate::engine::frist::notbremse() {
zeit_stopp = true;
break;
}
}
crate::engine::frist::iter_log(crate::engine::frist::Art::MwRiver, done as u64);
if baum {
crate::engine::baum::buche(setup_baum + done as f64 * p_baum);
}
crate::engine::baum::log("mw_river", &format!("{} {:?} {} 0", order.len(), combos, nodes), cpu_l0 - cpu0, crate::engine::frist::thread_cpu_ms() - cpu_l0, 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");
}
+1 -1
View File
@@ -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 && !crate::engine::frist::iter_aktiv())) {
if c.nur_zeit && !(crate::engine::frist::notbremse() || (crate::engine::frist::elapsed_ms() >= ZEIT_AB_MS && !crate::engine::frist::iter_aktiv() && !crate::engine::baum::aktiv()) || (crate::engine::baum::aktiv() && !crate::engine::frist::iter_aktiv() && crate::engine::baum::konto() >= ZEIT_AB_MS)) {
return None;
}
entscheide_mit(spot, lists, c, lage)
+57 -4
View File
@@ -1257,6 +1257,10 @@ pub fn solve(spot: &Spot, c: &Cfg) -> Option<Geloest> {
if !ohne_uhr && (crate::engine::frist::elapsed_ms() > NOTFALL_MS || crate::engine::frist::notbremse()) {
return None;
}
let baum = crate::engine::baum::aktiv();
if baum && (crate::engine::baum::konto() > NOTFALL_MS || crate::engine::frist::notbremse()) {
return None;
}
let started = std::time::Instant::now();
let cpu0 = crate::engine::frist::thread_cpu_ms();
// Ranges zum River-Beginn: die River-Aktionen kommen nur über den Baum.
@@ -1367,15 +1371,26 @@ pub fn solve(spot: &Spot, c: &Cfg) -> Option<Geloest> {
}
let mut done = 0;
let mut zeit_stopp = false;
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::HuRiver, c.iters) {
let cpu_l0 = crate::engine::frist::thread_cpu_ms();
// `BUDGET=baum`: the iterations the live cap would allow on an idle core, computed from the tree size up front.
let p_baum = crate::engine::baum::hu_river_iter_ms(combos[0], combos[1], nodes);
let iters_eff = if baum { crate::engine::baum::iters_fuer(BUDGET_MS, crate::engine::baum::HU_SETUP_MS, p_baum, 5, MIN_ITERS, c.iters) } else { c.iters };
while done < crate::engine::frist::iter_cap(crate::engine::frist::Art::HuRiver, iters_eff) {
solver.iterate();
done += 1;
if baum && crate::engine::frist::notbremse() {
break;
}
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()) {
zeit_stopp = true;
break;
}
}
crate::engine::frist::iter_log(crate::engine::frist::Art::HuRiver, done as u64);
if baum {
crate::engine::baum::buche(crate::engine::baum::HU_SETUP_MS + done as f64 * p_baum);
}
crate::engine::baum::log("hu_river", &format!("{} {} {}", combos[0], combos[1], nodes), cpu_l0 - cpu0, crate::engine::frist::thread_cpu_ms() - cpu_l0, done as u64);
if done < crate::engine::frist::iter_min(crate::engine::frist::Art::HuRiver, MIN_ITERS) {
return None;
}
@@ -1876,6 +1891,10 @@ fn solve_frueh_roh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
if !ohne_uhr && (crate::engine::frist::elapsed_ms() > NOTFALL_MS || crate::engine::frist::notbremse()) {
return weg("frist");
}
let baum = crate::engine::baum::aktiv();
if baum && (crate::engine::baum::konto() > NOTFALL_MS || crate::engine::frist::notbremse()) {
return weg("frist");
}
let started = std::time::Instant::now();
let cpu0 = crate::engine::frist::thread_cpu_ms();
let mut start = spot.clone();
@@ -1912,8 +1931,25 @@ fn solve_frueh_roh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
let villain_weights = hands[1].weights.clone();
let pct = brett_perzentil(&hands[1].masks, board);
let root = game.root;
let mut solver = if flop {
let (iters, kappe) = if flop { (c.flop_iters, FLOP_BUDGET_MS) } else { (c.turn_iters, TURN_BUDGET_MS) };
// `BUDGET=baum`: river cards of the turn solve and iterations from the tree size (see `baum.rs`), never from the clock.
// A flop solve that is too big for its cap at the minimum iterations goes the `eng` way (`SKALA`, solved again smaller).
let mut turn_karten_baum = c.karten;
if baum && !flop {
let k0 = if c.eng { ((ENG_GRENZE / (combos[0] * combos[1]).max(1) as f64) as usize).clamp(2, c.karten) } else { c.karten };
turn_karten_baum = if let Some(n) = crate::engine::baum::karten_vorgabe() { n } else if c.eng { crate::engine::baum::karten_fuer(k0, 2, kappe, MIN_TURN_ITERS, &|k| crate::engine::baum::hu_turn_iter_ms(combos[0], combos[1], nodes, k)) } else { k0 };
}
let schritt = baum && crate::engine::baum::wahl_schritt();
let mut solver = if schritt && flop {
TrSolver::new(game, hands, board, Some(c.flop_karten)).with_river_equity(board)
} else if schritt {
TrSolver::new(game, hands, board, Some(turn_karten_baum))
} else if flop && baum {
TrSolver::new_gleichmaessig(game, hands, board, crate::engine::baum::karten_vorgabe().unwrap_or(c.flop_karten)).with_river_equity(board)
} else if flop {
TrSolver::new(game, hands, board, Some(c.flop_karten)).with_river_equity(board)
} else if baum {
TrSolver::new_gleichmaessig(game, hands, board, turn_karten_baum)
} else {
// `eng`: die Kosten (Aufbau und jede Iteration) wachsen mit Kombos x Kombos x River-Karten; breite Ranges bekommen
// von vornherein weniger Karten, statt erst nach einem verlorenen Aufbau.
@@ -1962,9 +1998,22 @@ fn solve_frueh_roh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
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 < crate::engine::frist::iter_cap(art, iters) {
let p_baum = if flop { crate::engine::baum::hu_flop_iter_ms(combos[0], combos[1], nodes, karten) } else { crate::engine::baum::hu_turn_iter_ms(combos[0], combos[1], nodes, karten) };
let iters_eff = if baum {
if flop && c.eng && p_baum * MIN_TURN_ITERS as f64 * 1.3 > kappe - crate::engine::baum::HU_SETUP_MS {
SKALA.with(|x| x.set(Some(((kappe - crate::engine::baum::HU_SETUP_MS) / (p_baum * MIN_TURN_ITERS as f64 * 1.5)).clamp(0.05, 0.9))));
return weg("zu gross (eng)");
}
crate::engine::baum::iters_fuer(kappe, crate::engine::baum::HU_SETUP_MS, p_baum, 5, MIN_TURN_ITERS, iters)
} else {
iters
};
while done < crate::engine::frist::iter_cap(art, iters_eff) {
solver.iterate();
done += 1;
if baum && crate::engine::frist::notbremse() {
break;
}
if c.eng && !ohne_uhr && done == 2 {
let je = (crate::engine::frist::thread_cpu_ms() - cpu_iter0) / 2.0;
if je * MIN_TURN_ITERS as f64 * 1.3 > kappe - (cpu_iter0 - cpu0) {
@@ -1977,6 +2026,10 @@ fn solve_frueh_roh(spot: &Spot, c: &Cfg, strasse: Street) -> Option<TurnGeloest>
}
}
crate::engine::frist::iter_log(art, done as u64);
if baum {
crate::engine::baum::buche(crate::engine::baum::HU_SETUP_MS + done as f64 * p_baum);
}
crate::engine::baum::log(art.name(), &format!("{} {} {} {}", combos[0], combos[1], nodes, karten), cpu_iter0 - cpu0, crate::engine::frist::thread_cpu_ms() - cpu_iter0, done as u64);
if done < crate::engine::frist::iter_min(art, MIN_TURN_ITERS) {
return weg("zu wenig iterationen");
}
@@ -2115,7 +2168,7 @@ fn turn_decision_neu(raw: &Spot, c: &'static Cfg) -> Option<Decision> {
}
}
let mut breit = false;
if c.turn_gegen_stark_breit && stark_fold && !crate::engine::frist::fixed() && crate::engine::frist::elapsed_ms() > TGSTARK_SPAET_MS {
if c.turn_gegen_stark_breit && stark_fold && (!crate::engine::frist::fixed() && crate::engine::frist::elapsed_ms() > TGSTARK_SPAET_MS || crate::engine::baum::aktiv() && crate::engine::baum::konto() > TGSTARK_SPAET_MS) {
// Keine Zeit fuer die zweite Rechnung: die beste Nicht-Fold-Antwort dieser Rechnung statt des Folds.
if let Some(k2) = (0..g.acts.len()).filter(|&k| !matches!(g.acts[k], Act::Fold)).max_by(|&x, &y| g.werte[x].total_cmp(&g.werte[y])) {
(act, pick, breit) = (g.acts[k2], k2, true);