Multiway: Grund-Rekorder (kern_grund), SOLVER3_ALLE (5+ Spieler als gepoolte Gruppe, nachsichtige Linie), SOLVER3_FORM (Zeile des Solvers formen statt Klassen ausschliessen)
Co-Authored-By: Claude Opus 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 = ("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", "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", "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",
|
||||
|
||||
@@ -34,11 +34,18 @@ fn main() {
|
||||
if spot.to_call > 0.0 { "/gegen" } else { "/offen" }
|
||||
);
|
||||
rechner::engine::solver_kern::grund_nehmen();
|
||||
rechner::engine::multi3_spieler::grund_nehmen();
|
||||
let d = rechner::guard::enforce::enforce(&spot, rechner::engine::decide::decide(&spot));
|
||||
let grund = if d.reason.starts_with("solver-kern") {
|
||||
"solver".to_string()
|
||||
} else {
|
||||
rechner::engine::solver_kern::grund_nehmen().unwrap_or("nicht erreicht").to_string()
|
||||
let kern = rechner::engine::solver_kern::grund_nehmen();
|
||||
// A multiway spot's reason is the multiway gate (the heads-up kern only notes "mehrweg").
|
||||
match rechner::engine::multi3_spieler::grund_nehmen() {
|
||||
Some(m) if spot.live_villains().count() != 1 => m,
|
||||
_ => kern.unwrap_or("nicht erreicht"),
|
||||
}
|
||||
.to_string()
|
||||
};
|
||||
println!("{lage}\t{grund}\t{}", d.reason.replace('\t', " "));
|
||||
}
|
||||
|
||||
+71
-2
@@ -41,6 +41,9 @@ pub struct GameM {
|
||||
/// Common cap on a player's contribution over the game's streets.
|
||||
pub cap: f64,
|
||||
pub slots: usize,
|
||||
/// Players who never decide: they check, and call every bet up to the cap (the pooled field of a
|
||||
/// 5+-handed spot, their hands still sampled and in the showdown). Bit mask, 0 = none.
|
||||
pub passive: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -58,7 +61,12 @@ struct State {
|
||||
impl GameM {
|
||||
/// `menus[s]` = the betting of street `s`; `slots` = children of each deal node.
|
||||
pub fn build(players: usize, pot: f64, cap: f64, menus: &[Menu3], slots: usize) -> GameM {
|
||||
let mut g = GameM { nodes: Vec::new(), players, pot, cap, slots: slots.max(1) };
|
||||
Self::build_passiv(players, pot, cap, menus, slots, 0)
|
||||
}
|
||||
|
||||
/// As `build`, the players in the bit mask `passive` only check or call.
|
||||
pub fn build_passiv(players: usize, pot: f64, cap: f64, menus: &[Menu3], slots: usize, passive: u32) -> GameM {
|
||||
let mut g = GameM { nodes: Vec::new(), players, pot, cap, slots: slots.max(1), passive };
|
||||
let all = (1u32 << players) - 1;
|
||||
let s = State { c: vec![0.0; players], active: all, pending: all, raises: 0, to_act: 0, street: 0, level: 0.0 };
|
||||
g.grow(s, menus);
|
||||
@@ -101,7 +109,15 @@ impl GameM {
|
||||
let top = s.c.iter().copied().fold(0.0, f64::max);
|
||||
let mut acts: Vec<Act> = Vec::new();
|
||||
let mut totals: Vec<f64> = Vec::new();
|
||||
if top > s.c[p] + eps {
|
||||
if self.passive & (1 << p) != 0 {
|
||||
if top > s.c[p] + eps {
|
||||
acts.push(Act::Call);
|
||||
totals.push(top);
|
||||
} else {
|
||||
acts.push(Act::Check);
|
||||
totals.push(s.c[p]);
|
||||
}
|
||||
} else if top > s.c[p] + eps {
|
||||
acts.push(Act::Fold);
|
||||
acts.push(Act::Call);
|
||||
totals.extend([s.c[p], top]);
|
||||
@@ -186,6 +202,56 @@ impl GameM {
|
||||
}
|
||||
Some(at)
|
||||
}
|
||||
|
||||
/// As `follow`, but a player whose turn comes before the next recorded act and who is not `me` is taken
|
||||
/// to have folded when a bet is open, else checked (a live player without a recorded act: the history is incomplete,
|
||||
/// the pot says he put nothing more in). Ends at `me`'s next node.
|
||||
pub fn follow_nachsicht(&self, line: &[(usize, Act)], me: usize) -> Option<usize> {
|
||||
let mut at = 0;
|
||||
let skip = |at: usize, me: usize| -> Option<usize> {
|
||||
let NodeM::Dec { player, acts, kids, .. } = &self.nodes[at] else { return None };
|
||||
if *player == me {
|
||||
return None;
|
||||
}
|
||||
let k = acts.iter().position(|t| *t == Act::Fold).or_else(|| acts.iter().position(|t| matches!(t, Act::Check | Act::Call)))?;
|
||||
Some(kids[k])
|
||||
};
|
||||
for (who, a) in line {
|
||||
loop {
|
||||
let NodeM::Dec { player, .. } = &self.nodes[at] else { return None };
|
||||
if player == who {
|
||||
break;
|
||||
}
|
||||
at = skip(at, me)?;
|
||||
}
|
||||
at = self.step(at, a)?;
|
||||
}
|
||||
while let NodeM::Dec { player, .. } = &self.nodes[at] {
|
||||
if *player == me {
|
||||
break;
|
||||
}
|
||||
at = skip(at, me)?;
|
||||
}
|
||||
Some(at)
|
||||
}
|
||||
|
||||
/// The child of `at` that the observed act `a` leads to (nearest size for bets and raises).
|
||||
fn step(&self, at: usize, a: &Act) -> Option<usize> {
|
||||
let NodeM::Dec { acts, kids, .. } = &self.nodes[at] else { return None };
|
||||
let k = match a {
|
||||
Act::Bet(x) | Act::Raise(x) => acts
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(k, t)| match t {
|
||||
Act::Bet(y) | Act::Raise(y) => Some((k, (y - x).abs())),
|
||||
_ => None,
|
||||
})
|
||||
.min_by(|p, q| p.1.total_cmp(&q.1))?
|
||||
.0,
|
||||
_ => acts.iter().position(|t| t == a)?,
|
||||
};
|
||||
Some(kids[k])
|
||||
}
|
||||
}
|
||||
|
||||
struct Xs(u64);
|
||||
@@ -327,6 +393,9 @@ impl SolverM {
|
||||
pub fn iterate(&mut self) {
|
||||
self.t += 1;
|
||||
for i in 0..self.game.players {
|
||||
if self.game.passive & (1 << i) != 0 {
|
||||
continue;
|
||||
}
|
||||
let Some(d) = self.draw(i) else { continue };
|
||||
let live: Vec<f64> = d.mine.iter().map(|s| if *s > 0 { 1.0 } else { 0.0 }).collect();
|
||||
let reach = live.clone();
|
||||
|
||||
+65
-2
@@ -51,6 +51,9 @@ pub struct Game3 {
|
||||
pub pot: f64,
|
||||
/// The common stack cap (this street's total a player can reach).
|
||||
pub cap: f64,
|
||||
/// Players who never decide: they check, and call every bet up to the cap (the pooled field of a
|
||||
/// 5+-handed spot, their hands still sampled and in the showdown). Bit mask, 0 = none.
|
||||
pub passive: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -66,7 +69,12 @@ impl Game3 {
|
||||
/// The tree for `players` players (index = acting order), pot `pot` before the street, every
|
||||
/// player able to put in at most `cap` on this street.
|
||||
pub fn build(players: usize, pot: f64, cap: f64, menu: &Menu3) -> Game3 {
|
||||
let mut g = Game3 { nodes: Vec::new(), players, pot, cap };
|
||||
Self::build_passiv(players, pot, cap, menu, 0)
|
||||
}
|
||||
|
||||
/// As `build`, the players in the bit mask `passive` only check or call.
|
||||
pub fn build_passiv(players: usize, pot: f64, cap: f64, menu: &Menu3, passive: u32) -> Game3 {
|
||||
let mut g = Game3 { nodes: Vec::new(), players, pot, cap, passive };
|
||||
let all = (1u32 << players) - 1;
|
||||
let s = State { c: vec![0.0; players], active: all, pending: all, raises: 0, to_act: 0 };
|
||||
g.grow(s, menu);
|
||||
@@ -86,7 +94,9 @@ impl Game3 {
|
||||
let top = s.c.iter().copied().fold(0.0, f64::max);
|
||||
let eps = 1e-9 * self.cap.max(1.0);
|
||||
let mut acts: Vec<Act> = Vec::new();
|
||||
if top > s.c[p] + eps {
|
||||
if self.passive & (1 << p) != 0 {
|
||||
acts.push(if top > s.c[p] + eps { Act::Call } else { Act::Check });
|
||||
} else if top > s.c[p] + eps {
|
||||
acts.push(Act::Fold);
|
||||
acts.push(Act::Call);
|
||||
if s.raises < menu.max_raises && top < self.cap - eps {
|
||||
@@ -168,6 +178,56 @@ impl Game3 {
|
||||
}
|
||||
Some(at)
|
||||
}
|
||||
|
||||
/// As `follow`, but a player whose turn comes before the next recorded act and who is not `me` is taken
|
||||
/// to have folded when a bet is open, else checked (a live player without a recorded act: the history is incomplete,
|
||||
/// the pot says he put nothing more in). Ends at `me`'s next node.
|
||||
pub fn follow_nachsicht(&self, line: &[(usize, Act)], me: usize) -> Option<usize> {
|
||||
let mut at = 0;
|
||||
let skip = |at: usize, me: usize| -> Option<usize> {
|
||||
let Node3::Dec { player, acts, kids, .. } = &self.nodes[at] else { return None };
|
||||
if *player == me {
|
||||
return None;
|
||||
}
|
||||
let k = acts.iter().position(|t| *t == Act::Fold).or_else(|| acts.iter().position(|t| matches!(t, Act::Check | Act::Call)))?;
|
||||
Some(kids[k])
|
||||
};
|
||||
for (who, a) in line {
|
||||
loop {
|
||||
let Node3::Dec { player, .. } = &self.nodes[at] else { return None };
|
||||
if player == who {
|
||||
break;
|
||||
}
|
||||
at = skip(at, me)?;
|
||||
}
|
||||
at = self.step(at, a)?;
|
||||
}
|
||||
while let Node3::Dec { player, .. } = &self.nodes[at] {
|
||||
if *player == me {
|
||||
break;
|
||||
}
|
||||
at = skip(at, me)?;
|
||||
}
|
||||
Some(at)
|
||||
}
|
||||
|
||||
/// The child of `at` that the observed act `a` leads to (nearest size for bets and raises).
|
||||
fn step(&self, at: usize, a: &Act) -> Option<usize> {
|
||||
let Node3::Dec { acts, kids, .. } = &self.nodes[at] else { return None };
|
||||
let k = match a {
|
||||
Act::Bet(x) | Act::Raise(x) => acts
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(k, t)| match t {
|
||||
Act::Bet(y) | Act::Raise(y) => Some((k, (y - x).abs())),
|
||||
_ => None,
|
||||
})
|
||||
.min_by(|p, q| p.1.total_cmp(&q.1))?
|
||||
.0,
|
||||
_ => acts.iter().position(|t| t == a)?,
|
||||
};
|
||||
Some(kids[k])
|
||||
}
|
||||
}
|
||||
|
||||
/// One player's hands: card masks, weights (> 0), and showdown scores with the board.
|
||||
@@ -239,6 +299,9 @@ impl Solver3 {
|
||||
pub fn iterate(&mut self) {
|
||||
self.t += 1;
|
||||
for i in 0..self.game.players {
|
||||
if self.game.passive & (1 << i) != 0 {
|
||||
continue;
|
||||
}
|
||||
// Sample the other players' hands jointly, card-disjoint (rejection on the whole tuple).
|
||||
let mut picked = vec![usize::MAX; self.game.players];
|
||||
let mut ok = false;
|
||||
|
||||
+143
-24
@@ -41,6 +41,110 @@ static TURN_OHNE: AtomicU8 = AtomicU8::new(0);
|
||||
/// `SOLVER3_FSPERRE=1`: on the multiway flop facing a bet of at most the pot, a solver fold with top pair or
|
||||
/// better goes to the heuristic (owner order 19.11., the overfold of 17.11.). Default off.
|
||||
static FSPERRE: AtomicBool = AtomicBool::new(false);
|
||||
/// `SOLVER3_ALLE=1`: every multiway spot. 5+-handed spots too (at most `MAX_AKTIV` villains decide, the others are
|
||||
/// a pooled field that checks and calls every bet, hands sampled and in the showdown), and a live player without a
|
||||
/// recorded act counts as folded (`follow_nachsicht`). Default off: those spots stay with the heuristic.
|
||||
static ALLE: AtomicBool = AtomicBool::new(false);
|
||||
/// `SOLVER3_FORM=1`: the solver's own row is shaped before the draw, so that no exclusion has to hand a class to the
|
||||
/// heuristic (owner order 19.11.): (a) trips or better never check when a bet is possible (the mass goes to the bets),
|
||||
/// (b) a pair, top pair or overpair facing a bet never raises (the mass goes to the call), (c) with `SOLVER3_FSPERRE`
|
||||
/// 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);
|
||||
|
||||
pub fn set_form(on: bool) {
|
||||
FORM.store(on, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Shape the row of hero's node under `SOLVER3_FORM` (see there); returns whether it changed.
|
||||
pub(crate) fn form_row(raw: &Spot, acts: &[Act], row: &mut [f64]) -> bool {
|
||||
if !FORM.load(Ordering::Relaxed) || raw.hero_cards.len() != 2 || row.len() != acts.len() {
|
||||
return false;
|
||||
}
|
||||
let k = crate::sim::poolruf::klasse(&raw.hero_cards, &raw.board);
|
||||
let facing = raw.to_call > 0.0;
|
||||
let mut changed = false;
|
||||
let mut moven = |row: &mut [f64], von: &dyn Fn(&Act) -> bool, nach: &dyn Fn(&Act) -> bool| {
|
||||
let m: f64 = acts.iter().zip(row.iter()).filter(|(a, _)| von(a)).map(|(_, p)| *p).sum();
|
||||
let ziele: Vec<usize> = (0..acts.len()).filter(|i| nach(&acts[*i])).collect();
|
||||
if m <= 0.0 || ziele.is_empty() {
|
||||
return;
|
||||
}
|
||||
let basis: f64 = ziele.iter().map(|i| row[*i]).sum();
|
||||
for (i, a) in acts.iter().enumerate() {
|
||||
if von(a) {
|
||||
row[i] = 0.0;
|
||||
}
|
||||
}
|
||||
for i in &ziele {
|
||||
row[*i] += if basis > 0.0 { m * row[*i] / basis } else { m / ziele.len() as f64 };
|
||||
}
|
||||
changed = true;
|
||||
};
|
||||
if !facing && k >= 6 {
|
||||
moven(row, &|a| *a == Act::Check, &|a| matches!(a, Act::Bet(_)));
|
||||
}
|
||||
if facing && (2..=4).contains(&k) {
|
||||
moven(row, &|a| matches!(a, Act::Raise(_)), &|a| *a == Act::Call);
|
||||
}
|
||||
if fsperre_greift(raw) {
|
||||
moven(row, &|a| *a == Act::Fold, &|a| *a == Act::Call);
|
||||
}
|
||||
changed
|
||||
}
|
||||
/// Most deciding villains of one solve (4 players: the largest game that fits the time budget).
|
||||
pub const MAX_AKTIV: usize = 3;
|
||||
|
||||
pub fn set_alle(on: bool) {
|
||||
ALLE.store(on, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn alle() -> bool {
|
||||
ALLE.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Bit mask over `order` (index) of the villains who only check or call: none up to `MAX_AKTIV` villains; with
|
||||
/// more, the villains with the most aggressive line on this street decide (a bet counts before a call, a call
|
||||
/// before a check, then acting order) and the rest are the field. `None` for 5+ players without `SOLVER3_ALLE`.
|
||||
pub(crate) fn passiv_maske(spot: &Spot, order: &[u8]) -> Option<u32> {
|
||||
let n = order.len();
|
||||
if n <= MAX_AKTIV + 1 {
|
||||
return Some(0);
|
||||
}
|
||||
if !alle() {
|
||||
return None;
|
||||
}
|
||||
let punkte = |seat: u8| -> u32 {
|
||||
spot.history
|
||||
.iter()
|
||||
.filter(|r| r.street == spot.street && r.seat == seat)
|
||||
.map(|r| match r.action {
|
||||
crate::game::SeenAction::Bet | crate::game::SeenAction::Raise | crate::game::SeenAction::AllIn => 3,
|
||||
crate::game::SeenAction::Call => 2,
|
||||
_ => 0,
|
||||
})
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
};
|
||||
let mut rang: Vec<usize> = (0..n).filter(|i| order[*i] != spot.hero_seat).collect();
|
||||
rang.sort_by_key(|i| std::cmp::Reverse(punkte(order[*i])));
|
||||
Some(rang[MAX_AKTIV..].iter().fold(0u32, |m, i| m | (1 << i)))
|
||||
}
|
||||
|
||||
// Why the last multiway call on this thread left the spot to the heuristic (`weg`); read only by the
|
||||
// diagnosis tool `kern_grund`, never by a decision. Shared by flop/turn and river.
|
||||
thread_local! {
|
||||
static GRUND: std::cell::Cell<Option<&'static str>> = const { std::cell::Cell::new(None) };
|
||||
}
|
||||
|
||||
pub(crate) fn weg<T>(g: &'static str) -> Option<T> {
|
||||
GRUND.with(|x| x.set(Some(g)));
|
||||
None
|
||||
}
|
||||
|
||||
/// Take the recorded reason (and clear it).
|
||||
pub fn grund_nehmen() -> Option<&'static str> {
|
||||
GRUND.with(|x| x.take())
|
||||
}
|
||||
|
||||
pub fn set_lage(nur_offen: u8, ohne: u8) {
|
||||
NUR_OFFEN.store(nur_offen, Ordering::Relaxed);
|
||||
@@ -76,6 +180,8 @@ pub fn ohne_from_env() {
|
||||
set_river_ohne(river_ohne_from_env());
|
||||
set_strassen_ohne(klassen_env("SOLVER3_FOHNE"), klassen_env("SOLVER3_TOHNE"));
|
||||
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"));
|
||||
}
|
||||
|
||||
/// `(nur_offen, ohne)` from `SOLVER_FLOP3` / `SOLVER_TURN3` / `SOLVER_RIVER3` = `offen` and
|
||||
@@ -108,15 +214,21 @@ pub fn cap_ms(default: f64) -> f64 {
|
||||
}
|
||||
|
||||
/// Whether a multiway solver may decide this spot under the stage-4 limits.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn lage_passt(raw: &Spot) -> bool {
|
||||
lage_grund(raw).is_none()
|
||||
}
|
||||
|
||||
/// The stage-4 limit that keeps a multiway solver from this spot (`None`: it may decide).
|
||||
pub(crate) fn lage_grund(raw: &Spot) -> Option<&'static str> {
|
||||
let bit = match raw.street {
|
||||
Street::Flop => 1,
|
||||
Street::Turn => 2,
|
||||
Street::River => 4,
|
||||
_ => return true,
|
||||
_ => return None,
|
||||
};
|
||||
if NUR_OFFEN.load(Ordering::Relaxed) & bit != 0 && raw.to_call > 0.0 {
|
||||
return false;
|
||||
return Some("mw nur offen");
|
||||
}
|
||||
let strasse = match bit {
|
||||
1 => FLOP_OHNE.load(Ordering::Relaxed),
|
||||
@@ -124,7 +236,7 @@ pub(crate) fn lage_passt(raw: &Spot) -> bool {
|
||||
_ => RIVER_OHNE.load(Ordering::Relaxed),
|
||||
};
|
||||
let ohne = OHNE.load(Ordering::Relaxed) | strasse;
|
||||
!(ohne != 0 && raw.hero_cards.len() == 2 && (3..=5).contains(&raw.board.len()) && ohne & (1 << crate::sim::poolruf::klasse(&raw.hero_cards, &raw.board)) != 0)
|
||||
(ohne != 0 && raw.hero_cards.len() == 2 && (3..=5).contains(&raw.board.len()) && ohne & (1 << crate::sim::poolruf::klasse(&raw.hero_cards, &raw.board)) != 0).then_some("mw klasse ausgeschlossen")
|
||||
}
|
||||
|
||||
pub fn set_turn3(on: bool) {
|
||||
@@ -186,17 +298,18 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
Street::Flop => (3, FLOP_BUDGET_MS, crate::engine::frist::FLOP_MS, FLOP_SLOTS),
|
||||
_ => return None,
|
||||
};
|
||||
if spot.board.len() != cards || spot.hero_cards.len() != 2 || !(2..=3).contains(&villains) {
|
||||
return None;
|
||||
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);
|
||||
if budget <= 0.0 {
|
||||
return None;
|
||||
return weg("mw keine zeit");
|
||||
}
|
||||
let started = std::time::Instant::now();
|
||||
let cpu0 = crate::engine::frist::thread_cpu_ms();
|
||||
let order = acting_order(spot)?;
|
||||
let (line, c) = street_line3(spot, &order, spot.street)?;
|
||||
let order = acting_order(spot).or_else(|| weg("mw ohne blinds"))?;
|
||||
let passiv = passiv_maske(spot, &order).or_else(|| weg("mw 5+ spieler"))?;
|
||||
let (line, c) = street_line3(spot, &order, spot.street).or_else(|| weg("mw linie"))?;
|
||||
let me = order.iter().position(|s| *s == spot.hero_seat)?;
|
||||
let stack_of = |seat: u8| -> f64 {
|
||||
if seat == spot.hero_seat {
|
||||
@@ -208,25 +321,25 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
let cap = order.iter().enumerate().map(|(i, s)| stack_of(*s) + c[i]).fold(f64::INFINITY, f64::min);
|
||||
let pot = spot.pot - c.iter().sum::<f64>();
|
||||
if pot <= 0.0 || !cap.is_finite() || cap <= c.iter().copied().fold(0.0, f64::max) {
|
||||
return None;
|
||||
return weg("mw stack");
|
||||
}
|
||||
let board = fast7::mask(&spot.board);
|
||||
let hero_mask = fast7::mask(&spot.hero_cards);
|
||||
let mut hands = Vec::with_capacity(order.len());
|
||||
for seat in &order {
|
||||
let h = if *seat == spot.hero_seat {
|
||||
model_hands(spot, &Villain { seat: *seat, stack: spot.hero_stack, folded: false, profile: None }, board, Some(hero_mask), MAX_COMBOS)?
|
||||
model_hands(spot, &Villain { seat: *seat, stack: spot.hero_stack, folded: false, profile: None }, board, Some(hero_mask), MAX_COMBOS)
|
||||
} else {
|
||||
let v = spot.live_villains().find(|v| v.seat == *seat)?;
|
||||
model_hands(spot, v, board, None, MAX_COMBOS)?
|
||||
model_hands(spot, v, board, None, MAX_COMBOS)
|
||||
};
|
||||
hands.push(h);
|
||||
hands.push(h.or_else(|| weg("mw range leer"))?);
|
||||
}
|
||||
let game = GameM::build(order.len(), pot, cap, &[Menu3::standard(), later()], slots);
|
||||
let at = game.follow(&line)?;
|
||||
let NodeM::Dec { player, acts, .. } = &game.nodes[at] else { return None };
|
||||
let game = GameM::build_passiv(order.len(), pot, cap, &[Menu3::standard(), later()], slots, 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 {
|
||||
return None;
|
||||
return weg("mw knoten");
|
||||
}
|
||||
let acts = acts.clone();
|
||||
let nodes = game.nodes.len();
|
||||
@@ -242,7 +355,7 @@ pub fn solve_multi3(spot: &Spot) -> Option<SolvedM> {
|
||||
}
|
||||
}
|
||||
if done < MIN_ITERS {
|
||||
return None;
|
||||
return weg("mw zu wenig iterationen");
|
||||
}
|
||||
let row = solver.row(at, hero_index);
|
||||
Some(SolvedM { row, acts, iterations: solver.iterations(), millis: started.elapsed().as_secs_f64() * 1e3, players: order.len(), nodes, combos })
|
||||
@@ -265,15 +378,21 @@ pub fn multi3_decision(raw: &Spot) -> Option<Decision> {
|
||||
Street::Flop => flop3(),
|
||||
_ => false,
|
||||
};
|
||||
if !on || raw.hero_cards.len() != 2 || raw.live_villains().count() < 2 || !lage_passt(raw) {
|
||||
return None;
|
||||
if !on || raw.hero_cards.len() != 2 || raw.live_villains().count() < 2 {
|
||||
// The river is the river solver's (it has noted its own reason).
|
||||
return if matches!(raw.street, Street::Flop | Street::Turn) { weg("mw schalter aus") } else { None };
|
||||
}
|
||||
if let Some(g) = lage_grund(raw) {
|
||||
return weg(g);
|
||||
}
|
||||
let gated = crate::engine::read_gate::gate_reads(raw);
|
||||
let s = solve_multi3(&gated)?;
|
||||
let (draw, _) = Rng::seeded(gated.seed).unit();
|
||||
let mut acc = 0.0;
|
||||
let mut pick = s.acts.len() - 1;
|
||||
for (k, p) in s.row.iter().enumerate() {
|
||||
let mut row = s.row.clone();
|
||||
let geformt = form_row(raw, &s.acts, &mut row);
|
||||
for (k, p) in row.iter().enumerate() {
|
||||
acc += p;
|
||||
if draw < acc {
|
||||
pick = k;
|
||||
@@ -282,16 +401,16 @@ pub fn multi3_decision(raw: &Spot) -> Option<Decision> {
|
||||
}
|
||||
let act = s.acts[pick];
|
||||
if act == Act::Fold && fsperre_greift(raw) {
|
||||
return None;
|
||||
return weg("mw fold-sperre");
|
||||
}
|
||||
let p = s.row[pick];
|
||||
let p = row[pick];
|
||||
let street = if gated.street == Street::Turn { "turn3" } else { "flop3" };
|
||||
Some(Decision::new(
|
||||
legal_choice(&gated, act),
|
||||
p.clamp(0.0, 1.0),
|
||||
format!(
|
||||
"solver-kern solver {street} ({} players): {:?} combos, {} nodes, {} iters, {act:?} p {p:.2}, {:.0} ms",
|
||||
s.players, s.combos, s.nodes, s.iterations, s.millis
|
||||
"solver-kern solver {street} ({} players): {:?} combos, {} nodes, {} iters, {act:?} p {p:.2}, {:.0} ms{}",
|
||||
s.players, s.combos, s.nodes, s.iterations, s.millis, if geformt { " | form" } else { "" }
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -166,6 +166,7 @@ fn lage_limits_open_spots_and_classes() {
|
||||
/// bet at most the pot). All off by default.
|
||||
#[test]
|
||||
fn strassen_ohne_und_flop_sperre() {
|
||||
let _g = LOCK.lock().unwrap();
|
||||
let flop = three_way(Street::Flop, "Ac Kd"); // top pair, 3.75 into 7.5
|
||||
let k = crate::sim::poolruf::klasse(&flop.hero_cards, &flop.board);
|
||||
assert_eq!(k, 3);
|
||||
@@ -186,3 +187,62 @@ fn strassen_ohne_und_flop_sperre() {
|
||||
assert!(!fsperre_greift(&three_way(Street::Turn, "Ac Kd")), "flop only");
|
||||
set_fsperre(false);
|
||||
}
|
||||
|
||||
/// Six players on the flop: seats 1, 2, 3 call preflop too and have not acted on the flop (not recorded).
|
||||
fn six_way_flop(hero: &str) -> Spot {
|
||||
let mut s = three_way(Street::Flop, hero);
|
||||
for r in s.history.iter_mut().filter(|r| r.street == Street::Preflop && matches!(r.seat, 1 | 2 | 3)) {
|
||||
r.action = SeenAction::Call;
|
||||
r.amount = Some(2.5);
|
||||
}
|
||||
s.pot += 7.5;
|
||||
for seat in [1u8, 2, 3] {
|
||||
s.villains.push(Villain { seat, stack: 97.5, folded: false, profile: None });
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
/// `SOLVER3_ALLE`: 5+ players (the pooled field) and a live player without a recorded act; off, the spot stays out.
|
||||
#[test]
|
||||
fn alle_solves_six_way_and_incomplete_lines() {
|
||||
let _g = LOCK.lock().unwrap();
|
||||
let _fest = crate::engine::frist::fest_hier();
|
||||
set_alle(false);
|
||||
let _ = grund_nehmen();
|
||||
assert!(solve_multi3(&six_way_flop("As Ad")).is_none());
|
||||
assert_eq!(grund_nehmen(), Some("mw 5+ spieler"));
|
||||
set_alle(true);
|
||||
let s = solve_multi3(&six_way_flop("As Ad")).expect("six-way flop solves under ALLE");
|
||||
assert_eq!(s.players, 6);
|
||||
assert!((s.row.iter().sum::<f64>() - 1.0).abs() < 1e-9);
|
||||
assert!(fold(&s) < 0.1, "{:?} {:?}", s.row, s.acts);
|
||||
// Six players, three villains decide, two are the pooled field.
|
||||
let spot = six_way_flop("As Ad");
|
||||
let order = acting_order(&spot).unwrap();
|
||||
assert_eq!(passiv_maske(&spot, &order).unwrap().count_ones(), 2);
|
||||
set_alle(false);
|
||||
}
|
||||
|
||||
/// `SOLVER3_FORM`: trips or better do not check, pairs do not raise into a bet, top pair does not fold on the flop.
|
||||
#[test]
|
||||
fn form_shapes_the_row() {
|
||||
let _g = LOCK.lock().unwrap();
|
||||
set_form(true);
|
||||
set_fsperre(true);
|
||||
let mut open = three_way(Street::Flop, "Ah Ac"); // set of aces
|
||||
open.to_call = 0.0;
|
||||
let acts = [Act::Check, Act::Bet(3.0), Act::Bet(7.0)];
|
||||
let mut row = [0.8, 0.1, 0.1];
|
||||
assert!(form_row(&open, &acts, &mut row));
|
||||
assert_eq!(row[0], 0.0);
|
||||
assert!((row.iter().sum::<f64>() - 1.0).abs() < 1e-12);
|
||||
let facing = three_way(Street::Flop, "Ac Kd"); // top pair
|
||||
let acts = [Act::Fold, Act::Call, Act::Raise(9.0)];
|
||||
let mut row = [0.5, 0.2, 0.3];
|
||||
assert!(form_row(&facing, &acts, &mut row));
|
||||
assert_eq!(row, [0.0, 1.0, 0.0]);
|
||||
set_form(false);
|
||||
let mut row = [0.5, 0.2, 0.3];
|
||||
assert!(!form_row(&facing, &acts, &mut row));
|
||||
set_fsperre(false);
|
||||
}
|
||||
|
||||
@@ -135,18 +135,20 @@ pub struct Solved3 {
|
||||
|
||||
/// Solve this 3- or 4-handed river (gated spot) and return hero's average strategy at its node.
|
||||
pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
use crate::engine::multi3_spieler::{passiv_maske, weg};
|
||||
let villains = spot.live_villains().count();
|
||||
if spot.street != Street::River || spot.board.len() != 5 || spot.hero_cards.len() != 2 || !(2..=3).contains(&villains) {
|
||||
return None;
|
||||
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);
|
||||
if budget <= 0.0 {
|
||||
return None;
|
||||
return weg("mw keine zeit");
|
||||
}
|
||||
let started = std::time::Instant::now();
|
||||
let cpu0 = crate::engine::frist::thread_cpu_ms();
|
||||
let order = acting_order(spot)?;
|
||||
let (line, c) = street_line3(spot, &order, Street::River)?;
|
||||
let order = acting_order(spot).or_else(|| weg("mw ohne blinds"))?;
|
||||
let passiv = passiv_maske(spot, &order).or_else(|| weg("mw 5+ spieler"))?;
|
||||
let (line, c) = street_line3(spot, &order, Street::River).or_else(|| weg("mw linie"))?;
|
||||
let me = order.iter().position(|s| *s == spot.hero_seat)?;
|
||||
let stack_of = |seat: u8| -> f64 {
|
||||
if seat == spot.hero_seat {
|
||||
@@ -158,25 +160,25 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
let cap = order.iter().enumerate().map(|(i, s)| stack_of(*s) + c[i]).fold(f64::INFINITY, f64::min);
|
||||
let pot = spot.pot - c.iter().sum::<f64>();
|
||||
if pot <= 0.0 || !cap.is_finite() || cap <= c.iter().copied().fold(0.0, f64::max) {
|
||||
return None;
|
||||
return weg("mw stack");
|
||||
}
|
||||
let board = fast7::mask(&spot.board);
|
||||
let hero_mask = fast7::mask(&spot.hero_cards);
|
||||
let mut hands = Vec::with_capacity(order.len());
|
||||
for seat in &order {
|
||||
let h = if *seat == spot.hero_seat {
|
||||
model_hands(spot, &Villain { seat: *seat, stack: spot.hero_stack, folded: false, profile: None }, board, Some(hero_mask), MAX_COMBOS)?
|
||||
model_hands(spot, &Villain { seat: *seat, stack: spot.hero_stack, folded: false, profile: None }, board, Some(hero_mask), MAX_COMBOS)
|
||||
} else {
|
||||
let v = spot.live_villains().find(|v| v.seat == *seat)?;
|
||||
model_hands(spot, v, board, None, MAX_COMBOS)?
|
||||
model_hands(spot, v, board, None, MAX_COMBOS)
|
||||
};
|
||||
hands.push(h);
|
||||
hands.push(h.or_else(|| weg("mw range leer"))?);
|
||||
}
|
||||
let game = Game3::build(order.len(), pot, cap, &Menu3::standard());
|
||||
let at = game.follow(&line)?;
|
||||
let Node3::Dec { player, acts, .. } = &game.nodes[at] else { return None };
|
||||
let game = Game3::build_passiv(order.len(), pot, cap, &Menu3::standard(), 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 {
|
||||
return None;
|
||||
return weg("mw knoten");
|
||||
}
|
||||
let acts = acts.clone();
|
||||
let nodes = game.nodes.len();
|
||||
@@ -192,7 +194,7 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
}
|
||||
}
|
||||
if done < MIN_ITERS {
|
||||
return None;
|
||||
return crate::engine::multi3_spieler::weg("mw zu wenig iterationen");
|
||||
}
|
||||
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 })
|
||||
@@ -200,15 +202,20 @@ pub fn solve_river3(spot: &Spot) -> Option<Solved3> {
|
||||
|
||||
/// 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 || !crate::engine::multi3_spieler::lage_passt(raw) {
|
||||
return None;
|
||||
if !river3() || raw.street != Street::River || raw.hero_cards.len() != 2 || raw.board.len() != 5 || raw.live_villains().count() < 2 {
|
||||
return crate::engine::multi3_spieler::weg("mw schalter aus");
|
||||
}
|
||||
if let Some(g) = crate::engine::multi3_spieler::lage_grund(raw) {
|
||||
return crate::engine::multi3_spieler::weg(g);
|
||||
}
|
||||
let gated = crate::engine::read_gate::gate_reads(raw);
|
||||
let s = solve_river3(&gated)?;
|
||||
let (draw, _) = Rng::seeded(gated.seed).unit();
|
||||
let mut acc = 0.0;
|
||||
let mut pick = s.acts.len() - 1;
|
||||
for (k, p) in s.row.iter().enumerate() {
|
||||
let mut row = s.row.clone();
|
||||
let geformt = crate::engine::multi3_spieler::form_row(raw, &s.acts, &mut row);
|
||||
for (k, p) in row.iter().enumerate() {
|
||||
acc += p;
|
||||
if draw < acc {
|
||||
pick = k;
|
||||
@@ -216,13 +223,13 @@ pub fn river3_decision(raw: &Spot) -> Option<Decision> {
|
||||
}
|
||||
}
|
||||
let act = s.acts[pick];
|
||||
let p = s.row[pick];
|
||||
let p = row[pick];
|
||||
Some(Decision::new(
|
||||
legal_choice(&gated, act),
|
||||
p.clamp(0.0, 1.0),
|
||||
format!(
|
||||
"solver-kern river3 solver ({} players): {:?} combos, {} nodes, {} iters, {act:?} p {p:.2}, {:.0} ms",
|
||||
s.players, s.combos, s.nodes, s.iterations, s.millis
|
||||
"solver-kern river3 solver ({} players): {:?} combos, {} nodes, {} iters, {act:?} p {p:.2}, {:.0} ms{}",
|
||||
s.players, s.combos, s.nodes, s.iterations, s.millis, if geformt { " | form" } else { "" }
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user