101 lines
4.7 KiB
Python
101 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Spot-Mix des Helden: echte Vorflop-Anfragen (Schatten-Logs, nur lesen) neu gerechnet mit den Live-Schaltern und mit
|
|
dem Arm (VORFLOP_POP + jamread). Zaehlt, wie viele Entscheidungen der Teil kippt und was dort auf dem Spiel steht.
|
|
|
|
Ausgabe nur Zaehler, Klasse, Position, Preis, Equity, Read-Spalte (keine Gegnerkennung, keine Namen).
|
|
Kern-Kopie `pokerbench-vorflop-jamread.exe`, BelowNormal.
|
|
|
|
python -I -X utf8 lesen/vorflop/jamread_replay.py <kern.exe> <kern_schalter.txt> <aus.json> <shadow.jsonl> ...
|
|
[--prozesse 12] [--teil jamread|jamall|jamread,jamall]
|
|
"""
|
|
import collections
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
_HIER = os.path.dirname(os.path.abspath(__file__))
|
|
_BAUM = os.path.dirname(os.path.dirname(_HIER))
|
|
sys.path.insert(0, os.path.join(_BAUM, "werkzeuge"))
|
|
import kippliste as KL # noqa: E402
|
|
|
|
RANG = {"TWO": "2", "THREE": "3", "FOUR": "4", "FIVE": "5", "SIX": "6", "SEVEN": "7", "EIGHT": "8", "NINE": "9", "TEN": "T",
|
|
"JACK": "J", "QUEEN": "Q", "KING": "K", "ACE": "A"}
|
|
ORD = "23456789TJQKA"
|
|
|
|
|
|
def klasse(cards):
|
|
a, b = cards
|
|
ra, rb = RANG[a["rank"]], RANG[b["rank"]]
|
|
if ORD.index(ra) < ORD.index(rb):
|
|
ra, rb = rb, ra
|
|
if ra == rb:
|
|
return ra + rb
|
|
return ra + rb + ("s" if a["suit"] == b["suit"] else "o")
|
|
|
|
|
|
def main():
|
|
args = [a for a in sys.argv[1:] if not a.startswith("--")]
|
|
pz = int(sys.argv[sys.argv.index("--prozesse") + 1]) if "--prozesse" in sys.argv else 12
|
|
if "--prozesse" in sys.argv:
|
|
args = [a for a in args if a != str(pz)]
|
|
teil = sys.argv[sys.argv.index("--teil") + 1] if "--teil" in sys.argv else "jamread"
|
|
args = [a for a in args if a != teil]
|
|
kern, schalter, aus, logs = args[0], args[1], args[2], args[3:]
|
|
live = KL.lies_schalter(schalter)
|
|
vp = live.get("VORFLOP_POP", "")
|
|
arm = dict(live, VORFLOP_POP=(vp + "," + teil).strip(","))
|
|
spots, gesehen = [], set()
|
|
for f in logs:
|
|
for z in open(f, encoding="utf-8"):
|
|
if '"anfrage"' not in z or '"PREFLOP"' not in z:
|
|
continue
|
|
d = json.loads(z)
|
|
a = d["anfrage"]
|
|
if a.get("street") != "PREFLOP" or float(a.get("toCall") or 0) <= 0:
|
|
continue
|
|
key = json.dumps({k: a[k] for k in a if k != "_sitze"}, sort_keys=True)
|
|
if key in gesehen:
|
|
continue
|
|
gesehen.add(key)
|
|
req = {k: v for k, v in a.items() if not k.startswith("_")}
|
|
spots.append({"req": req, "datei": os.path.basename(f)})
|
|
base = KL.kern_lauf(kern, spots, live, prozesse=pz)
|
|
kand = KL.kern_lauf(kern, spots, arm, prozesse=pz)
|
|
bb_of = lambda s: float(s["req"]["bigBlind"])
|
|
kipps = []
|
|
for s, x, y in zip(spots, base, kand):
|
|
ax, ay = KL.art(x, s["req"]), KL.art(y, s["req"])
|
|
if ax == ay:
|
|
continue
|
|
r = s["req"]
|
|
bb = bb_of(s)
|
|
grund = y.get("reason", "")
|
|
m = re.search(r"Equity ([0-9.]+) - (\d+) dahinter \+ Marge ([0-9.]+) < Preis ([0-9.]+)", grund)
|
|
call = min(float(r["toCall"]), float(r["heroStack"])) / bb
|
|
eq, need = (float(m.group(1)), float(m.group(4))) if m else (None, None)
|
|
k = {"datei": s["datei"], "klasse": klasse(r["heroCards"]), "live": ax, "arm": ay, "call_bb": round(call, 1),
|
|
"topf_bb": round(float(r["pot"]) / bb, 1), "equity_tabelle": eq, "preis": need,
|
|
"gewinn_modell_bb": round((need - eq) * call / need, 2) if m else None,
|
|
"lage": (re.search(r"(?:jamread|jamall): ([^,]*)", grund).group(1) if re.search(r"(?:jamread|jamall): ", grund)
|
|
else grund[-160:]),
|
|
"grund_live": x.get("reason", "")[:200]}
|
|
kipps.append(k)
|
|
jam_spots = sum(1 for s in spots if float(s["req"]["toCall"]) >= 0.9 * float(s["req"]["heroStack"])
|
|
or any(h.get("action") == "ALL_IN" and h.get("street") == "PREFLOP" for h in s["req"]["history"]))
|
|
erg = {"anfragen_vorflop_mit_einsatz": len(spots), "davon_gegen_allin": jam_spots,
|
|
"je_datei": dict(collections.Counter(s["datei"] for s in spots)), "gekippt": len(kipps),
|
|
"richtung": dict(collections.Counter("%s->%s" % (k["live"], k["arm"]) for k in kipps)),
|
|
"einsatz_bb": round(sum(k["call_bb"] for k in kipps), 1),
|
|
"gewinn_modell_bb": round(sum(k["gewinn_modell_bb"] or 0 for k in kipps), 1), "kipps": kipps}
|
|
with open(aus, "w", encoding="utf-8", newline="\n") as f:
|
|
json.dump(erg, f, ensure_ascii=False, indent=1)
|
|
print(json.dumps({k: v for k, v in erg.items() if k != "kipps"}, ensure_ascii=False))
|
|
for k in kipps:
|
|
print(k["datei"][:22], k["klasse"], k["live"], "->", k["arm"], k["call_bb"], k["preis"], k["equity_tabelle"],
|
|
k["gewinn_modell_bb"], k["lage"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|