Echte Auszahlungen nachrechnen und Chop-Tische in der Anfrage (Claudes Specs)
echte_chops liest Equity aus game.poker_odds VOR der Entscheidung, die Wahl aus game.ev_chop_opted_action, Topf und Ergebnis aus den Winner-Zeilen - und rechnet die Auszahlung nach (der Raum zahlt 97 % der Equity). Ohne Gegenzeile bleibt der Betrag leer statt erfunden. Ausserdem traegt die Anfrage auf Chop-Tischen evChop - der Kern weiss dann, dass die Equity auszahlbar ist.
This commit is contained in:
+143
@@ -9,9 +9,19 @@ den Topf). Reine Funktionen; Spezifikation: tests/funde_spec.py, tests/evchop_re
|
||||
annehmen(unsere_equity, gezahlter_anteil) -> (bool, grund)
|
||||
preis_anteil(auszahlung, topf) -> Prozent des Topfes oder None
|
||||
chops(text) -> je entschiedener Hand {"name", "anteil"}
|
||||
echte_chops(text) -> je Auszahlung {"hand", "equity", "topf", "ausgezahlt", "anteil"}
|
||||
cashout_wert(equity, topf) -> was der Raum dafuer zahlt
|
||||
|
||||
`echte_chops` ist der genaue Weg: Equity aus `game.poker_odds` VOR der Entscheidung, die Wahl aus
|
||||
`game.ev_chop_opted_action`, Topf aus `game.winnerInfo`, Ergebnis aus `game.cumulativeWinnerInfo`.
|
||||
Der Gegner bekommt den ganzen Topf, sein Einsatz ist also Topf minus sein Gewinn - im Kopf-an-Kopf
|
||||
ist das der Einsatz des Auszahlers, und Auszahlung = Einsatz + sein Ergebnis.
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
|
||||
CASHOUT_ANTEIL = 0.97 # der Raum zahlt 97 % der Equity (an acht echten Auszahlungen nachgerechnet)
|
||||
|
||||
# Ein Chop ist nur bei echtem Vorteil richtig: bei gleichem Anteil nimmt man die Schwankung
|
||||
# freiwillig mit. Der Rand deckt unsere eigene Schaetzunsicherheit mit ab.
|
||||
VORTEIL = 0.0
|
||||
@@ -62,9 +72,142 @@ def chops(text):
|
||||
return treffer
|
||||
|
||||
|
||||
CASHOUT_QUOTE = 0.97
|
||||
|
||||
|
||||
def cashout_wert(equity, topf):
|
||||
"""Auszahlung in Chips bei `equity` Prozent und `topf` nach Rake."""
|
||||
return equity / 100.0 * CASHOUT_QUOTE * topf
|
||||
|
||||
|
||||
_ZEILE = re.compile(r'SendMessageToPipe - (\{.*\})\s*$')
|
||||
|
||||
|
||||
def _bohnen(text):
|
||||
for roh in (text or "").splitlines():
|
||||
m = _ZEILE.search(roh)
|
||||
if not m or "game." not in roh:
|
||||
continue
|
||||
try:
|
||||
bohne = json.loads(m.group(1))["Data"]["cmd_bean"]
|
||||
yield bohne["Cmd"], json.loads(bohne["BeanData"])
|
||||
except (ValueError, KeyError, TypeError):
|
||||
continue
|
||||
|
||||
|
||||
def _auszahlung(ich, gewinner, topf):
|
||||
"""Der Gegner bekam den ganzen Topf: sein Einsatz ist Topf minus sein Gewinn, im Kopf-an-Kopf
|
||||
auch unserer. Ohne Gegenzeile oder Topf None."""
|
||||
andere = [g for g in gewinner if g is not ich]
|
||||
if len(andere) != 1 or not topf:
|
||||
return None
|
||||
return round(topf - andere[0]["cumulativeProfitLoss"] + ich["cumulativeProfitLoss"], 2)
|
||||
|
||||
|
||||
def echte_chops(text):
|
||||
"""Jede ausgezahlte Hand aus dem Log. `equity` ist die erste Zahl des Clients je Hand, also die
|
||||
vor der Wahl. Nicht nachrechenbar: `ausgezahlt` und `anteil` None."""
|
||||
equity, topf, treffer = {}, {}, []
|
||||
for cmd, d in _bohnen(text):
|
||||
hand = d.get("gameHandId")
|
||||
if cmd == "game.poker_odds" and hand not in equity:
|
||||
equity[hand] = {h["seatId"]: h["winChance"] for h in d.get("hands") or []}
|
||||
elif cmd == "game.winnerInfo":
|
||||
topf[hand] = sum(p.get("potAmountAfterRake") or 0 for p in d.get("winnerDataList") or [])
|
||||
elif cmd == "game.cumulativeWinnerInfo":
|
||||
gewinner = d.get("winnersData") or []
|
||||
for g in (g for g in gewinner if g.get("isEVChopWinner")):
|
||||
t = topf.get(hand)
|
||||
aus = _auszahlung(g, gewinner, t)
|
||||
treffer.append({"hand": hand, "name": g.get("userName"), "topf": t, "ausgezahlt": aus,
|
||||
"equity": equity.get(hand, {}).get(g.get("seatId")),
|
||||
"anteil": None if aus is None else preis_anteil(aus, t)})
|
||||
return treffer
|
||||
|
||||
|
||||
def klartext(v):
|
||||
if not v or not v.get("moeglich"): return "kein EV-Chop"
|
||||
teile = ["EV-Auszahlung moeglich"]
|
||||
if v.get("min_pot_bb"): teile.append(f"ab {v['min_pot_bb']:g} BB Topf")
|
||||
if v.get("entschieden"): teile.append(f"{v['entschieden']} Entscheidungen im Log")
|
||||
return " | ".join(teile)
|
||||
|
||||
|
||||
_BEAN = re.compile(r'"BeanData":"((?:[^"\\]|\\.)*)","Cmd":"([a-zA-Z_.]+)","RoomName":"((?:[^"\\]|\\.)*)"')
|
||||
|
||||
|
||||
def _bohnen(text):
|
||||
"""(cmd, daten) je Logzeile - die Bohne doppelt entschluesselt (C#-String, dann JSON)."""
|
||||
for m in _BEAN.finditer(text or ""):
|
||||
try:
|
||||
roh = json.loads('"' + m.group(1) + '"')
|
||||
d = json.loads(roh)
|
||||
except ValueError:
|
||||
continue
|
||||
if isinstance(d, dict):
|
||||
yield m.group(2), d
|
||||
|
||||
|
||||
def cashout_wert(equity_prozent, topf, anteil=CASHOUT_ANTEIL):
|
||||
"""Was der Raum fuer diese Equity zahlt. None, wenn Equity oder Topf fehlen."""
|
||||
if equity_prozent is None or not topf:
|
||||
return None
|
||||
return topf * (equity_prozent / 100.0) * anteil
|
||||
|
||||
|
||||
def _equity_je_sitz(bean):
|
||||
"""Erste Odds-Zeile einer Hand: Sitz -> Gewinnchance (vor der Entscheidung)."""
|
||||
return {h.get("seatId"): h.get("winChance") for h in bean.get("hands") or [] if isinstance(h, dict)}
|
||||
|
||||
|
||||
def echte_chops(text):
|
||||
"""Jede Hand mit EV-Auszahlung, mit Equity, Topf und dem tatsaechlich gezahlten Betrag.
|
||||
|
||||
Ohne Gegenzeile (nur eine Ergebniszeile) bleibt der Betrag None - lieber leer als erfunden.
|
||||
"""
|
||||
equity, topf, chop = {}, {}, {}
|
||||
zeilen = {}
|
||||
for cmd, bean in _bohnen(text):
|
||||
hand = bean.get("gameHandId")
|
||||
if not hand:
|
||||
continue
|
||||
zeilen.setdefault(hand, []).append((cmd, bean))
|
||||
if cmd == "game.poker_odds" and not equity.get(hand):
|
||||
equity[hand] = _equity_je_sitz(bean)
|
||||
elif cmd == "game.ev_chop_opted_action":
|
||||
for e in bean.get("optedEvChopActionData") or []:
|
||||
if isinstance(e, dict) and e.get("optedForEVChop") is True and e.get("seatId") is not None:
|
||||
chop.setdefault(hand, e["seatId"])
|
||||
elif cmd == "game.winnerInfo":
|
||||
for w in bean.get("winnerDataList") or []:
|
||||
if isinstance(w, dict) and w.get("potAmountAfterRake") is not None:
|
||||
topf[hand] = float(w["potAmountAfterRake"])
|
||||
aus = []
|
||||
for hand, sitz in chop.items():
|
||||
un = equity.get(hand) or {}
|
||||
gewinn = _gewinn_der_hand(zeilen.get(hand) or [], sitz)
|
||||
pot = topf.get(hand)
|
||||
ausgezahlt = None
|
||||
if gewinn is not None and pot is not None and gewinn["gegner"] is not None:
|
||||
einsatz = pot - gewinn["gegner"]
|
||||
ausgezahlt = round(einsatz + gewinn["chop"], 2)
|
||||
aus.append({"hand": hand, "equity": un.get(sitz), "topf": pot, "ausgezahlt": ausgezahlt,
|
||||
"anteil": preis_anteil(ausgezahlt, pot) if ausgezahlt is not None else None})
|
||||
return sorted(aus, key=lambda c: c["hand"])
|
||||
|
||||
|
||||
def _gewinn_der_hand(zeilen, sitz):
|
||||
"""(Ergebnis des Auszahlers, Ergebnis des Gegners) aus der Ergebniszeile - None, wenn keine."""
|
||||
for cmd, bean in zeilen:
|
||||
if cmd != "game.cumulativeWinnerInfo":
|
||||
continue
|
||||
chop = gegen = None
|
||||
for w in bean.get("winnersData") or []:
|
||||
if not isinstance(w, dict):
|
||||
continue
|
||||
if w.get("seatId") == sitz or w.get("isEVChopWinner") is True:
|
||||
chop = w.get("cumulativeProfitLoss")
|
||||
else:
|
||||
gegen = w.get("cumulativeProfitLoss")
|
||||
return {"chop": chop, "gegner": gegen} if chop is not None else None
|
||||
return None
|
||||
|
||||
@@ -245,6 +245,7 @@ class Tisch:
|
||||
|
||||
def __init__(self, room):
|
||||
self.room = room
|
||||
self.evchop = False
|
||||
self.marken = {} # Spielername -> Marke (vom Aufrufer gesetzt)"""
|
||||
self.board = {}
|
||||
self.board_double = {}
|
||||
@@ -266,6 +267,7 @@ class Tisch:
|
||||
self.art = None # Spielart des Tisches (bleibt über Hände), siehe `spielart`
|
||||
self.rueckgaben = set() # schon verbuchte return_chips (dieselbe Zeile kann doppelt im Text stehen)
|
||||
self.kpoker = False # roomProperties.isKPoker (game_alldata)
|
||||
self.ev_chop = False # roomProperties.isEvChop (game_alldata)
|
||||
self.raum_rp = {} # roomProperties aus game_alldata, siehe `format`
|
||||
self.lobby = None # Turniertisch: Raum der Turnierlobby (Comm_Tournament_<Nr>), siehe `merke_turnier`
|
||||
|
||||
@@ -283,6 +285,8 @@ class Tisch:
|
||||
"""roomProperties aus game_alldata: Spielart, Format-Merkmale (plans/2026-10-30_formate.md)."""
|
||||
self.merke_art(rp.get("miniGameTypeId"), rp.get("gameType"), "roomProperties")
|
||||
self.kpoker = rp.get("isKPoker") is True
|
||||
self.ev_chop = rp.get("isEvChop") is True
|
||||
self.evchop = rp.get("isEvChop") is True # Tisch zahlt die Equity aus
|
||||
self.raum_rp = rp
|
||||
|
||||
def format(self):
|
||||
@@ -505,8 +509,10 @@ class Tisch:
|
||||
"minRaiseTo": groessen[0] if groessen else None,
|
||||
"maxRaiseTo": groessen[-1] if groessen else None,
|
||||
"legalActions": legal, "allowedSizes": groessen or None, "villains": gegner,
|
||||
# Chop-Tisch: der Kern soll wissen, dass die Equity auszahlbar ist
|
||||
**({"evChop": True} if self.evchop else {}),
|
||||
"history": [dict(r, seat=plan[r["seat"]]) for r in self.verlauf],
|
||||
"tournament": feld,
|
||||
"tournament": feld, "evChop": True if self.ev_chop else None,
|
||||
"_unklar": unklar, "_sitze": {neu: alt for alt, neu in plan.items()},
|
||||
}
|
||||
anfrage = {k: v for k, v in anfrage.items() if v not in (None, {}, [])}
|
||||
|
||||
Reference in New Issue
Block a user