Mehrweg-Loeser: SOLVER3_KARTE=zufall (Draw-Outs treffen mit wahrer Rate), SOLVER3_TIEF=1 (Poolsperre auch auf der Folgestrasse)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,7 +38,7 @@ SCHALTER_DATEI = os.path.join(BASE, "..", "betrieb", "kern_schalter.txt")
|
||||
# GEGNER_ZAEHLUNG=1 ist kein Kern-Schalter, sondern einer des Laeufers (betrieb/runner.py): die gezaehlten
|
||||
# Reads je Gegner gehen in die Profile. Er steht hier, damit er in der Arm-Marke jeder Hand steht.
|
||||
BEKANNTE_SCHALTER = ("FAUSTREGEL", "MDF_UNREAD", "RAISE_DRAWS", "RAISE_PRIOR", "TURN_SPIEL", "GRUNDSTRATEGIE", "OPEN_JAM",
|
||||
"SOLVER_RIVER", "SOLVER_KERN", "SOLVER_TURN", "SOLVER_FLOP", "SOLVER_RIVER3", "SOLVER_TURN3", "SOLVER_FLOP3", "SOLVER3_OHNE", "SOLVER3_MS", "SOLVER3_ROHNE", "SOLVER3_FOHNE", "SOLVER3_TOHNE", "SOLVER3_FSPERRE", "SOLVER3_ALLE", "SOLVER3_FORM", "SOLVER3_POOL", "SOLVER3_LINIE", "ALLIN_EINSATZ", "ALLIN_RANGE",
|
||||
"SOLVER_RIVER", "SOLVER_KERN", "SOLVER_TURN", "SOLVER_FLOP", "SOLVER_RIVER3", "SOLVER_TURN3", "SOLVER_FLOP3", "SOLVER3_OHNE", "SOLVER3_MS", "SOLVER3_ROHNE", "SOLVER3_FOHNE", "SOLVER3_TOHNE", "SOLVER3_FSPERRE", "SOLVER3_ALLE", "SOLVER3_FORM", "SOLVER3_POOL", "SOLVER3_LINIE", "SOLVER3_KARTE", "SOLVER3_OFFEN", "SOLVER3_TIEF", "ALLIN_EINSATZ", "ALLIN_RANGE",
|
||||
"RAKE_LIVE", "GEGNER_ZAEHLUNG", "GEGNER_SHOWDOWN", "GEGNER_RANGE", "GEGNER_BREIT",
|
||||
"GEGNER_POOL", "GEGNER_POOL_STUFE", "RERAISE_TIEFE", "RERAISE_BLUFF",
|
||||
"TURN_RAISE_BLUFF", "TURN_RAISE_NUR", "STATION_POSTFLOP", "POKERINTEL",
|
||||
|
||||
@@ -45,3 +45,24 @@ gepaart auf den Turn-Spots nachgemessen.)
|
||||
Nicht im Bündel: Turnier-Spots mit ICM-Prämie und Omaha gehen weiter an die Heuristik (der Rückfall ist dort nicht
|
||||
verdrahtet). Die Heuristik-Codepfade werden nach positivem Bündel-Lauf gelöscht, nicht vorher: bis dahin ist
|
||||
`FAUSTREGEL=aus` der Halbierungsschalter.
|
||||
|
||||
## Mehrweg-Zug (fn-mw-zug, 19.11.): zwei Lecks im Mehrwege-Löser
|
||||
|
||||
Neue Schalter, einzeln schaltbar, in BEKANNTE_SCHALTER: `SOLVER3_KARTE=zufall`, `SOLVER3_TIEF=1`, (`SOLVER3_OFFEN=<w>`, gemessen
|
||||
negativ, bleibt aus). Arm = Bündel-Arm plus `SOLVER3_KARTE=zufall;SOLVER3_TIEF=1`.
|
||||
|
||||
1. **Draws folden (Turn, 3-way, "Fold p 0,99-1,00").** Ursache: die Karte der nächsten Straße wurde aus wenigen festen
|
||||
Vertretern gezogen (Schritt über ein farbweises Deck). Bei 2-4 Slots (Rückfallstufen unter `SOLVER3_ALLE`) lag die Trefferquote eines
|
||||
8-Outs-Draws bei 0, 1/2 oder 1 statt 8/44; der Draw wirkte tot und wurde gefoldet. `SOLVER3_KARTE=zufall` zieht gleichverteilt aus allen
|
||||
ungesehenen Karten und ordnet sie rangsortierten Slots zu. Test: `random_cards_hit_a_draw_at_its_true_rate`.
|
||||
2. **Value-Hände checken (Mehrweg).** Ursache: die Poolsperre (Fold-Kurve) wirkte nur auf der ersten Straße; auf der Folgestraße
|
||||
spielten die Gegner im Baum frei (zu viele Checks, Value verpufft). `SOLVER3_TIEF=1` läuft über den Kartenknoten und sperrt auch
|
||||
die Folgestraße (Linie aus dem letzten Aggressor der ersten Straße). Test: `tief_walk_reaches_the_next_street`.
|
||||
|
||||
Messung (113 Mehrweg-Spots der 628 Starkfälle, Kern-Wiederholung): Draws gegen Einsatz 57 und 116 jetzt Call/Raise; die Spots, die
|
||||
weiter folden (26, 30, 80, 106, 118), haben 17-21 % Equity gegen 23-25 % Break-even, also zu Recht. Value-Hände 189, 291, 342, 608, 295,
|
||||
461, 173 setzen bei MS=300; 190, 189, 448 mischen noch Check (bei 8-10k Iterationen Bet 40-60 %).
|
||||
Nicht-Reproduzierbarkeit der Replays (Zeitbudget, Thread-Reihenfolge) unverändert: 8-14 abweichende Aktionen je 113 Mehrweg-Spots
|
||||
vorher wie nachher.
|
||||
Latenz (unter schwerer Maschinenlast): max 3359 ms neu gegen 2469 ms Basis; 4-5-Wege-Flop/Turn dominieren, schon die Basis lag darüber.
|
||||
Der zusätzliche Sperrgang kostet 15-120 ms je Lösung. Pflichtfälle: BESTANDEN (43/44, live 38/44, Ziele 3/4). Abdeckung 0/238.
|
||||
|
||||
+64
-7
@@ -371,12 +371,25 @@ fn deck() -> Vec<u64> {
|
||||
(0..4).flat_map(|s| (0..13).map(move |r| 1u64 << (16 * s + r))).collect()
|
||||
}
|
||||
|
||||
/// `SOLVER3_KARTE=zufall` (default off): the next street's card is drawn uniformly from every undealt card and only
|
||||
/// *mapped* onto a slot (a chunk of neighbouring ranks), instead of dealing a few fixed representative cards. The fixed
|
||||
/// representatives (an even stride over a suit-major deck) hit a draw's outs by aliasing: 8 outs among 46 cards are 17 %
|
||||
/// of the river, but with 8 slots 0 to 2 slots hit (0 to 25 %), with 4 slots (the first fallback under time pressure) 0
|
||||
/// to 50 %, with 2 slots 0, 50 or 100 %. A draw was then valued at ~0 and folded at "p 1.00" (live replay 19.11.).
|
||||
static ZUFALL: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
pub fn set_zufall(on: bool) {
|
||||
ZUFALL.store(on, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub struct SolverM {
|
||||
pub game: GameM,
|
||||
hands: Vec<Hands3>,
|
||||
board: u64,
|
||||
/// The slot cards of the next street (evenly strided over the undealt deck).
|
||||
slot_cards: Vec<u64>,
|
||||
/// `SOLVER3_KARTE=zufall`: every undealt card with its slot (rank-ordered chunks); empty = the fixed slot cards.
|
||||
karten_slot: Vec<(u64, usize)>,
|
||||
/// Cards dealt per iteration beyond the slot card (uniformly from the rest).
|
||||
extra: usize,
|
||||
cum: Vec<Vec<f64>>,
|
||||
@@ -385,7 +398,7 @@ pub struct SolverM {
|
||||
rng: Xs,
|
||||
t: u64,
|
||||
/// As `river3::Solver3`: the pool's row per hand and its weight per node.
|
||||
locks: Vec<Option<(Vec<f64>, f64)>>,
|
||||
locks: Vec<Option<(std::sync::Arc<Vec<f64>>, f64)>>,
|
||||
}
|
||||
|
||||
/// One iteration's sampled cards.
|
||||
@@ -401,6 +414,11 @@ struct Draw {
|
||||
impl SolverM {
|
||||
/// `hands[p]` per player in acting order; `board` = the cards out now (3 or 4).
|
||||
pub fn new(game: GameM, hands: Vec<Hands3>, board: u64, seed: u64) -> SolverM {
|
||||
Self::new_mit(game, hands, board, seed, ZUFALL.load(std::sync::atomic::Ordering::Relaxed))
|
||||
}
|
||||
|
||||
/// As `new`, with the card mode given (`zufall`: see `ZUFALL`).
|
||||
pub fn new_mit(game: GameM, hands: Vec<Hands3>, board: u64, seed: u64, zufall: bool) -> SolverM {
|
||||
assert_eq!(hands.len(), game.players);
|
||||
let undealt: Vec<u64> = deck().into_iter().filter(|c| c & board == 0).collect();
|
||||
let k = game.slots.min(undealt.len());
|
||||
@@ -427,11 +445,25 @@ impl SolverM {
|
||||
_ => Vec::new(),
|
||||
}).collect();
|
||||
let locks = vec![None; game.nodes.len()];
|
||||
SolverM { game, hands, board, slot_cards, extra, cum, regret, avg, rng: Xs(seed | 1), t: 0, locks }
|
||||
let karten_slot = if zufall && !undealt.is_empty() {
|
||||
// Rank-major order (low to high, the suits of a rank together), cut into `k` chunks of nearly equal size.
|
||||
let mut by_rank = undealt.clone();
|
||||
by_rank.sort_by_key(|c| (c.trailing_zeros() % 16, c.trailing_zeros() / 16));
|
||||
let n = by_rank.len();
|
||||
by_rank.iter().enumerate().map(|(i, c)| (*c, (i * k / n).min(k.saturating_sub(1)))).collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
SolverM { game, hands, board, slot_cards, karten_slot, extra, cum, regret, avg, rng: Xs(seed | 1), t: 0, locks }
|
||||
}
|
||||
|
||||
/// Lock `node`'s player to the pool rows `rows` (one row per hand over the node's acts) with weight `w`.
|
||||
pub fn lock(&mut self, node: usize, rows: Vec<f64>, w: f64) {
|
||||
self.locks[node] = Some((std::sync::Arc::new(rows), w.clamp(0.0, 1.0)));
|
||||
}
|
||||
|
||||
/// As `lock`, the rows shared with other nodes (the later streets' nodes repeat one row per player and card slot).
|
||||
pub fn lock_geteilt(&mut self, node: usize, rows: std::sync::Arc<Vec<f64>>, w: f64) {
|
||||
self.locks[node] = Some((rows, w.clamp(0.0, 1.0)));
|
||||
}
|
||||
|
||||
@@ -439,6 +471,20 @@ impl SolverM {
|
||||
&self.hands[p].masks
|
||||
}
|
||||
|
||||
/// One card per slot of the next street, the one the locks rank the hands on: the fixed slot card, or (`zufall`) the
|
||||
/// middle card of the slot's chunk.
|
||||
pub fn slot_vertreter(&self) -> Vec<u64> {
|
||||
if self.karten_slot.is_empty() {
|
||||
return self.slot_cards.clone();
|
||||
}
|
||||
(0..self.slot_cards.len())
|
||||
.map(|j| {
|
||||
let drin: Vec<u64> = self.karten_slot.iter().filter(|(_, s)| *s == j).map(|(c, _)| *c).collect();
|
||||
drin.get(drin.len() / 2).copied().unwrap_or(0)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn sample(&mut self, p: usize) -> usize {
|
||||
let c = &self.cum[p];
|
||||
let x = self.rng.unit() * c.last().copied().unwrap_or(0.0);
|
||||
@@ -475,12 +521,23 @@ impl SolverM {
|
||||
let mut run = 0u64;
|
||||
let mut slot = 0;
|
||||
if missing > 0 {
|
||||
let free: Vec<usize> = (0..self.slot_cards.len()).filter(|j| self.slot_cards[*j] & used == 0).collect();
|
||||
if free.is_empty() {
|
||||
return None;
|
||||
if self.karten_slot.is_empty() {
|
||||
let free: Vec<usize> = (0..self.slot_cards.len()).filter(|j| self.slot_cards[*j] & used == 0).collect();
|
||||
if free.is_empty() {
|
||||
return None;
|
||||
}
|
||||
slot = free[self.rng.below(free.len())];
|
||||
run |= self.slot_cards[slot];
|
||||
} else {
|
||||
// Uniform over every card no sampled hand holds; its slot only picks the subtree.
|
||||
let free: Vec<(u64, usize)> = self.karten_slot.iter().copied().filter(|(c, _)| c & used == 0).collect();
|
||||
if free.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let (c, s) = free[self.rng.below(free.len())];
|
||||
slot = s;
|
||||
run |= c;
|
||||
}
|
||||
slot = free[self.rng.below(free.len())];
|
||||
run |= self.slot_cards[slot];
|
||||
}
|
||||
for _ in 0..self.extra {
|
||||
let rest: Vec<u64> = deck().into_iter().filter(|c| c & (self.board | used | run) == 0).collect();
|
||||
|
||||
@@ -119,3 +119,29 @@ fn timing() {
|
||||
println!("{label}: {nodes} nodes, {} hands, 2000 iters {:.0} ms", h.masks.len(), t.elapsed().as_secs_f64() * 1e3);
|
||||
}
|
||||
}
|
||||
|
||||
/// The next street's card is drawn from the whole deck, not from a few fixed representatives: a draw with 8 outs hits the
|
||||
/// river in about 8/44 of the draws however few slots the game has. With fixed representatives and 2 slots the same draw
|
||||
/// hit 0, 1/2 or 1 of the time (the stride aliasing with the suit-major deck; live replay 19.11.: draws folded at p 1.00).
|
||||
#[test]
|
||||
fn random_cards_hit_a_draw_at_its_true_rate() {
|
||||
// Board 9c 6s 5d Qh: hero's 4s 7s has an open-ended draw (four eights, four threes) against two pairs of kings.
|
||||
let b = fast7::mask(&Card::parse_list("9c 6s 5d Qh").unwrap());
|
||||
let hand = |c: &str| Hands3 { masks: vec![fast7::mask(&Card::parse_list(c).unwrap())], weights: vec![1.0] };
|
||||
let wahr = 8.0 / 44.0;
|
||||
for slots in [2usize, 4, 8] {
|
||||
let g = GameM::build(3, 10.0, 100.0, &[Menu3::standard(), later()], slots);
|
||||
let mut s = SolverM::new_mit(g, vec![hand("4s 7s"), hand("Kd Kc"), hand("Kh Ks")], b, 7, true);
|
||||
let (mut hits, mut n) = (0, 0);
|
||||
for _ in 0..8_000 {
|
||||
let Some(d) = s.draw(0) else { continue };
|
||||
n += 1;
|
||||
// Hero's score (+1) beats both pairs of kings only when the river makes the straight.
|
||||
if d.mine[0] > d.opp[1].max(d.opp[2]) + 1 {
|
||||
hits += 1;
|
||||
}
|
||||
}
|
||||
let anteil = hits as f64 / n as f64;
|
||||
assert!((anteil - wahr).abs() < 0.02, "{slots} slots: hero wins {anteil:.3}, the draw hits {wahr:.3}");
|
||||
}
|
||||
}
|
||||
|
||||
+190
-29
@@ -102,8 +102,11 @@ pub(crate) fn linie_sperren(pfad: &[(usize, usize)], me: usize, spieler: &dyn Fn
|
||||
/// 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())?;
|
||||
fn pool_zeile(spot: &Spot, who: &Villain, acts: &[Act], q: &[f64], ratio: f64, allin_ab: f64, strasse: Street, linie: Option<usize>) -> Option<Vec<f64>> {
|
||||
let f = match linie {
|
||||
None => crate::exploit::wett_kurve::pool_fold(spot, strasse, ratio, allin_ab, who.profile.as_ref())?,
|
||||
Some(l) => crate::exploit::wett_kurve::pool_fold_linie(strasse, l, 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)?;
|
||||
@@ -124,13 +127,68 @@ fn pool_zeile(spot: &Spot, who: &Villain, acts: &[Act], q: &[f64], ratio: f64, a
|
||||
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).
|
||||
/// `SOLVER3_OFFEN=<w>` (0 < w <= 1): the villains of the multiway solvers play an OPEN node (nobody has bet, they may bet) like the
|
||||
/// measured pool (the `BETTOR` table by board percentile, as the heads-up core's open nodes) instead of like equilibrium
|
||||
/// players. Cause of the checked-back value hands (replay 19.11.): the tree locked every villain's answer to hero's bet to
|
||||
/// the pool but left what he does after hero CHECKS to CFR; a CFR villain bets into a check with bluffs and thin value at
|
||||
/// equilibrium frequency, hero's check collected from them and beat every bet (top two pair, a straight: check 0.8 to 1.0),
|
||||
/// while the NL2 pool rarely bluffs. Thousandths, default 0 = off.
|
||||
static OFFEN: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
|
||||
pub fn set_offen(w: f64) {
|
||||
OFFEN.store((w.clamp(0.0, 1.0) * 1000.0).round() as u32, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn offen_w() -> f64 {
|
||||
OFFEN.load(Ordering::Relaxed) as f64 / 1000.0
|
||||
}
|
||||
|
||||
/// What `pool_sperren` needs of a node: the actor, its acts and its kids, or a deal (the kids are the slots of the next
|
||||
/// street's card), or the end.
|
||||
pub(crate) enum KnotenSicht<'a> {
|
||||
Dec { player: usize, acts: &'a [Act], kids: &'a [usize] },
|
||||
Deal { 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`;
|
||||
/// `SOLVER3_TIEF=1`: the pool locks (`SOLVER3_POOL`, `SOLVER3_OFFEN`) also hold on the streets AFTER the first one (the river of
|
||||
/// the turn game, the turn of the flop game), at every card slot. Cause of the second half of the checked-back value hands
|
||||
/// (replay 19.11.): the villains' answers on the first street were the pool's, but on every later street they were CFR players
|
||||
/// again, who fold exactly the hands that lose to hero's betting range there and never pay off with a worse one: a bet on the
|
||||
/// turn bought nothing on the river, checking (hiding the range) beat every bet. Default off.
|
||||
static TIEF: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub fn set_tief(on: bool) {
|
||||
TIEF.store(on, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn tief() -> bool {
|
||||
TIEF.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// One walk state of `pool_sperren`.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Gang {
|
||||
at: usize,
|
||||
/// Contributions over the whole game.
|
||||
c: [f64; 12],
|
||||
/// The last bet or raise of the street: its increment, the pot before it, the level before it, whether it was a raise.
|
||||
incr: f64,
|
||||
before: f64,
|
||||
prev_top: f64,
|
||||
geraist: bool,
|
||||
/// Every player's contribution at the start of this street, the street (0 = the one decided) and its card slot.
|
||||
level: f64,
|
||||
st: usize,
|
||||
slot: usize,
|
||||
/// Street 0: the last player to bet or raise (`pool_fold`'s line of the next street) and all who did.
|
||||
letzter: Option<usize>,
|
||||
aggr: u32,
|
||||
}
|
||||
|
||||
/// The nodes of the first betting round at which a villain faces a bet (index, pool rows) and, with `offen`, the nodes at which
|
||||
/// he may bet into a street nobody has bet yet (index, `BETTOR` rows); with `karten` (the slot cards of the next street) also
|
||||
/// the same nodes of the next street at every slot. `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)]
|
||||
@@ -143,38 +201,121 @@ pub(crate) fn pool_sperren<'a>(
|
||||
board: u64,
|
||||
pot: f64,
|
||||
cap: f64,
|
||||
offen: bool,
|
||||
karten: Option<&[u64]>,
|
||||
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();
|
||||
) -> (Vec<(usize, std::sync::Arc<Vec<f64>>)>, Vec<(usize, std::sync::Arc<Vec<f64>>)>) {
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
let mut ranks: HashMap<(usize, usize), Vec<f64>> = HashMap::new();
|
||||
let mut brett_pct: HashMap<(usize, usize), Vec<f64>> = HashMap::new();
|
||||
// The board of a node: the cards out now, plus (on a later street) the slot's card (a combo that holds that card is never
|
||||
// dealt in that slot; its rank there is not used).
|
||||
let brett_von = |st: usize, slot: usize| -> u64 { if st == 0 { board } else { board | karten.map_or(0, |k| k[slot.min(k.len().saturating_sub(1))]) } };
|
||||
let mut gecacht: HashMap<(u8, usize, usize, u64), Arc<Vec<f64>>> = HashMap::new();
|
||||
let hash = |zahlen: &[u64]| -> u64 { zahlen.iter().fold(0xcbf2_9ce4_8422_2325u64, |h, z| (h ^ z).wrapping_mul(0x0100_0000_01b3).rotate_left(23)) };
|
||||
if order.len() > 12 {
|
||||
return (Vec::new(), Vec::new());
|
||||
}
|
||||
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 {
|
||||
let mut frei = Vec::new();
|
||||
let naechste = match spot.street {
|
||||
Street::Flop => Street::Turn,
|
||||
_ => Street::River,
|
||||
};
|
||||
let mut stack = vec![Gang { at: 0, c: [0.0; 12], incr: 0.0, before: pot, prev_top: 0.0, geraist: false, level: 0.0, st: 0, slot: 0, letzter: None, aggr: 0 }];
|
||||
while let Some(g) = stack.pop() {
|
||||
let (player, acts, kids) = match knoten(g.at) {
|
||||
KnotenSicht::Dec { player, acts, kids } => (player, acts, kids),
|
||||
KnotenSicht::Deal { kids } => {
|
||||
if karten.is_some_and(|k| !k.is_empty()) {
|
||||
let top = g.c.iter().copied().fold(0.0, f64::max);
|
||||
for (j, k) in kids.iter().enumerate() {
|
||||
stack.push(Gang { at: *k, c: g.c, incr: 0.0, before: pot + g.c.iter().sum::<f64>(), prev_top: top, geraist: false, level: top, st: g.st + 1, slot: j, letzter: g.letzter, aggr: g.aggr });
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
KnotenSicht::Ende => continue,
|
||||
};
|
||||
let top = g.c.iter().copied().fold(0.0, f64::max);
|
||||
let strasse = if g.st == 0 { spot.street } else { naechste };
|
||||
let live = player != me && passive & (1 << player) == 0;
|
||||
if live && (offen && !acts.contains(&Act::Fold) && g.incr == 0.0 && acts.iter().any(|a| matches!(a, Act::Bet(_))) || acts.contains(&Act::Fold) && g.incr > 0.0 && !g.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));
|
||||
let b = brett_von(g.st, g.slot);
|
||||
if acts.contains(&Act::Fold) {
|
||||
let r = ranks.entry((player, g.slot + g.st * 64)).or_insert_with(|| crate::engine::river_spieler::percentiles(masks[player], &vec![1.0; masks[player].len()], b));
|
||||
let allin_ab = (cap - g.prev_top) / g.before.max(1e-9);
|
||||
let ratio = g.incr / g.before.max(1e-9);
|
||||
let linie = if g.st == 0 { None } else if g.letzter == Some(me) { Some(0) } else if g.letzter.is_some() { Some(3) } else { Some(1) };
|
||||
let schl = (0u8, player, g.slot + g.st * 64, hash(&[ratio.to_bits(), allin_ab.to_bits(), linie.map_or(9, |l| l as u64), acts.len() as u64]));
|
||||
let rows = match gecacht.get(&schl) {
|
||||
Some(x) => Some(x.clone()),
|
||||
None => pool_zeile(spot, who, acts, r, ratio, allin_ab, strasse, linie).map(|v| {
|
||||
let a = Arc::new(v);
|
||||
gecacht.insert(schl, a.clone());
|
||||
a
|
||||
}),
|
||||
};
|
||||
if let Some(rows) = rows {
|
||||
out.push((g.at, rows));
|
||||
}
|
||||
} else {
|
||||
let pfa = spot.history.iter().rev().find(|r| r.street == Street::Preflop && r.action.is_aggressive()).is_some_and(|r| r.seat == who.seat);
|
||||
let before = match g.st {
|
||||
0 => match spot.street {
|
||||
Street::Turn => spot.history.iter().any(|r| r.seat == who.seat && r.street == Street::Flop && r.action.is_aggressive()),
|
||||
Street::River => spot.history.iter().any(|r| r.seat == who.seat && r.street == Street::Turn && r.action.is_aggressive()),
|
||||
_ => false,
|
||||
},
|
||||
_ => g.aggr & (1 << player) != 0,
|
||||
};
|
||||
let pot_now = pot + g.c.iter().sum::<f64>();
|
||||
let pct = brett_pct.entry((player, g.slot + g.st * 64)).or_insert_with(|| crate::engine::solver_kern::brett_perzentil(masks[player], b));
|
||||
let cap_str = cap - g.level;
|
||||
let mut schl = vec![pot_now.to_bits(), cap_str.to_bits(), pfa as u64, before as u64];
|
||||
schl.extend(acts.iter().map(|a| match a {
|
||||
Act::Bet(x) => x.to_bits(),
|
||||
_ => 0,
|
||||
}));
|
||||
let schl = (1u8, player, g.slot + g.st * 64, hash(&schl));
|
||||
let rows = match gecacht.get(&schl) {
|
||||
Some(x) => Some(x.clone()),
|
||||
None => crate::engine::solver_kern::offen_zeile(strasse, pfa, before, pct, acts, pot_now, cap_str).map(|v| {
|
||||
let a = Arc::new(v);
|
||||
gecacht.insert(schl, a.clone());
|
||||
a
|
||||
}),
|
||||
};
|
||||
if let Some(rows) = rows {
|
||||
frei.push((g.at, rows));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (a, k) in acts.iter().zip(kids) {
|
||||
let mut t = c.clone();
|
||||
let mut agg = (incr, before, prev_top, geraist);
|
||||
let mut t = Gang { at: *k, c: g.c, incr: g.incr, before: g.before, prev_top: g.prev_top, geraist: g.geraist, level: g.level, st: g.st, slot: g.slot, letzter: g.letzter, aggr: g.aggr };
|
||||
match a {
|
||||
Act::Fold | Act::Check => {}
|
||||
Act::Call => t[player] = top,
|
||||
Act::Call => t.c[player] = top,
|
||||
Act::Bet(x) | Act::Raise(x) => {
|
||||
agg = (*x - top, pot + c.iter().sum::<f64>(), top, matches!(a, Act::Raise(_)));
|
||||
t[player] = *x;
|
||||
let total = g.level + *x;
|
||||
t.incr = total - top;
|
||||
t.before = pot + g.c.iter().sum::<f64>();
|
||||
t.prev_top = top;
|
||||
t.geraist = matches!(a, Act::Raise(_));
|
||||
t.c[player] = total;
|
||||
if g.st == 0 {
|
||||
t.letzter = Some(player);
|
||||
t.aggr |= 1 << player;
|
||||
}
|
||||
}
|
||||
}
|
||||
stack.push((*k, t, agg));
|
||||
stack.push(t);
|
||||
}
|
||||
}
|
||||
out
|
||||
(out, frei)
|
||||
}
|
||||
|
||||
/// The first street's menu; under `SOLVER3_ALLE` it allows as many raises as the observed line holds (the tree must
|
||||
@@ -319,6 +460,9 @@ pub fn ohne_from_env() {
|
||||
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"));
|
||||
crate::cfr::multi3::set_zufall(std::env::var("SOLVER3_KARTE").as_deref() == Ok("zufall"));
|
||||
set_tief(std::env::var("SOLVER3_TIEF").as_deref() == Ok("1"));
|
||||
set_offen(std::env::var("SOLVER3_OFFEN").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(0.0));
|
||||
set_pool(std::env::var("SOLVER3_POOL").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(0.0));
|
||||
}
|
||||
|
||||
@@ -438,6 +582,7 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
Street::Flop => (3, FLOP_BUDGET_MS, crate::engine::frist::FLOP_MS, FLOP_SLOTS),
|
||||
_ => return None,
|
||||
};
|
||||
let slots = std::env::var("KERN_SLOTS").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(slots);
|
||||
if spot.board.len() != cards || spot.hero_cards.len() != 2 || villains < 2 {
|
||||
return weg("mw lage");
|
||||
}
|
||||
@@ -474,6 +619,10 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
let stufen: Vec<(usize, usize)> = if alle() { vec![(MAX_COMBOS, slots), (100, (slots / 2).max(2)), (50, 2)] } else { vec![(MAX_COMBOS, slots)] };
|
||||
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());
|
||||
if erzwungen.is_some_and(|n| n != lvl) {
|
||||
continue;
|
||||
}
|
||||
let mut hands = Vec::with_capacity(order.len());
|
||||
for seat in &order {
|
||||
let h = if *seat == spot.hero_seat {
|
||||
@@ -496,14 +645,26 @@ 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 },
|
||||
if pool_w() > 0.0 || offen_w() > 0.0 {
|
||||
let masks: Vec<&[u64]> = (0..order.len()).map(|p| solver.masks(p)).collect();
|
||||
let t_sperre = std::time::Instant::now();
|
||||
let vertreter = solver.slot_vertreter();
|
||||
let karten = if tief() { Some(&vertreter[..]) } else { None };
|
||||
let (sperren, frei) = pool_sperren(spot, &order, me, passiv, &masks, board, pot, cap, offen_w() > 0.0, karten, &|i| match &solver.game.nodes[i] {
|
||||
NodeM::Dec { player, acts, kids, .. } => KnotenSicht::Dec { player: *player, acts, kids },
|
||||
NodeM::Deal { kids } => KnotenSicht::Deal { kids },
|
||||
_ => KnotenSicht::Ende,
|
||||
});
|
||||
for (n, rows) in sperren {
|
||||
solver.lock(n, rows, pool_w());
|
||||
if pool_w() > 0.0 {
|
||||
for (n, rows) in sperren {
|
||||
solver.lock_geteilt(n, rows, pool_w());
|
||||
}
|
||||
}
|
||||
for (n, rows) in frei {
|
||||
solver.lock_geteilt(n, rows, offen_w());
|
||||
}
|
||||
if std::env::var("KERN_REGRET").is_ok() {
|
||||
eprintln!("sperren {:.1} ms, {} nodes", t_sperre.elapsed().as_secs_f64() * 1e3, solver.game.nodes.len());
|
||||
}
|
||||
}
|
||||
if linie() {
|
||||
@@ -526,7 +687,7 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
let jetzt = crate::engine::frist::thread_cpu_ms();
|
||||
if done == 30 && !letzte && (jetzt - cpu_stufe) / 30.0 * MIN_ITERS as f64 > budget - (jetzt - cpu0) {
|
||||
if done == 30 && !letzte && erzwungen.is_none() && (jetzt - cpu_stufe) / 30.0 * MIN_ITERS as f64 > budget - (jetzt - cpu0) {
|
||||
zu_gross = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -246,3 +246,42 @@ fn form_shapes_the_row() {
|
||||
assert!(!form_row(&facing, &acts, &mut row));
|
||||
set_fsperre(false);
|
||||
}
|
||||
|
||||
/// `SOLVER3_TIEF`: the pool-lock walk also reaches the nodes of the street after the deal (at every slot), not only the first
|
||||
/// street; without the slot cards it stops at the deal node as before.
|
||||
#[test]
|
||||
fn tief_walk_reaches_the_next_street() {
|
||||
use crate::cfr::multi3::{GameM, NodeM};
|
||||
use crate::cfr::river3::Menu3;
|
||||
use crate::hand::fast7;
|
||||
let spot = three_way(Street::Turn, "As Ad");
|
||||
let order = acting_order(&spot).unwrap();
|
||||
let me = order.iter().position(|s| *s == spot.hero_seat).unwrap();
|
||||
let board = fast7::mask(&spot.board);
|
||||
let later = Menu3 { fracs: vec![0.75], raise_mult: 3.0, max_raises: 1, allin: true };
|
||||
let game = GameM::build(3, 18.75, 90.0, &[Menu3::standard(), later], 3);
|
||||
let hands: Vec<u64> = vec![fast7::mask(&Card::parse_list("9c 8h").unwrap())];
|
||||
let masks: Vec<&[u64]> = vec![&hands, &hands, &hands];
|
||||
let besucht = |karten: Option<&[u64]>| {
|
||||
let n = std::cell::Cell::new((0usize, 0usize));
|
||||
let sicht = |i: usize| {
|
||||
match &game.nodes[i] {
|
||||
NodeM::Dec { player, street, acts, kids } => {
|
||||
let (a, b) = n.get();
|
||||
n.set(if *street == 0 { (a + 1, b) } else { (a, b + 1) });
|
||||
KnotenSicht::Dec { player: *player, acts, kids }
|
||||
}
|
||||
NodeM::Deal { kids } => KnotenSicht::Deal { kids },
|
||||
NodeM::Term { .. } => KnotenSicht::Ende,
|
||||
}
|
||||
};
|
||||
let _ = pool_sperren(&spot, &order, me, 0, &masks, board, 18.75, 90.0, false, karten, &sicht);
|
||||
n.get()
|
||||
};
|
||||
let slots = [fast7::mask(&Card::parse_list("2s").unwrap()), fast7::mask(&Card::parse_list("5h").unwrap()), fast7::mask(&Card::parse_list("Jd").unwrap())];
|
||||
let (erste_ohne, spaeter_ohne) = besucht(None);
|
||||
let (erste_mit, spaeter_mit) = besucht(Some(&slots));
|
||||
assert!(erste_ohne > 0 && spaeter_ohne == 0, "{erste_ohne} {spaeter_ohne}");
|
||||
assert_eq!(erste_ohne, erste_mit);
|
||||
assert!(spaeter_mit > erste_mit, "{spaeter_mit} nodes after the deal against {erste_mit} before it");
|
||||
}
|
||||
|
||||
@@ -191,14 +191,20 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
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 wo = crate::engine::multi3_spieler::offen_w();
|
||||
if w > 0.0 || wo > 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] {
|
||||
let (sperren, frei) = crate::engine::multi3_spieler::pool_sperren(spot, &order, me, passiv, &masks, board, pot, cap, wo > 0.0, None, &|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 w > 0.0 {
|
||||
for (n, rows) in sperren {
|
||||
solver.lock(n, rows.as_ref().clone(), w);
|
||||
}
|
||||
}
|
||||
for (n, rows) in frei {
|
||||
solver.lock(n, rows.as_ref().clone(), wo);
|
||||
}
|
||||
}
|
||||
if crate::engine::multi3_spieler::linie() {
|
||||
|
||||
@@ -338,7 +338,7 @@ pub fn listen_ohne_river(spot: &Spot) -> Option<(Vec<(Vec<Card>, f64)>, Vec<(Vec
|
||||
|
||||
/// Brett-Perzentil jeder Maske wie BETTOR: Anteil ALLER Zwei-Karten-Hände (ohne Brettkarten), die sie schlägt,
|
||||
/// Gleichstand halb.
|
||||
fn brett_perzentil(masks: &[u64], board: u64) -> Vec<f64> {
|
||||
pub(crate) fn brett_perzentil(masks: &[u64], board: u64) -> Vec<f64> {
|
||||
let mut alle: Vec<u32> = all_pairs(board).into_iter().map(|(a, b)| fast7::score(a | b | board)).collect();
|
||||
alle.sort_unstable();
|
||||
let n = alle.len().max(1) as f64;
|
||||
@@ -391,8 +391,14 @@ pub struct Locks {
|
||||
|
||||
/// Die BETTOR-Zeile des Gegners an einem offenen Knoten (Check + Einsätze), je Kombo eine Zeile über `acts`.
|
||||
fn bettor_rows(m: &Modell, acts: &[Act], pot_now: f64, cap: f64) -> Option<Vec<f64>> {
|
||||
offen_zeile(m.strasse, m.pfa, m.before, &m.pct, acts, pot_now, cap)
|
||||
}
|
||||
|
||||
/// `bettor_rows` ohne den Heads-up-`Modell`: auch die Mehrweg-Solver legen ihre Gegner an offenen Knoten so fest
|
||||
/// (`SOLVER3_OFFEN`). `pct` = Brett-Perzentil je Kombo (`brett_perzentil`), `cap` = Obergrenze der Straße.
|
||||
pub(crate) fn offen_zeile(strasse: Street, pfa: bool, before: bool, pct: &[f64], acts: &[Act], pot_now: f64, cap: f64) -> Option<Vec<f64>> {
|
||||
const KL: [char; 5] = ['x', 'k', 'm', 'g', 'u'];
|
||||
let raw: Vec<Option<crate::exploit::bettor::Likelihood>> = KL.iter().map(|a| crate::exploit::bettor::raw_likelihood(m.strasse, m.pfa, m.before, *a)).collect();
|
||||
let raw: Vec<Option<crate::exploit::bettor::Likelihood>> = KL.iter().map(|a| crate::exploit::bettor::raw_likelihood(strasse, pfa, before, *a)).collect();
|
||||
raw[0]?;
|
||||
// Klasse je Aktion (0 = Check, 1..4 = k..u). Ein All-in liest sich eine Klasse stärker als seine Größe: gecallte
|
||||
// NL2-River-All-ins zeigen unter 1,2 Pot so oft eine Hand ab Perzentil 0,9 wie normale Einsätze von 0,8–1,2 Pot
|
||||
@@ -416,8 +422,8 @@ fn bettor_rows(m: &Modell, acts: &[Act], pot_now: f64, cap: f64) -> Option<Vec<f
|
||||
_ => 0,
|
||||
})
|
||||
.collect();
|
||||
let mut rows = Vec::with_capacity(m.pct.len() * acts.len());
|
||||
for &p in &m.pct {
|
||||
let mut rows = Vec::with_capacity(pct.len() * acts.len());
|
||||
for &p in pct {
|
||||
let mut row = vec![0.0; acts.len()];
|
||||
for (ki, lk) in raw.iter().enumerate() {
|
||||
let Some(lk) = lk else { continue };
|
||||
|
||||
@@ -238,11 +238,10 @@ pub fn river_pool_fold(spot: &Spot, ratio: f64, allin_ab: f64, profile: Option<&
|
||||
/// Wie `river_pool_fold`, auf der Straße `strasse` (Flop, Turn oder River): Linie aus dem Aggressor der Straße
|
||||
/// davor, Kurve dieser Straße.
|
||||
pub fn pool_fold(spot: &Spot, strasse: Street, ratio: f64, allin_ab: f64, profile: Option<&Profile>) -> Option<f64> {
|
||||
let c = cfg()?;
|
||||
let (vorher, k) = match strasse {
|
||||
Street::Flop => (Street::Preflop, 0),
|
||||
Street::Turn => (Street::Flop, 1),
|
||||
Street::River => (Street::Turn, 2),
|
||||
let vorher = match strasse {
|
||||
Street::Flop => Street::Preflop,
|
||||
Street::Turn => Street::Flop,
|
||||
Street::River => Street::Turn,
|
||||
_ => return None,
|
||||
};
|
||||
let ag = letzter_aggressor(spot, vorher);
|
||||
@@ -253,6 +252,19 @@ pub fn pool_fold(spot: &Spot, strasse: Street, ratio: f64, allin_ab: f64, profil
|
||||
} else {
|
||||
1
|
||||
};
|
||||
pool_fold_linie(strasse, linie, ratio, allin_ab, profile)
|
||||
}
|
||||
|
||||
/// `pool_fold` mit der Linie schon bestimmt (0 = hero war Aggressor der Straße davor, 3 = ein Gegner, 1 = keiner): die
|
||||
/// Mehrweg-Solver kennen sie an ihren spaeteren Strassen aus dem Baumpfad, nicht aus der gespielten Hand.
|
||||
pub fn pool_fold_linie(strasse: Street, linie: usize, ratio: f64, allin_ab: f64, profile: Option<&Profile>) -> Option<f64> {
|
||||
let c = cfg()?;
|
||||
let k = match strasse {
|
||||
Street::Flop => 0,
|
||||
Street::Turn => 1,
|
||||
Street::River => 2,
|
||||
_ => return None,
|
||||
};
|
||||
let ratio = if ratio.is_finite() { ratio.max(0.0) } else { 0.0 };
|
||||
let (linie, r) = if ratio >= allin_ab - 1e-9 { (2, ratio.min(allin_ab)) } else { (linie, ratio) };
|
||||
let pool = interp(&c.kurven[k][linie], r);
|
||||
|
||||
Reference in New Issue
Block a user