diff --git a/entscheiden/motor/src/dienst.rs b/entscheiden/motor/src/dienst.rs index bc6c06ad..d2979a95 100644 --- a/entscheiden/motor/src/dienst.rs +++ b/entscheiden/motor/src/dienst.rs @@ -98,8 +98,8 @@ fn uebersetze(z: &Zustand, m: &Menue, x: f32, rng: &mut Rng) -> Option<(Zug, boo } /// Als Erster im Topf (kein Limper, kein Raise, nicht SB/BB) nie nur mitgehen: der Anteil geht auf die Erhoehungen. -fn ohne_limp(z: &Zustand, m: &Menue, v: &mut [f32; MAXA]) { - if z.strasse != 0 || z.hoch != 100 || z.pot != 150 || z.dran < 2 { +fn ohne_limp(z: &Zustand, m: &Menue, v: &mut [f32; MAXA], tot: i32) { + if z.strasse != 0 || z.hoch != 100 || z.pot != 150 + tot || z.dran < 2 { return; } let Some(c) = m.liste().iter().position(|x| x.code == CALL) else { return }; @@ -140,6 +140,10 @@ pub fn nachspielen(s: &Spiel, zuege: &[Echt], strasse: u8, ich: u8, vorweg_raus: let mut l = Lage { z, hoch: 100.0, pot: 150.0 + s.splash_echt, einsatz: [0.0; MAXN], fehler: None, fehler_strasse: 9, pfad: vec![], pot_start: 150.0 + s.splash_echt, gesamt_start: [0.0; MAXN], gesamt: [0.0; MAXN], gepostet: [false; MAXN] }; l.einsatz[0] = 50.0; l.einsatz[1] = 100.0; + if s.straddle { + l.einsatz[2] = 200.0; + (l.hoch, l.pot, l.pot_start) = (200.0, l.pot + 200.0, l.pot_start + 200.0); + } l.gesamt = l.einsatz; let mut st = 0u8; let mut h = salz; @@ -233,15 +237,39 @@ impl Motor { self.t.kl[(z.lebende() > 2) as usize].klasse(st, &b, hand) } - /// Spielregeln mit dem echten Splash dieser Hand + /// Spielregeln mit dem echten Splash dieser Hand; Antes (POST_ANTE ohne Splash) liegen als totes Geld dazu (MOTOR_ANTE, 26.11.) fn spiel(&self, q: &Value) -> Spiel { let mut s = self.s.clone(); - if s.splash > 0 { - s.splash_echt = (q["_splash"].as_f64().unwrap_or(0.0) / q["bigBlind"].as_f64().unwrap_or(1.0) * 100.0) as f32; - } + // auch im Baum ohne Splash (Heads-up): der echte Splash liegt als totes Geld im Topf + s.splash_echt = Self::splash_tot(q) + Self::ante_tot(q); s } + /// Splash dieser Hand in Hundertstel-bb (rakefrei) + fn splash_tot(q: &Value) -> f32 { + (q["_splash"].as_f64().unwrap_or(0.0) / q["bigBlind"].as_f64().unwrap_or(1.0) * 100.0) as f32 + } + + /// Summe der Antes in Hundertstel-bb (geht wie Einsaetze in den Rake) + pub fn ante_tot(q: &Value) -> f32 { + let bb = q["bigBlind"].as_f64().unwrap_or(1.0); + let s: f64 = q["history"].as_array().into_iter().flatten().filter(|h| h["action"] == "POST_ANTE" && h["splash"] != true).filter_map(|h| h["amount"].as_f64()).sum(); + (s / bb * 100.0) as f32 + } + + /// Straddle: zweiter POST_BB ueber 1,5 bb vom Platz direkt nach dem BB (vor jedem anderen Zug) + pub fn ist_straddle(q: &Value) -> bool { + let bb = q["bigBlind"].as_f64().unwrap_or(1.0); + let h: Vec<&Value> = q["history"].as_array().into_iter().flatten().filter(|h| h["action"] != "POST_ANTE").collect(); + h.len() >= 3 && h[0]["action"] == "POST_SB" && h[1]["action"] == "POST_BB" && h[2]["action"] == "POST_BB" && h[2]["amount"].as_f64().unwrap_or(0.0) > 1.5 * bb + } + + /// All-In or Fold: nur Fold und ein Raise auf den ganzen Stapel erlaubt (kein Check, kein Call) + pub fn ist_aof(q: &Value) -> bool { + let legal = |x: &str| q["legalActions"].as_array().is_some_and(|l| l.iter().any(|y| y == x)); + legal("RAISE") && !legal("CALL") && !legal("CHECK") && q["minRaiseTo"].as_f64().is_some() && q["minRaiseTo"] == q["maxRaiseTo"] + } + /// Sitzen nur zwei am Tisch (Plaetze aus Verlauf, Gegnern und Held)? pub fn zu_zweit(q: &Value) -> bool { let mut s: Vec = q["villains"].as_array().into_iter().flatten().chain(q["history"].as_array().into_iter().flatten()).filter_map(|x| x["seat"].as_i64()).collect(); @@ -291,7 +319,7 @@ impl Motor { } fn nl2(&self, q: &Value, a: Value) -> Value { - if self.s.n == 2 || self.s.splash > 0 || q.get("eigen").is_some() || q.get("probeHand").is_some() || q["nackt"] == true { + if self.s.n == 2 || self.s.splash > 0 || self.s.art == crate::spiel::Art::PushFold || q.get("eigen").is_some() || q.get("probeHand").is_some() || q["nackt"] == true { return a; } let hand: Vec = q["heroCards"].as_array().into_iter().flatten().filter_map(karte).collect(); @@ -333,7 +361,12 @@ impl Motor { if m > n || (n > 2 && m < 3) { return Err(format!("{m} Spieler, Strategie fuer {n}")); } - let idx = |s: i64| sitze.iter().position(|&x| x == s).map(|j| if j < 2 { j } else { n - m + j } as u8); + // Straddle: der Straddler bleibt Platz 2, vorweg gefoldet wird dahinter + let fest = if self.s.straddle { 3 } else { 2 }; + if self.s.straddle && m < 4 { + return Err(format!("Straddle mit {m} Spielern")); + } + let idx = |s: i64| sitze.iter().position(|&x| x == s).map(|j| if j < fest { j } else { n - m + j } as u8); let strasse_nr = |s: &str| ["PREFLOP", "FLOP", "TURN", "RIVER"].iter().position(|x| *x == s).map(|x| x as u8); let strasse = q["street"].as_str().and_then(strasse_nr).ok_or("street")?; let mut zuege = Vec::new(); @@ -385,7 +418,7 @@ impl Motor { let mut blinds = 0; for h in hist.iter().filter(|h| h["action"] == "POST_BB") { blinds += 1; - if let (true, Some(i)) = (blinds > 1, idx(h["seat"].as_i64().unwrap_or(-1))) { + if let (true, Some(i)) = (blinds > 1 + self.s.straddle as i32, idx(h["seat"].as_i64().unwrap_or(-1))) { l.gepostet[i as usize] = true; } } @@ -413,7 +446,7 @@ impl Motor { let e = format!("Punkt nie gelernt (Strasse {strasse}, Klasse {kl})"); return self.preisfrage(q, &l, &gegner, hand, &brett, &e).ok_or(e); }; - ohne_limp(&z, &menue, &mut v); + ohne_limp(&z, &menue, &mut v, if self.s.ante { self.s.splash } else { 0 }); // Riesen-All-in aus der Tafel (nach dem Flop, >= 2,5x Topf): nur, wenn es gegen die Ranges mit der echten NL2-Fold-Rate // mehr bringt als Call/Check bzw. Fold. NL2 foldet gegen solche Einsaetze nur 48-67 % (messung/motor/allin-probe/). let mut jam_text = String::new(); @@ -492,6 +525,10 @@ impl Motor { ("RAISE", Some((ziel / bb * 100.0).round() / 100.0 * bb)) } }; + // All-In or Fold: mitgehen heisst den ganzen Stapel setzen + if akt == "CALL" && Self::ist_aof(q) { + (akt, groesse) = ("RAISE", f("maxRaiseTo")); + } if akt == "RAISE" && !legal("RAISE") { (akt, groesse) = (if offen > 0.0 { "CALL" } else { "CHECK" }, None); } @@ -739,7 +776,7 @@ impl Motor { let alle = fremd && *code >= 2; v[h] = self.st.hole(key, kl, m.n).map_or(1.0 / m.n as f32, |mut v| { if !fremd { - ohne_limp(z, &m, &mut v); + ohne_limp(z, &m, &mut v, if self.s.ante { self.s.splash } else { 0 }); } if alle { m.liste().iter().zip(&v).filter(|(x, _)| x.code >= 2).map(|(_, y)| y).sum::() * misch_anteil + v[i] * (1.0 - misch_anteil) } else { v[i] } }); @@ -817,7 +854,7 @@ impl Motor { if hoechst * 5 / 2 > pot * 12 { rest } else { rest.min(pot * 12) } }; // Rake nimmt der Raum nicht vom Splash - let rake_auf = 1.0 - (self.spiel(q).splash_echt / l.pot_start).clamp(0.0, 1.0) as f64; + let rake_auf = 1.0 - (Self::splash_tot(q) / l.pot_start).clamp(0.0, 1.0) as f64; let rake = (self.s.rake as f64 * rake_auf, if self.s.rake > 0.0 { self.s.rake_kappe as f64 } else { 0.0 }); let mich = seite(ich as usize); let h = paar(hand.0, hand.1); diff --git a/entscheiden/motor/src/main.rs b/entscheiden/motor/src/main.rs index 1feb5983..17db07b7 100644 --- a/entscheiden/motor/src/main.rs +++ b/entscheiden/motor/src/main.rs @@ -111,6 +111,18 @@ fn vorflopspiel(bb: &str, minuten: f64, faeden: usize, zittern: f32, aus: &str) std::fs::write(aus, o).unwrap(); } +/// All-In or Fold: wirksame Tiefe in bb (eigener Stapel samt Gesetztem gegen den groessten anderen) und Spielerzahl +fn aof_lage(q: &serde_json::Value) -> (f64, usize) { + let bb = q["bigBlind"].as_f64().unwrap_or(1.0); + let hist = q["history"].as_array(); + let gezahlt = |sitz: Option| hist.into_iter().flatten().filter(|h| h["seat"].as_i64() == sitz && h["action"] != "POST_ANTE").filter_map(|h| h["amount"].as_f64()).fold(0.0, f64::max); + let held = q["heroStack"].as_f64().unwrap_or(0.0) + gezahlt(q["heroSeat"].as_i64()); + let vs = q["villains"].as_array(); + let gross = vs.into_iter().flatten().map(|v| v["stack"].as_f64().unwrap_or(0.0) + gezahlt(v["seat"].as_i64())).fold(0.0, f64::max); + let k = 1 + vs.map_or(0, |v| v.len()); + (held.min(gross).max(bb) / bb, k) +} + fn main() { let a: Vec = std::env::args().collect(); match a[1].as_str() { @@ -166,7 +178,8 @@ fn main() { // splash.bin: gelernte Strategien fuer totes Geld im Topf, im Hintergrund geladen let (tx, rx) = std::sync::mpsc::channel(); let ordner = a[3].clone(); - if a[2] == "sechs100" { + // MOTOR_SPLASH=0: keine Splash-Strategien laden (spart ~5 GB; Splash-Haende dann an den alten Kern) + if a[2] == "sechs100" && std::env::var("MOTOR_SPLASH").map_or(true, |x| x != "0") { std::thread::spawn(move || { for d in [20, 5, 10, 50, 2, 100] { let p = format!("{ordner}/splash{d}.bin"); @@ -174,9 +187,46 @@ fn main() { return; } } + // zu zweit: splashn2.bin (als negative Groesse gemeldet) + for d in [5, 10, 2, 20, 50] { + let p = format!("{ordner}/splash{d}n2.bin"); + if std::path::Path::new(&format!("{p}.ok")).exists() && tx.send((-d, dienst::Strategie::lade(&p))).is_err() { + return; + } + } }); } let mut splash: Vec<(i32, dienst::Motor)> = vec![]; + let mut splash_hu: Vec<(i32, dienst::Motor)> = vec![]; + // straddle.bin: 6-max mit drittem Blind; aus mit MOTOR_STRADDLE=0 (dann wie bisher der Notbehelf im Normalbaum) + let straddle: Option = (a[2] == "sechs100" && std::env::var("MOTOR_STRADDLE").map_or(true, |x| x != "0") && std::path::Path::new(&format!("{}/straddle.bin.ok", a[3])).exists()) + .then(|| dienst::Motor { s: Spiel::neu("straddle"), t: m.t.clone(), st: dienst::Strategie::lade(&format!("{}/straddle.bin", a[3])), genau: m.genau, merk: Default::default() }); + // ante.bin: 6-max mit Antes (x Hundertstel-bb je Spieler); aus mit MOTOR_ANTE=0 (dann Normalbaum, Antes als totes Geld) + let mut ante: Vec<(f64, dienst::Motor)> = vec![]; + if a[2] == "sechs100" && std::env::var("MOTOR_ANTE").map_or(true, |x| x != "0") { + for e in std::fs::read_dir(&a[3]).into_iter().flatten().flatten() { + let d = e.file_name().to_string_lossy().to_string(); + if let Some(x) = d.strip_prefix("ante").and_then(|x| x.strip_suffix(".bin")) { + if x.parse::().is_ok() && std::path::Path::new(&format!("{}/{d}.ok", a[3])).exists() { + ante.push((x.parse::().unwrap(), dienst::Motor { s: Spiel::neu(&format!("ante{x}")), t: m.t.clone(), st: dienst::Strategie::lade(&e.path().to_string_lossy()), genau: m.genau, merk: Default::default() })); + } + } + } + } + // aof[n].bin: All-In or Fold je Stapeltiefe (und Spielerzahl), klein, sofort geladen; aus mit MOTOR_AOF=0 + let mut aof: Vec<(i32, usize, dienst::Motor)> = vec![]; + if a[2] == "sechs100" && std::env::var("MOTOR_AOF").map_or(true, |x| x != "0") { + for e in std::fs::read_dir(&a[3]).into_iter().flatten().flatten() { + let d = e.file_name().to_string_lossy().to_string(); + if let Some(name) = d.strip_prefix("aof").and_then(|x| x.strip_suffix(".bin")) { + if !std::path::Path::new(&format!("{}/{d}.ok", a[3])).exists() { + continue; + } + let s = Spiel::neu(&format!("aof{name}")); + aof.push((s.stack / 100, s.n, dienst::Motor { s, t: m.t.clone(), st: dienst::Strategie::lade(&e.path().to_string_lossy()), genau: false, merk: Default::default() })); + } + } + } use std::io::{BufRead, Write}; for z in std::io::stdin().lock().lines() { let z = z.unwrap(); @@ -184,15 +234,51 @@ fn main() { continue; } let r = match serde_json::from_str::(&z) { + Ok(q) if !aof.is_empty() && dienst::Motor::ist_aof(&q) => { + // gleiche Spielerzahl zuerst, dann naechste Stapeltiefe (Verhaeltnis), hoechstens um den Faktor 1,6 daneben + let (tief, k) = aof_lage(&q); + let best = aof.iter().filter(|y| y.1 >= k).map(|y| ((y.1 != k) as i32 as f64 * 10.0 + ((y.0 as f64).ln() - tief.ln()).abs(), y)).min_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); + match best { + Some((w, y)) if w % 10.0 < 1.6f64.ln() => { + let mut r = y.2.antworte(&q); + r["reason"] = serde_json::json!(format!("AoF{}x{} {}", y.0, y.1, r["reason"].as_str().unwrap_or(""))); + r + } + _ => serde_json::json!({"action": "ABSTAIN", "size": null, "confidence": 0, "reason": format!("motor notfall: keine AoF-Strategie fuer {tief:.1} bb, {k} Spieler")}), + } + } + Ok(q) if straddle.is_some() && q["_splash"].as_f64().unwrap_or(0.0) <= 0.0 && dienst::Motor::ist_straddle(&q) && !dienst::Motor::zu_zweit(&q) => { + let mut r = straddle.as_ref().unwrap().antworte(&q); + r["reason"] = serde_json::json!(format!("Straddle {}", r["reason"].as_str().unwrap_or(""))); + r + } Ok(q) if q["_splash"].as_f64().unwrap_or(0.0) > 0.0 => { while let Ok((d, st)) = rx.try_recv() { - splash.push((d, dienst::Motor { s: Spiel::neu(&format!("splash{d}")), t: m.t.clone(), st, genau: m.genau, merk: Default::default() })); + if d < 0 { + splash_hu.push((-d, dienst::Motor { s: Spiel::neu(&format!("splash{}n2", -d)), t: m.t.clone(), st, genau: m.genau, merk: Default::default() })); + } else { + splash.push((d, dienst::Motor { s: Spiel::neu(&format!("splash{d}")), t: m.t.clone(), st, genau: m.genau, merk: Default::default() })); + } } // naechste gelernte Splash-Groesse (Verhaeltnis), hoechstens um den Faktor 1,6 daneben let x = (q["_splash"].as_f64().unwrap_or(0.0) / q["bigBlind"].as_f64().unwrap_or(1.0)).ln(); let best = splash.iter().map(|y| (((y.0 as f64).ln() - x).abs(), y)).min_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); + // ueber der groessten gelernten Groesse: die groesste (Toepfe weit ueber den Stapeln spielen sich gleich); + // ungemessen, daher nur mit MOTOR_SPLASH_GROSS=1 (sonst wie bisher der alte Kern) + let groesste = if std::env::var("MOTOR_SPLASH_GROSS").is_ok_and(|x| x == "1") { splash.iter().map(|y| y.0).max().unwrap_or(i32::MAX) as f64 } else { f64::MAX }; + // zu zweit (MOTOR_SPLASH_HU, 26.11.): Heads-up-Strategie, der Splash liegt als totes Geld im Topf + // zu zweit (MOTOR_SPLASH_HU, 26.11.): gelernte splashn2, naechste Groesse wie oben + let best_hu = splash_hu.iter().map(|y| (((y.0 as f64).ln() - x).abs(), y)).min_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); + let groesste_hu = splash_hu.iter().map(|y| y.0).max().unwrap_or(i32::MAX) as f64; match best { - Some((w, y)) if w < 1.6f64.ln() && !dienst::Motor::zu_zweit(&q) => { + _ if dienst::Motor::zu_zweit(&q) && std::env::var("MOTOR_SPLASH_HU").map_or(true, |x| x != "0") + && best_hu.is_some_and(|(w, _)| w < 1.6f64.ln() || x > groesste_hu.ln()) => { + let y = best_hu.unwrap().1; + let mut r = y.1.antworte(&q); + r["reason"] = serde_json::json!(format!("Splash{}-HU {}", y.0, r["reason"].as_str().unwrap_or(""))); + r + } + Some((w, y)) if (w < 1.6f64.ln() || x > groesste.ln()) && !dienst::Motor::zu_zweit(&q) => { let mut r = y.1.antworte(&q); r["reason"] = serde_json::json!(format!("Splash{} {}", y.0, r["reason"].as_str().unwrap_or(""))); r @@ -200,6 +286,19 @@ fn main() { _ => serde_json::json!({"action": "ABSTAIN", "size": null, "confidence": 0, "reason": "motor notfall: keine Splash-Strategie"}), } } + Ok(q) if !ante.is_empty() && dienst::Motor::ante_tot(&q) > 0.0 && !dienst::Motor::zu_zweit(&q) => { + // Ante je Spieler (Hundertstel-bb), naechste gelernte Groesse, hoechstens Faktor 1,6 daneben; sonst Normalbaum + let k = 1 + q["villains"].as_array().map_or(0, |v| v.len()); + let x = (dienst::Motor::ante_tot(&q) as f64 / k as f64).ln(); + match ante.iter().map(|y| ((y.0.ln() - x).abs(), y)).min_by(|a, b| a.0.partial_cmp(&b.0).unwrap()) { + Some((w, y)) if w < 1.6f64.ln() => { + let mut r = y.1.antworte(&q); + r["reason"] = serde_json::json!(format!("Ante{} {}", y.0, r["reason"].as_str().unwrap_or(""))); + r + } + _ => m.antworte(&q), + } + } Ok(q) if hu.len() == 2 && dienst::Motor::zu_zweit(&q) => hu[(dienst::Motor::wirksam(&q) > 150.0) as usize].antworte(&q), Ok(q) => m.antworte(&q), Err(e) => serde_json::json!({"action": "ABSTAIN", "size": null, "confidence": 0, "reason": format!("motor: {e}")}), diff --git a/entscheiden/motor/src/spiel.rs b/entscheiden/motor/src/spiel.rs index c1a3cf16..d52d20ea 100644 --- a/entscheiden/motor/src/spiel.rs +++ b/entscheiden/motor/src/spiel.rs @@ -28,22 +28,47 @@ pub struct Spiel { /// totes Geld des Hauses im Haupttopf (Splash), ohne Rake; `splash_echt` = am Tisch, `splash` = im gelernten Baum pub splash: i32, pub splash_echt: f32, + /// dritter Blind (2 bb) des Platzes nach dem BB, der zuletzt noch einmal handeln darf + pub straddle: bool, + /// Antes statt Splash: das tote Geld (`splash`) kommt aus Antes, normales Einsatzmenue + pub ante: bool, } impl Spiel { pub fn neu(name: &str) -> Self { - let s = |art, n, stack, rake, rake_kappe| Spiel { art, n, stack, rake, rake_kappe, splash: 0, splash_echt: 0.0 }; + let s = |art, n, stack, rake, rake_kappe| Spiel { art, n, stack, rake, rake_kappe, splash: 0, splash_echt: 0.0, straddle: false, ante: false }; match name { "hu200" => s(Art::Hu200, 2, 20000, 0.0, 0.0), "sechs100" => s(Art::Sechs100, 6, 10000, 0.05, 1000.0), "hu100" => s(Art::Sechs100, 2, 10000, 0.05, 250.0), "pushfold10" => s(Art::PushFold, 2, 1000, 0.0, 0.0), - x if x.starts_with("splash") => { + // Antes: ante, 6-max, tote Antes im Topf, normales Menue (MOTOR_ANTE, 26.11.) + x if x.starts_with("ante") => { let mut y = s(Art::Sechs100, 6, 10000, 0.05, 1000.0); - y.splash = x[6..].parse::().unwrap() * 100; + y.splash = x[4..].parse::().unwrap() * 6; + y.splash_echt = y.splash as f32; + y.ante = true; + y + } + // Straddle: 6-max NL2 mit drittem Blind (MOTOR_STRADDLE, 26.11.) + "straddle" => { + let mut y = s(Art::Sechs100, 6, 10000, 0.05, 1000.0); + y.straddle = true; + y + } + // splash[n2]: n2 = heads-up (Rake-Kappe wie hu100), sonst 6-max + x if x.starts_with("splash") => { + let (d, n) = x[6..].split_once('n').map_or((&x[6..], 6), |(d, n)| (d, n.parse::().unwrap())); + let mut y = if n == 2 { s(Art::Sechs100, 2, 10000, 0.05, 250.0) } else { s(Art::Sechs100, 6, 10000, 0.05, 1000.0) }; + y.splash = d.parse::().unwrap() * 100; y.splash_echt = y.splash as f32; y } + // All-In or Fold: aof[n], nur Fold oder All-in, Rake wie NL2 (z. B. aof8n4 = 8 bb, vier Spieler) + x if x.starts_with("aof") => { + let (bb, n) = x[3..].split_once('n').map_or((&x[3..], 6), |(b, n)| (b, n.parse::().unwrap())); + s(Art::PushFold, n, bb.parse::().unwrap() * 100, 0.05, 1000.0) + } x if x.starts_with("vorflop") => s(Art::NurVorflop, 2, x[7..].parse::().unwrap() * 100, 0.0, 0.0), _ => panic!("unbekanntes Spiel {name}"), } @@ -141,6 +166,15 @@ impl Zustand { z.gesamt[i] = b; z.stack[i] -= b; } + if s.straddle && n > 3 { + z.einsatz[2] = 200; + z.gesamt[2] = 200; + z.stack[2] -= 200; + z.pot += 200; + z.hoch = 200; + z.schritt = 200; + z.dran = 3; + } z } @@ -213,8 +247,8 @@ impl Zustand { (Art::Hu200, _, 3) => (&[], 99.0), (Art::Hu200, _, _) => (&[], if self.r < 6 { 99.0 } else { 0.0 }), - (_, 0, 0 | 1) if s.splash > 0 => (&sp, 99.0), - (_, 0, 2) if s.splash > 0 => (&sp[1..], 99.0), + (_, 0, 0 | 1) if s.splash > 0 && !s.ante => (&sp, 99.0), + (_, 0, 2) if s.splash > 0 && !s.ante => (&sp[1..], 99.0), (_, 0, 0) if self.n == 2 => (&[0.75], 0.0), (_, 0, 0) if callers > 1 => (&[1.1], 0.0), (_, 0, 0) if d == 0 => (&[1.0], 0.0), diff --git a/messung/pruef/tisch6.py b/messung/pruef/tisch6.py index 7cfb2f0a..8f0c30f5 100644 --- a/messung/pruef/tisch6.py +++ b/messung/pruef/tisch6.py @@ -2,6 +2,10 @@ NL2: 0,01/0,02, 100 bb, Rake 5 %, Kappe 20 Cent. Regelpruefung in jeder Hand: Einsaetze = Auszahlungen + Rake. Aufruf: tisch6.py X Y mit X, Y aus der Tabelle SPIELER oder 'cmd:' +Spielarten (26.11.): TISCH_ANTE= (Antes vor den Blinds, gehen in den Rake), +TISCH_AOF= (All-In or Fold: Stapel , nur FOLD und RAISE auf den ganzen Stapel), +TISCH_STRADDLE=1 (UTG setzt 2 bb als dritten Blind, POST_BB, und handelt vorflop zuletzt), +TISCH_SPLASH= (totes Geld des Hauses im Haupttopf, rakefrei, Anfrage wie lesen/spot_from_log: `_splash` und POST_ANTE mit splash). """ import itertools import json @@ -13,7 +17,7 @@ import sys import slumbot as S W = S.WURZEL -D = os.path.join(W, "daten", "grundstrategie", "motor") +D = os.environ.get("TISCH_DATEN") or os.path.join(W, "daten", "grundstrategie", "motor") T = os.path.join(W, "entscheiden", "motor", "target") LIVE = os.path.join(W, ".claude", "worktrees", "engine-lecks-angreifen-de7b88") STR = ("PREFLOP", "FLOP", "TURN", "RIVER") @@ -35,8 +39,21 @@ def start(name): _, spiel, k2, km, datei, *genau = name.split(":") cmd, cwd = [os.path.join(T, os.environ.get("TISCH_EXE", "pokerbench-motor-tisch.exe")), "dienst", spiel, D, k2, km, os.path.join(D, datei)] + genau, None env["RAYON_NUM_THREADS"] = os.environ.get("TISCH_FAEDEN", "2") - return subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env, cwd=cwd, text=True, encoding="utf-8", - bufsize=1, creationflags=0x4000) + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env, cwd=cwd, text=True, encoding="utf-8", + bufsize=1, creationflags=0x4000) + ohne_eco(p) + return p + + +def ohne_eco(p): + """Windows drosselt verborgene BelowNormal-Prozesse (EcoQoS) auf ~1 Kern: hier abschalten.""" + if sys.platform == "win32": + import ctypes + + class Q(ctypes.Structure): + _fields_ = [(x, ctypes.c_ulong) for x in "VCM"] + q = Q(1, 1, 0) + ctypes.windll.kernel32.SetProcessInformation(ctypes.c_void_p(int(p._handle)), 4, ctypes.byref(q), 12) def frage(p, a): @@ -80,7 +97,7 @@ def wert7(c): return max(wert5(x) for x in itertools.combinations(c, 5)) -def hand(blatt, spieler, seed, bbw=0.02, n=6, rake=0.05, kappe=1000, stack=10000): +def hand(blatt, spieler, seed, bbw=0.02, n=6, rake=0.05, kappe=1000, stack=10000, ante=0, aof=False, splash=0, straddle=False): """spieler[i] = Prozess auf Platz i (0=SB, 1=BB, 2..). Gibt Ergebnis je Platz in Hundertstel-bb.""" loch = [blatt[2 * i:2 * i + 2] for i in range(n)] brett = blatt[2 * n:2 * n + 5] @@ -98,17 +115,26 @@ def hand(blatt, spieler, seed, bbw=0.02, n=6, rake=0.05, kappe=1000, stack=10000 ein[i] += x ges[i] += x + for i in range(n if ante else 0): + x = min(ante, rest[i]) + rest[i] -= x + ges[i] += x + hist.append({"street": "PREFLOP", "seat": sitz(i), "action": "POST_ANTE", "amount": geld(x)}) for i, b, a in ((0, 50, "POST_SB"), (1, 100, "POST_BB")): zahle(i, b) hist.append({"street": "PREFLOP", "seat": sitz(i), "action": a, "amount": geld(b)}) hoch, schritt, gruende = 100, 100, [] + if straddle: + zahle(2, 200) + hist.append({"street": "PREFLOP", "seat": sitz(2), "action": "POST_BB", "amount": geld(200)}) + hoch, schritt = 200, 200 for st in range(4): if st: ein, hoch, schritt = [0] * n, 0, 100 frei = [i for i in range(n) if not raus[i] and rest[i] > 0] if len(frei) <= 1 and st: continue - ordnung = [(2 + k) % n for k in range(n)] if st == 0 else list(range(n)) + ordnung = [(2 + straddle + k) % n for k in range(n)] if st == 0 else list(range(n)) if n == 2: ordnung = [0, 1] if st == 0 else [1, 0] warten = [i for i in ordnung if not raus[i] and rest[i] > 0] @@ -121,24 +147,42 @@ def hand(blatt, spieler, seed, bbw=0.02, n=6, rake=0.05, kappe=1000, stack=10000 max_to = ein[i] + rest[i] legal = ["FOLD", "CALL"] if offen > 0 else ["CHECK"] kann = max_to > hoch and andere_frei - if kann: + if aof: + if offen <= 0: + continue + legal, kann = ["FOLD", "RAISE"], True + elif kann: legal.append("RAISE") b = {} for k, (nm, v, z) in enumerate((("FLOP", 0, 3), ("TURN", 3, 4), ("RIVER", 4, 5))): if st > k: b[nm] = [S.karte(c) for c in brett[v:z]] a = {"variant": "NLHE", "bigBlind": bbw, "seats": n, "heroSeat": sitz(i), "buttonSeat": sitz(n - 1 if n > 2 else 0), - "heroCards": [S.karte(c) for c in loch[i]], "board": b, "street": STR[st], "pot": geld(sum(ges)), + "heroCards": [S.karte(c) for c in loch[i]], "board": b, "street": STR[st], "pot": geld(sum(ges) + splash), "toCall": geld(min(offen, rest[i])), "heroStack": geld(rest[i]), "legalActions": legal, "allowedSizes": None, "villains": [{"seat": sitz(j), "stack": geld(rest[j]), "folded": raus[j]} for j in range(n) if j != i], - "history": list(hist), "seed": (seed * 7919 + len(hist) * 104729 + i) & 0xFFFFFFFF} - if kann: + **({"_splash": geld(splash)} if splash else {}), + "history": ([{"street": "PREFLOP", "seat": sitz(i), "action": "POST_ANTE", "amount": geld(splash), "splash": True}] if splash else []) + list(hist), "seed": (seed * 7919 + len(hist) * 104729 + i) & 0xFFFFFFFF} + if aof: + a["minRaiseTo"] = a["maxRaiseTo"] = geld(max_to) + elif kann: a["minRaiseTo"], a["maxRaiseTo"] = geld(min(hoch + max(schritt, 100), max_to)), geld(max_to) w = frage(spieler[i], a) akt = w.get("action") gruende.append((i, STR[st], akt, w.get("size"), (w.get("reason") or "")[:140])) e = {"street": STR[st], "seat": sitz(i)} - if akt == "RAISE" and kann: + if aof and akt == "RAISE": + war = hoch + zahle(i, max_to) + e["action"], e["amount"] = "ALL_IN", geld(ein[i]) + if ein[i] > hoch: + hoch = ein[i] + k = ordnung.index(i) + warten = [j for j in ordnung[k + 1:] + ordnung[:k] if not raus[j] and rest[j] > 0] + elif aof: + raus[i] = True + e["action"] = "FOLD" + elif akt == "RAISE" and kann: ziel = int(round(float(w["size"]) / f)) ziel = min(max(ziel, min(hoch + max(schritt, 100), max_to)), max_to) war = hoch @@ -168,7 +212,7 @@ def hand(blatt, spieler, seed, bbw=0.02, n=6, rake=0.05, kappe=1000, stack=10000 zweit = max(g for j, g in enumerate(ges) if j != w) basis = sum(min(g, zweit) for g in ges) rk = min(basis * rake, kappe) - erg[w] += sum(ges) - rk + erg[w] += sum(ges) - rk + splash else: wt = {i: wert7(loch[i] + brett) for i in lebt} unten, basis, teile = 0, 0, [0.0] * n @@ -185,19 +229,24 @@ def hand(blatt, spieler, seed, bbw=0.02, n=6, rake=0.05, kappe=1000, stack=10000 ziel = teile if sum(g > unten for g in ges) > 1 else unger for i in sieger: ziel[i] += schicht / len(sieger) + if unten == 0: + unger[i] += splash / len(sieger) if ziel is teile: basis += schicht unten = oben rk = min(basis * rake, kappe) for i in range(n): erg[i] += unger[i] + teile[i] * (1 - rk / basis if basis else 1) - assert abs(sum(erg) + rk) < 0.01, (erg, rk) + assert abs(sum(erg) + rk - splash) < 0.01, (erg, rk) return erg, hist, gruende, ges def main(): blaetter, seed, aus, xn, yn = int(sys.argv[1]), int(sys.argv[2]), sys.argv[3], sys.argv[4], sys.argv[5] n = int(os.environ.get("TISCH_N", "6")) + ante, aof = int(os.environ.get("TISCH_ANTE", "0")), int(os.environ.get("TISCH_AOF", "0")) + art = dict(ante=ante, aof=bool(aof), stack=aof * 100 if aof else 10000, splash=int(os.environ.get("TISCH_SPLASH", "0")), + straddle=os.environ.get("TISCH_STRADDLE") == "1") x, y = start(xn), start(yn) rng = random.Random(seed) with open(aus, "a", encoding="utf-8") as f: @@ -206,7 +255,7 @@ def main(): rng.shuffle(blatt) for platz in range(n): sp = [x if i == platz else y for i in range(n)] - erg, hist, gr, ges = hand(blatt, sp, seed * 100000 + b * 10 + platz, n=n) + erg, hist, gr, ges = hand(blatt, sp, seed * 100000 + b * 10 + platz, n=n, **art) f.write(json.dumps({"blatt": b, "platz": platz, "erg": round(erg[platz] / 100, 3), "x": xn, "y": yn, "loch": blatt[2 * platz:2 * platz + 2], "karten": blatt[:2 * n + 5], "g": [g for g in gr if g[0] == platz],