Files
pokerfreak/tests/splash_topf_spec.py
T
mmintelandClaude Opus 5.5 d32d6e4dbd Splash-Pot: Topfanteil belegt und in die Uebersetzung (statt Enthaltung)
Beleg aus 25 echten Splash-Haenden (Client-Log 16.11., EV-INRIT): dropAmount bzw.
potInfo.splashPotDropAmount ist der Betrag, steht NICHT in user_turn.totalPot und geht
ohne Rake an den Gewinner des Haupttopfs (Gewinn = actualWinAmount + Drop; RIT teilt,
Nebentopf-Gewinner bekommt nichts). Proben in archiv/proben/splash/.

Uebersetzung: pot = totalPot + Drop, vorn im Verlauf POST_ANTE des eigenen Sitzes mit
"splash": true (totes Geld, Kern liest keinen Limp); _splash in der Anfrage. Kein oder
widerspruechlicher Betrag -> weiter Enthaltung. aivat/linien/rueckbau ueberspringen den
Splash-Eintrag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 17:51:17 +01:00

187 lines
7.6 KiB
Python

#!/usr/bin/env python3
"""Splash-Pot: der Topfanteil, belegt aus echten Händen, und wie die Übersetzung ihn weitergibt.
Quelle: archiv/proben/splash/splash_<hand>.log, Zeilen aus dem Client-Log
(%APPDATA%/CoinPoker/logs, 16.11., Tische EV-INRIT, NL 0.01/0.02), je Hand nur die Zeilen dieses
Tisches; 179003700007 und 178710800974 dazu mit dem letzten game_alldata des Raums.
Beleg (aus den Händen, nicht geraten):
* `game.splash_the_pot.dropAmount` > 0 ist der Splash (isIllusion mit 0.0 ist nur Bild);
`game.potInfo.splashPotDropAmount` trägt denselben Betrag, in Chips.
* `user_turn.totalPot` enthält ihn NICHT (179003700007: totalPot 0.03 = Blinds, Drop 0.04).
* Er geht ohne Rake an den Gewinner des Haupttopfs (potId 0): Gewinn = actualWinAmount + Drop,
`isSplashPotWinner: true`. Mit Run-it-twice teilen ihn beide Lauf-Gewinner (178710800974);
wer nur einen Nebentopf gewinnt, bekommt nichts (178819100127, Craf8).
Übersetzung: pot = totalPot + Drop, dazu vorn im Verlauf ein `POST_ANTE` des eigenen Sitzes mit
`"splash": true` (totes Geld, so rechnet der Kern Pot-Odds und Lage richtig). Unklarer Betrag
(keiner belegt, oder zwei verschiedene) -> weiter Enthaltung.
python3 tests/splash_topf_spec.py -v
"""
import json
import os
import re
import sys
import unittest
_w = os.path.dirname(os.path.abspath(__file__))
while _w != os.path.dirname(_w) and not os.path.isdir(os.path.join(_w, "lesen")):
_w = os.path.dirname(_w)
for _u in ("lesen", "entscheiden", "hand", "client"):
sys.path.insert(0, os.path.join(_w, _u))
import spot_from_log
PROBEN = os.path.join(_w, "archiv", "proben", "splash")
_BEAN = re.compile(r'BeanData":"(.*?)","Cmd":"([\w.]+)"')
def text(hand):
with open(os.path.join(PROBEN, "splash_%s.log" % hand), encoding="utf-8") as f:
return f.read()
def befehle(t, hand):
"""[(cmd, daten)] der Hand, in Logfolge."""
aus = []
for z in t.splitlines():
m = _BEAN.search(z)
if not m:
continue
try:
d = json.loads(m.group(1).encode().decode("unicode_escape"))
except ValueError:
continue
if isinstance(d, dict) and d.get("gameHandId") == hand:
aus.append((m.group(2), d))
return aus
def drops(t, hand):
return {round(d["dropAmount"], 10) for c, d in befehle(t, hand)
if c == "game.splash_the_pot" and (d.get("dropAmount") or 0) > 0}
def gewinner(t, hand):
"""Name -> [Gewinn der Hand, isSplashPotWinner, [actualWinAmount je Topf/Lauf], [potId]]"""
cum = [d for c, d in befehle(t, hand) if c == "game.cumulativeWinnerInfo"][-1]
aus = {w["userName"]: [w["cumulativeProfitLoss"], w.get("isSplashPotWinner"), [], []]
for w in cum["winnersData"]}
for c, d in befehle(t, hand):
if c != "game.winnerInfo":
continue
for p in d.get("winnerDataList") or []:
for x in (p.get("winnerDetails") or {}).get("winnerList") or []:
aus[x["playerName"]][2].append(x.get("actualWinAmount"))
aus[x["playerName"]][3].append(p.get("potId"))
return aus
def anfragen(t):
return [json.loads(z[0]) for z in spot_from_log.spots(t)]
def setze(t, feld, wert):
"""Ein Betragsfeld in allen (maskierten) Zeilen überschreiben."""
return re.sub(r'(\b%s\\":)[0-9.]+' % feld, lambda m: m.group(1) + wert, t)
class Beleg(unittest.TestCase):
def test_drop_und_potinfo_nennen_denselben_betrag(self):
for hand, betrag in (("179003700007", 0.04), ("178845700016", 0.5),
("178710800974", 1.0), ("178819100127", 1.0)):
t = text(hand)
self.assertEqual(drops(t, hand), {betrag}, hand)
pi = {round(d["splashPotDropAmount"], 10) for c, d in befehle(t, hand)
if c == "game.potInfo" and (d.get("splashPotDropAmount") or 0) > 0}
self.assertEqual(pi, {betrag}, hand)
def test_totalpot_ohne_splash(self):
zuege = [d for c, d in befehle(text("179003700007"), "179003700007")
if c == "game.user_turn" and d.get("userTurnOptions")]
self.assertEqual(zuege[0]["totalPot"], 0.03) # SB 0.01 + BB 0.02, Drop 0.04 fehlt
def test_gewinner_bekommt_drop_ohne_rake(self):
for hand in ("179003700007", "178845700016"):
t = text(hand)
(drop,) = drops(t, hand)
g = gewinner(t, hand)
self.assertEqual(len(g), 1, hand)
gewinn, splash, wins, pots = next(iter(g.values()))
self.assertTrue(splash)
self.assertEqual(pots, [0])
self.assertAlmostEqual(gewinn, sum(wins) + drop, places=6, msg=hand)
def test_run_it_twice_teilt_den_splash(self):
g = gewinner(text("178710800974"), "178710800974")
self.assertEqual(len(g), 2)
self.assertTrue(all(v[1] for v in g.values()))
def test_nebentopf_gewinner_bekommt_nichts(self):
g = gewinner(text("178819100127"), "178819100127")
self.assertFalse(g["Craf8"][1])
self.assertEqual(g["Craf8"][3], [1])
self.assertTrue(g["lasting98005466"][1])
class Uebersetzung(unittest.TestCase):
def pruefe(self, hand, drop):
anf = anfragen(text(hand))
self.assertTrue(anf, hand)
for a in anf:
self.assertNotIn("Splash", a.get("_unklar") or "")
self.assertTrue(a["legalActions"])
self.assertEqual(a["_splash"], drop)
kopf = a["history"][0]
self.assertEqual((kopf["action"], kopf["amount"], kopf.get("splash"), kopf["street"]),
("POST_ANTE", drop, True, "PREFLOP"))
self.assertEqual(sum(1 for r in a["history"] if r.get("splash")), 1)
return anf
def test_kleiner_splash_179003700007(self):
(a,) = self.pruefe("179003700007", 0.04)
self.assertEqual(a["street"], "PREFLOP")
self.assertAlmostEqual(a["pot"], 0.07) # 0.03 + 0.04
self.assertAlmostEqual(a["toCall"], 0.02)
def test_mega_splash_178710800974(self):
(a,) = self.pruefe("178710800974", 1.0)
self.assertAlmostEqual(a["pot"], 1.57) # 0.57 + 1.0
def test_illusion_ist_kein_splash(self):
t = setze(setze(text("179003700007"), "dropAmount", "0.0"), "splashPotDropAmount", "0.0")
(a,) = anfragen(t)
self.assertNotIn("_splash", a)
self.assertAlmostEqual(a["pot"], 0.03)
self.assertFalse(any(r.get("splash") for r in a["history"]))
def test_widerspruch_setzt_aus(self):
(a,) = anfragen(setze(text("179003700007"), "splashPotDropAmount", "0.05"))
self.assertIn("Splash-Pot: Topfanteil unklar", a["_unklar"])
self.assertEqual(a["legalActions"], [])
def test_mega_ohne_betrag_setzt_aus(self):
t = setze(setze(text("178710800974"), "dropAmount", "0.0"), "splashPotDropAmount", "0.0")
(a,) = anfragen(t)
self.assertIn("Splash-Pot: Topfanteil unklar", a["_unklar"])
class Kern(unittest.TestCase):
"""Der gebaute Kern rechnet die Splash-Anfrage normal (keine Enthaltung, gültige Antwort)."""
def test_kern_antwortet(self):
import decide
pfad = next((p for p in (decide.BINARY, decide.BINARY + ".exe") if os.path.exists(p)), None)
if not pfad:
self.skipTest("Kern nicht gebaut (COINPOKER_KERN)")
decide.BINARY = pfad
anf = anfragen(text("179003700007")) + anfragen(text("178710800974"))
for a, b in zip(anf, decide.entscheide([json.dumps(a) for a in anf])):
self.assertNotEqual(b["action"], "ABSTAIN", b)
self.assertNotIn("invalid", b.get("reason", ""), b)
if __name__ == "__main__":
unittest.main()