Multiway-Solver: Pool-Antwort der Gegner, gespielte Linie fest, exakte Einsatzgroesse (SOLVER3_POOL, SOLVER3_LINIE), Diagnose kern_zeile
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,6 +51,132 @@ static ALLE: AtomicBool = AtomicBool::new(false);
|
||||
/// the top-pair flop fold becomes a call. The answer stays the solver's (reason `solver-kern ... | form`). Default off.
|
||||
static FORM: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
/// `SOLVER3_POOL=<w>` (0 < w <= 1): the villains of the multiway solvers answer a bet like the measured pool instead of
|
||||
/// like equilibrium players (weight `w`, the heads-up core's node lock). Cause of the hand rules `SOLVER3_FORM` and
|
||||
/// `SOLVER3_FSPERRE` (20.11.): a CFR villain folds every hand that loses to hero's bet range and never pays off with a
|
||||
/// worse hand, so thin value (trips, an overpair) is worth nothing against it and checking wins; the heads-up core had
|
||||
/// the pool's fold curve all along (`wett_kurve`), the multiway solvers did not. Stored in thousandths, default 0 = off.
|
||||
static POOL: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
|
||||
pub fn set_pool(w: f64) {
|
||||
POOL.store((w.clamp(0.0, 1.0) * 1000.0).round() as u32, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn pool_w() -> f64 {
|
||||
POOL.load(Ordering::Relaxed) as f64 / 1000.0
|
||||
}
|
||||
|
||||
/// `SOLVER3_LINIE=1`: the villains' acts already played on the observed line are fixed (the played act with probability 1).
|
||||
/// Their ranges are the range model's of that line (the act is in them), but the tree let the act happen a second time by
|
||||
/// the CFR strategy: a bet was weighted by how often CFR bets the hand (the range squared) and hero's node was reached in a
|
||||
/// fraction of the iterations, with a row learned from a few noisy samples (the same double count the heads-up core fixed
|
||||
/// with `linie=modell`). Default off.
|
||||
static LINIE: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub fn set_linie(on: bool) {
|
||||
LINIE.store(on, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn linie() -> bool {
|
||||
LINIE.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// The locks of the played line: at each node of `pfad` of a player other than `me`, every hand plays the act taken.
|
||||
/// `acts(node)` = the node's act count, `hands[p]` = player `p`'s combos.
|
||||
pub(crate) fn linie_sperren(pfad: &[(usize, usize)], me: usize, spieler: &dyn Fn(usize) -> Option<(usize, usize)>, hands: &[usize]) -> Vec<(usize, Vec<f64>)> {
|
||||
pfad.iter()
|
||||
.filter_map(|&(node, k)| {
|
||||
let (p, a) = spieler(node)?;
|
||||
if p == me || a < 2 {
|
||||
return None;
|
||||
}
|
||||
let mut rows = vec![0.0; hands[p] * a];
|
||||
for h in 0..hands[p] {
|
||||
rows[h * a + k] = 1.0;
|
||||
}
|
||||
Some((node, rows))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The pool's answer of villain `p` (index in the acting order) at a node facing a bet: fold the weakest `fold` share of
|
||||
/// his range (soft edge), raise the strongest `raise_pool` share, call the rest. `q` = each hand's rank in his range.
|
||||
/// `ratio` = the last bet or raise over the pot before it, `allin_ab` = the ratio at which a bet is all-in.
|
||||
fn pool_zeile(spot: &Spot, who: &Villain, acts: &[Act], q: &[f64], ratio: f64, allin_ab: f64) -> Option<Vec<f64>> {
|
||||
let f = crate::exploit::wett_kurve::pool_fold(spot, spot.street, ratio, allin_ab, who.profile.as_ref())?;
|
||||
let allin = ratio >= allin_ab - 1e-9;
|
||||
let r = if allin { 0.0 } else { crate::engine::solver_kern::raise_pool(ratio) };
|
||||
let fold_i = acts.iter().position(|a| *a == Act::Fold)?;
|
||||
let call_i = acts.iter().position(|a| *a == Act::Call)?;
|
||||
let raise_i = acts.iter().enumerate().filter_map(|(i, a)| if let Act::Raise(x) = a { Some((i, *x)) } else { None }).min_by(|a, b| a.1.total_cmp(&b.1)).map(|x| x.0);
|
||||
let mut rows = Vec::with_capacity(q.len() * acts.len());
|
||||
for &qi in q {
|
||||
let mut row = vec![0.0; acts.len()];
|
||||
let pf = crate::engine::solver_kern::rampe(qi, f, 0.08, true);
|
||||
let pr = if raise_i.is_some() { crate::engine::solver_kern::rampe(qi, r, 0.04, false) * (1.0 - pf) } else { 0.0 };
|
||||
row[fold_i] = pf;
|
||||
if let Some(i) = raise_i {
|
||||
row[i] = pr;
|
||||
}
|
||||
row[call_i] = (1.0 - pf - pr).max(0.0);
|
||||
rows.extend(row);
|
||||
}
|
||||
Some(rows)
|
||||
}
|
||||
|
||||
/// What `pool_sperren` needs of a node: the actor, its acts and its kids (a deal node has none: the walk stops there).
|
||||
pub(crate) enum KnotenSicht<'a> {
|
||||
Dec { player: usize, acts: &'a [Act], kids: &'a [usize] },
|
||||
Ende,
|
||||
}
|
||||
|
||||
/// The nodes (index, pool rows) of the first betting round at which a villain faces a bet. `knoten(i)` shows node `i`;
|
||||
/// `hands[p]` = player `p`'s combos (masks), `pot` the pot before the street, `cap` the common cap, `passive` the pooled
|
||||
/// players (never decide). The walk follows the tree from the root keeping the street's contributions.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn pool_sperren<'a>(
|
||||
spot: &Spot,
|
||||
order: &[u8],
|
||||
me: usize,
|
||||
passive: u32,
|
||||
masks: &[&[u64]],
|
||||
board: u64,
|
||||
pot: f64,
|
||||
cap: f64,
|
||||
knoten: &dyn Fn(usize) -> KnotenSicht<'a>,
|
||||
) -> Vec<(usize, Vec<f64>)> {
|
||||
let ranks: Vec<Vec<f64>> = masks.iter().map(|m| crate::engine::river_spieler::percentiles(m, &vec![1.0; m.len()], board)).collect();
|
||||
let mut out = Vec::new();
|
||||
// (node, contributions, last aggression: (increment, pot before it, level before it))
|
||||
let mut stack = vec![(0usize, vec![0.0; order.len()], (0.0f64, pot, 0.0f64, false))];
|
||||
while let Some((at, c, (incr, before, prev_top, geraist))) = stack.pop() {
|
||||
let KnotenSicht::Dec { player, acts, kids } = knoten(at) else { continue };
|
||||
let top = c.iter().copied().fold(0.0, f64::max);
|
||||
if player != me && passive & (1 << player) == 0 && acts.contains(&Act::Fold) && incr > 0.0 && !geraist {
|
||||
if let Some(who) = spot.live_villains().find(|v| v.seat == order[player]) {
|
||||
let allin_ab = (cap - prev_top) / before.max(1e-9);
|
||||
if let Some(rows) = pool_zeile(spot, who, acts, &ranks[player], incr / before.max(1e-9), allin_ab) {
|
||||
out.push((at, rows));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (a, k) in acts.iter().zip(kids) {
|
||||
let mut t = c.clone();
|
||||
let mut agg = (incr, before, prev_top, geraist);
|
||||
match a {
|
||||
Act::Fold | Act::Check => {}
|
||||
Act::Call => t[player] = top,
|
||||
Act::Bet(x) | Act::Raise(x) => {
|
||||
agg = (*x - top, pot + c.iter().sum::<f64>(), top, matches!(a, Act::Raise(_)));
|
||||
t[player] = *x;
|
||||
}
|
||||
}
|
||||
stack.push((*k, t, agg));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The first street's menu; under `SOLVER3_ALLE` it allows as many raises as the observed line holds (the tree must
|
||||
/// contain the line), else as given.
|
||||
pub(crate) fn menu_fuer(line: &[(usize, Act)], mut menu: Menu3) -> Menu3 {
|
||||
@@ -192,6 +318,8 @@ pub fn ohne_from_env() {
|
||||
set_fsperre(std::env::var("SOLVER3_FSPERRE").as_deref() == Ok("1"));
|
||||
set_alle(std::env::var("SOLVER3_ALLE").as_deref() == Ok("1"));
|
||||
set_form(std::env::var("SOLVER3_FORM").as_deref() == Ok("1"));
|
||||
set_linie(std::env::var("SOLVER3_LINIE").as_deref() == Ok("1"));
|
||||
set_pool(std::env::var("SOLVER3_POOL").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(0.0));
|
||||
}
|
||||
|
||||
/// `(nur_offen, ohne)` from `SOLVER_FLOP3` / `SOLVER_TURN3` / `SOLVER_RIVER3` = `offen` and
|
||||
@@ -356,7 +484,8 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
};
|
||||
hands.push(h.or_else(|| weg("mw range leer"))?);
|
||||
}
|
||||
let game = GameM::build_passiv(order.len(), pot, cap, &[menu_fuer(&line, Menu3::standard()), later()], sl, passiv);
|
||||
let menus = [menu_fuer(&line, Menu3::standard()), later()];
|
||||
let game = if linie() { GameM::build_linie(order.len(), pot, cap, &menus, sl, passiv, &line, me) } else { GameM::build_passiv(order.len(), pot, cap, &menus, sl, passiv) };
|
||||
let at = if alle() { game.follow_nachsicht(&line, me) } else { game.follow(&line) }.or_else(|| weg("mw linie nicht im baum"))?;
|
||||
let NodeM::Dec { player, acts, .. } = &game.nodes[at] else { return weg("mw knoten") };
|
||||
if *player != me {
|
||||
@@ -367,6 +496,28 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
let combos: Vec<usize> = hands.iter().map(|h| h.masks.len()).collect();
|
||||
let hero_index = hands[me].masks.iter().position(|m| *m == hero_mask)?;
|
||||
let mut solver = SolverM::new(game, hands, board, spot.seed ^ 0x9e37_79b9_7f4a_7c15);
|
||||
if pool_w() > 0.0 {
|
||||
let masks: Vec<&[u64]> = (0..order.len()).map(|p| solver.masks(p)).collect();
|
||||
let sperren = pool_sperren(spot, &order, me, passiv, &masks, board, pot, cap, &|i| match &solver.game.nodes[i] {
|
||||
NodeM::Dec { player, street: 0, acts, kids } => KnotenSicht::Dec { player: *player, acts, kids },
|
||||
_ => KnotenSicht::Ende,
|
||||
});
|
||||
for (n, rows) in sperren {
|
||||
solver.lock(n, rows, pool_w());
|
||||
}
|
||||
}
|
||||
if linie() {
|
||||
let hands_n: Vec<usize> = (0..order.len()).map(|p| solver.masks(p).len()).collect();
|
||||
if let Some(pfad) = solver.game.pfad_nachsicht(&line, me) {
|
||||
let sperren = linie_sperren(&pfad, me, &|n| match &solver.game.nodes[n] {
|
||||
NodeM::Dec { player, acts, .. } => Some((*player, acts.len())),
|
||||
_ => None,
|
||||
}, &hands_n);
|
||||
for (n, rows) in sperren {
|
||||
solver.lock(n, rows, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
let cpu_stufe = crate::engine::frist::thread_cpu_ms();
|
||||
let mut done = 0u32;
|
||||
let mut zu_gross = false;
|
||||
@@ -404,6 +555,14 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
if done < min_iter {
|
||||
return weg("mw zu wenig iterationen");
|
||||
}
|
||||
if std::env::var("KERN_REGRET").is_ok() {
|
||||
eprintln!("regret chips {:?} hero_index {hero_index} combos {combos:?}", solver.regret_chips(at, hero_index));
|
||||
let mut v: Vec<(u32, String)> = (0..solver.masks(me).len()).map(|h| (fast7::score(solver.masks(me)[h] | board), format!("{:?}", solver.row(at, h).iter().map(|x| (x * 100.0).round() / 100.0).collect::<Vec<_>>()))).collect();
|
||||
v.sort();
|
||||
for (sc, r) in v {
|
||||
eprintln!(" score {sc} row {r}");
|
||||
}
|
||||
}
|
||||
let row = solver.row(at, hero_index);
|
||||
return Some(SolvedM { row, acts, iterations: solver.iterations(), millis: started.elapsed().as_secs_f64() * 1e3, players: order.len(), nodes, combos });
|
||||
}
|
||||
|
||||
@@ -178,7 +178,8 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
};
|
||||
hands.push(h.or_else(|| weg("mw range leer"))?);
|
||||
}
|
||||
let game = Game3::build_passiv(order.len(), pot, cap, &crate::engine::multi3_spieler::menu_fuer(&line, Menu3::standard()), passiv);
|
||||
let menu = crate::engine::multi3_spieler::menu_fuer(&line, Menu3::standard());
|
||||
let game = if crate::engine::multi3_spieler::linie() { Game3::build_linie(order.len(), pot, cap, &menu, passiv, &line, me) } else { Game3::build_passiv(order.len(), pot, cap, &menu, passiv) };
|
||||
let at = if crate::engine::multi3_spieler::alle() { game.follow_nachsicht(&line, me) } else { game.follow(&line) }.or_else(|| weg("mw linie nicht im baum"))?;
|
||||
let Node3::Dec { player, acts, .. } = &game.nodes[at] else { return weg("mw knoten") };
|
||||
if *player != me {
|
||||
@@ -189,6 +190,29 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
let combos: Vec<usize> = hands.iter().map(|h| h.masks.len()).collect();
|
||||
let hero_index = hands[me].masks.iter().position(|m| *m == hero_mask)?;
|
||||
let mut solver = Solver3::new(game, hands, board, spot.seed ^ 0x9e37_79b9_7f4a_7c15);
|
||||
let w = crate::engine::multi3_spieler::pool_w();
|
||||
if w > 0.0 {
|
||||
let masks: Vec<&[u64]> = (0..order.len()).map(|p| solver.masks(p)).collect();
|
||||
let sperren = crate::engine::multi3_spieler::pool_sperren(spot, &order, me, passiv, &masks, board, pot, cap, &|i| match &solver.game.nodes[i] {
|
||||
Node3::Dec { player, acts, kids } => crate::engine::multi3_spieler::KnotenSicht::Dec { player: *player, acts, kids },
|
||||
Node3::Term { .. } => crate::engine::multi3_spieler::KnotenSicht::Ende,
|
||||
});
|
||||
for (n, rows) in sperren {
|
||||
solver.lock(n, rows, w);
|
||||
}
|
||||
}
|
||||
if crate::engine::multi3_spieler::linie() {
|
||||
let hands_n: Vec<usize> = (0..order.len()).map(|p| solver.masks(p).len()).collect();
|
||||
if let Some(pfad) = solver.game.pfad_nachsicht(&line, me) {
|
||||
let sperren = crate::engine::multi3_spieler::linie_sperren(&pfad, me, &|n| match &solver.game.nodes[n] {
|
||||
Node3::Dec { player, acts, .. } => Some((*player, acts.len())),
|
||||
_ => None,
|
||||
}, &hands_n);
|
||||
for (n, rows) in sperren {
|
||||
solver.lock(n, rows, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut done = 0u32;
|
||||
while done < ITERS {
|
||||
solver.iterate();
|
||||
@@ -200,10 +224,38 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
if done < MIN_ITERS {
|
||||
return crate::engine::multi3_spieler::weg("mw zu wenig iterationen");
|
||||
}
|
||||
if std::env::var("KERN_REGRET").is_ok() {
|
||||
eprintln!("regret chips {:?}", solver.regret_chips(at, hero_index));
|
||||
let n = solver.masks(me).len();
|
||||
let mut v: Vec<f64> = (0..n).map(|h| solver.regret_chips(at, h).iter().fold(0.0f64, |m, x| m.max(x.abs()))).collect();
|
||||
v.sort_by(f64::total_cmp);
|
||||
eprintln!("max |regret| je Hand (sortiert) {:?}", v);
|
||||
}
|
||||
let row = solver.row(at, hero_index);
|
||||
Some(Solved3 { row, acts, iterations: solver.iterations(), millis: started.elapsed().as_secs_f64() * 1e3, players: order.len(), nodes, combos })
|
||||
}
|
||||
|
||||
/// Diagnosis only (`kern_zeile`): per player (acting order) the model combos' showdown scores against hero's, `(better, tie, worse)` counts.
|
||||
pub fn debug_bereiche(spot: &Spot) -> Option<Vec<(u8, usize, usize, usize, usize)>> {
|
||||
let order = acting_order(spot)?;
|
||||
let board = fast7::mask(&spot.board);
|
||||
let hero_mask = fast7::mask(&spot.hero_cards);
|
||||
let hs = fast7::score(hero_mask | board);
|
||||
let mut out = Vec::new();
|
||||
for seat in &order {
|
||||
let v = if *seat == spot.hero_seat { Villain { seat: *seat, stack: spot.hero_stack, folded: false, profile: None } } else { spot.live_villains().find(|v| v.seat == *seat)?.clone() };
|
||||
let h = model_hands(spot, &v, board, if *seat == spot.hero_seat { Some(hero_mask) } else { None }, MAX_COMBOS)?;
|
||||
let (mut b, mut t, mut w) = (0, 0, 0);
|
||||
for m in &h.masks {
|
||||
if m & hero_mask != 0 { continue; }
|
||||
let s = fast7::score(m | board);
|
||||
if s > hs { b += 1 } else if s == hs { t += 1 } else { w += 1 }
|
||||
}
|
||||
out.push((*seat, h.masks.len(), b, t, w));
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// The live multiway-river decision, or `None` and the heuristic keeps it.
|
||||
pub fn river3_decision(raw: &Spot) -> Option<Decision> {
|
||||
if !river3() || raw.street != Street::River || raw.hero_cards.len() != 2 || raw.board.len() != 5 || raw.live_villains().count() < 2 {
|
||||
|
||||
@@ -269,12 +269,12 @@ fn interp(k: &[(f64, f64)], r: f64) -> f64 {
|
||||
/// Teil A `river|<Fach>`, 19.10.–16.11., n ≥ 37 000 je Fach); All-in: 0.
|
||||
const RAISE_POOL: [(f64, f64); 8] = [(0.20, 0.21), (0.33, 0.143), (0.48, 0.11), (0.62, 0.095), (0.77, 0.086), (0.97, 0.079), (1.3, 0.066), (2.0, 0.047)];
|
||||
|
||||
fn raise_pool(r: f64) -> f64 {
|
||||
pub(crate) fn raise_pool(r: f64) -> f64 {
|
||||
interp(&RAISE_POOL, r)
|
||||
}
|
||||
|
||||
/// Weicher Übergang: Anteil `share` am unteren (`von_unten`) Ende der Range, Breite `h` im Perzentil.
|
||||
fn rampe(q: f64, share: f64, h: f64, von_unten: bool) -> f64 {
|
||||
pub(crate) fn rampe(q: f64, share: f64, h: f64, von_unten: bool) -> f64 {
|
||||
if share <= 0.0 {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user