Files
pokerfreak/lesen/vorflop/fix_tor.py
T

98 lines
4.3 KiB
Python

#!/usr/bin/env python3
"""Tor eines Vorflop-Kandidaten auf den hhDealer-Spots: zwei Kernlaeufe (aus / an) ueber dieselben Spots
(`stackoff_kern.py lauf`), kreuzgefittet bepreist wie `stackoff_kern.py bericht`.
Ausgabe je Knoten: Kipps, Kipps nach Richtung, Delta (an - aus) in bb (Modellpreis; nicht bepreisbare Kipps gezaehlt),
Praemien-Folds gegen ein All-in heads-up / mehrweg vorher und nachher, und bb/100 bezogen auf alle Spieler-Haende.
python -I -X utf8 lesen/vorflop/fix_tor.py <spots.pkl> <lauf-aus.pkl> <lauf-an.pkl> <aus.json> [--spielerhaende N]
"""
import collections
import json
import os
import pickle
import sys
_HIER = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, _HIER)
sys.path.insert(0, os.path.join(os.path.dirname(_HIER), "vorflop_population"))
import stackoff_kern as SK # noqa: E402
import klassen as K # noqa: E402
def heads_up(s):
"""Kein anderer Gegner callt (oder geht all-in) nach der hoechsten Erhoehung eines Gegners (nach Betrag, ein
All-in unter der Hoehe ist ein Call) - wie `vorflop_pop::jam_lage`."""
r = s["req"]
hoch, idx, jammer = 0.0, None, None
for i, h in enumerate(r["history"]):
a = h.get("amount")
if a is None:
continue
if h["action"] in ("POST_SB", "POST_BB"):
hoch = max(hoch, a)
elif h["action"] in ("RAISE", "ALL_IN") and a > hoch + 1e-9:
hoch, idx, jammer = a, i, h["seat"]
if idx is None or jammer == r["heroSeat"]:
return True
return not any(h["action"] in ("CALL", "ALL_IN", "RAISE") and h["seat"] not in (r["heroSeat"], jammer)
for h in r["history"][idx + 1:])
def main():
args = sys.argv[1:]
spf, af, bf, aus = args[:4]
sh = int(args[args.index("--spielerhaende") + 1]) if "--spielerhaende" in args else None
d = pickle.load(open(spf, "rb"))
sp = d["spots"]
A, B = pickle.load(open(af, "rb")), pickle.load(open(bf, "rb"))
P = {h: SK.Preise(sp, d["jams"], d["knoten_ev"], h, K) for h in (0, 1)}
z = collections.defaultdict(collections.Counter)
beispiele = collections.defaultdict(list)
for i, s in enumerate(sp):
a, b = A["art"][i], B["art"][i]
kn = "%s %s" % (SK.knoten(s), SK.TIEFEN[s["tiefe"]])
c = z[kn]
prae = s["klasse"] in SK.PRAEMIE and s["facing_allin"]
if prae:
hu = "hu" if heads_up(s) else "mehrweg"
c["praemie_fold_vorher_" + hu] += a == "FOLD"
c["praemie_fold_nachher_" + hu] += b == "FOLD"
if a == b:
continue
c["kipp"] += 1
c["%s->%s" % (a, b)] += 1
c["kipp_" + s["gruppe"]] += 1
pr = P[1 - s["hf"]]
ea, eb = pr.ev(s, a), pr.ev(s, b)
if ea is None or eb is None:
c["unbepreist"] += 1
continue
c["bepreist"] += 1
c["delta_bb"] += eb - ea
c["delta_bb_" + s["gruppe"]] += eb - ea
if len(beispiele[kn]) < 6:
beispiele[kn].append("%s %s->%s %+.1f | %s" % (s["klasse"], a, b, eb - ea, (B["grund"][i] or "")[-110:]))
gesamt = collections.Counter()
for c in z.values():
gesamt.update(c)
out = {"spots": len(sp), "gesamt": {k: (round(v, 1) if isinstance(v, float) else v) for k, v in gesamt.items()},
"knoten": {k: {kk: (round(vv, 1) if isinstance(vv, float) else vv) for kk, vv in c.items()}
for k, c in sorted(z.items()) if c}, "beispiele": dict(beispiele)}
if sh:
out["spielerhaende"] = sh
out["delta_bb_je_100"] = round(100.0 * gesamt["delta_bb"] / sh, 4)
with open(aus, "w", encoding="utf-8", newline="\n") as f:
json.dump(out, f, ensure_ascii=False, indent=1)
for k, c in sorted(z.items()):
if c["kipp"] or c["praemie_fold_vorher_hu"] or c["praemie_fold_vorher_mehrweg"]:
print("%-30s kipp %5d bepreist %5d delta %+9.1f bb | praemie-fold hu %d->%d mehrweg %d->%d | %s" % (
k, c["kipp"], c["bepreist"], c["delta_bb"], c["praemie_fold_vorher_hu"], c["praemie_fold_nachher_hu"],
c["praemie_fold_vorher_mehrweg"], c["praemie_fold_nachher_mehrweg"],
" ".join("%s:%d" % (kk, v) for kk, v in c.items() if "->" in kk)))
print("GESAMT", json.dumps(out["gesamt"], ensure_ascii=False), out.get("delta_bb_je_100"))
if __name__ == "__main__":
main()