Files
pokerfreak/messung/motor/stackoff_preis/scan.py
T
mmintelandClaude Opus 5.5 1f4e1dfcee Motor: Stack-off v2 (Call nur bei All-in danach, Vorgeschichte K/D, nach VERTRAUEN, bis 3 Gegner)
Livelauf v1 30.11.: AsKc Turn-Call gegen All-in-Range bei 41 bb Rest war falsch.
Aus-Pruefung gegen eec96654: 600/600 gleich; an: 39/4968 Nachflop-Entscheidungen auf 30.11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:22:41 +01:00

171 lines
6.2 KiB
Python

#!/usr/bin/env python3
"""Stack-off-Spots aus den NL2-Haenden (hhDealer, ein Jahr 6-max): jede Nachflop-Aggression zu zweit, mit Antwort und gezeigten Karten.
Je Einsatz/Raise von X gegen Y (genau zwei Spieler zu Beginn der Strasse und beim Zug):
s Strasse 1 Flop, 2 Turn, 3 River
lvl Zahl der Einsaetze vor diesem auf der Strasse (0 Einsatz, 1 Raise, 2 Re-Raise ...)
g Nachlegen von X / Topf vor dem Zug
spr effektiver Rest nach Zug und Call / Topf danach (0 = all-in)
vspr effektiver Rest vor dem Zug / Topf davor
resp Antwort von Y: f / c / r
xh yh gezeigte Karten (falls gezeigt), b Brett dieser Strasse
xr yr 1, wenn X bzw. Y auf einer frueheren Nachflop-Strasse geraist hat (Einsatz ueber einen Einsatz), sonst 0
Eigene Hand-Ids und Haende ab dem 17.11. fliegen raus. Ausgabe je Teil eine JSONL-Datei ausserhalb des Repos (Hand-Ebene).
python -I -X utf8 scan.py <aussen.zip> <eigene_ids.txt> <ausordner> [--prozesse 16]
"""
import calendar
import io
import json
import multiprocessing as mp
import os
import re
import sys
import zipfile
_HIER = os.path.dirname(os.path.abspath(__file__))
_BAUM = os.path.dirname(os.path.dirname(os.path.dirname(_HIER)))
sys.path.insert(0, os.path.join(_BAUM, "lesen", "gegnernetz"))
sys.path.insert(0, os.path.join(_BAUM, "lesen"))
import hhd # noqa: E402
STICHTAG = calendar.timegm((2026, 11, 17, 0, 0, 0, 0, 0, 0))
def _bremse():
try:
import ctypes
k = ctypes.windll.kernel32
k.GetCurrentProcess.restype = ctypes.c_void_p
k.SetPriorityClass.argtypes = [ctypes.c_void_p, ctypes.c_uint]
k.SetPriorityClass(k.GetCurrentProcess(), 0x4000)
except Exception:
pass
def spots(h):
n = len(h["stacks"])
stacks = h["stacks"]
inv = list(h["blinds"])
sc = list(h["blinds"])
lebt = set(range(n))
tot = h["ante"]
s_alt = 0
start = set(lebt)
lvl = 0
raiser = set() # auf frueheren Nachflop-Strassen geraist
neu = set()
akt = h["akt"]
aus = []
for i, (s, p, art, ziel) in enumerate(akt):
if s != s_alt:
sc = [0.0] * n
s_alt = s
raiser |= neu
neu = set()
start = set(lebt)
lvl = 0
topf = tot + sum(inv)
if art == "f":
lebt.discard(p)
continue
if art == "c":
amt = min(max(sc) - sc[p], stacks[p] - inv[p])
sc[p] += amt
inv[p] += amt
continue
add = ziel - sc[p]
if s >= 1 and len(start) == 2 and len(lebt) == 2 and add > 0:
y = next(q for q in lebt if q != p)
rx = stacks[p] - inv[p] - add
ry = stacks[y] - inv[y]
ycall = min(ziel - sc[y], ry)
nach = topf + add + ycall
eff = max(0.0, min(rx, ry - ycall))
vor = min(stacks[p] - inv[p], ry) / topf if topf > 0 else 0
resp = None
for s2, p2, a2, _ in akt[i + 1:]:
if s2 != s:
break
if p2 == y:
resp = a2
break
if resp is None and ry <= 1e-9:
resp = "x" # Y schon all-in
aus.append({"s": s, "lvl": lvl, "g": round(add / topf, 3) if topf > 0 else 0, "spr": round(eff / nach, 3),
"vspr": round(vor, 3), "resp": resp, "xh": h["gezeigt"].get(p), "yh": h["gezeigt"].get(y),
"b": "".join(h["board"][:s + 2]), "bb": h["bb"], "xr": int(p in raiser), "yr": int(y in raiser)})
sc[p] = ziel
inv[p] += add
if s >= 1 and lvl >= 1:
neu.add(p)
lvl += 1
return aus
def teil(args):
aussen, namen, eigene_pfad, ziel = args
_bremse()
eigene = set(open(eigene_pfad, encoding="utf-8").read().split())
za = zipfile.ZipFile(aussen)
st = {"haende": 0, "unlesbar": 0, "eigene": 0, "stichtag": 0, "spots": 0}
tmp = ziel + ".tmp"
with open(tmp, "w", encoding="utf-8") as f:
for name in namen:
innen = zipfile.ZipFile(io.BytesIO(za.read(name)))
for info in innen.infolist():
text = innen.read(info).decode("utf-8", "replace")
for blk in re.split(r"\n\s*\n\s*\n", text):
zeilen = [z.rstrip("\r") for z in blk.strip().splitlines()]
if not zeilen or not zeilen[0].startswith("CoinPoker Hand #"):
continue
try:
r = hhd.hand_lesen(zeilen)
except (ValueError, IndexError, KeyError):
r = None
if not r:
st["unlesbar"] += 1
continue
h = r[0]
if str(h["nr"]) in eigene:
st["eigene"] += 1
continue
if h["zeit"] >= STICHTAG:
st["stichtag"] += 1
continue
st["haende"] += 1
if h["strassen"] == 0:
continue
try:
for x in spots(h):
f.write(json.dumps(x, separators=(",", ":")) + "\n")
st["spots"] += 1
except (StopIteration, IndexError):
st["unlesbar"] += 1
os.replace(tmp, ziel)
return st
def main():
aussen, eigene, aus = sys.argv[1:4]
prozesse = int(sys.argv[sys.argv.index("--prozesse") + 1]) if "--prozesse" in sys.argv else 16
os.makedirs(aus, exist_ok=True)
namen = sorted(zipfile.ZipFile(aussen).namelist())
jobs = []
for k in range(0, len(namen), 4):
ziel = os.path.join(aus, f"teil-{k // 4:03d}.jsonl")
if os.path.exists(ziel):
continue # fertig, nie neu schreiben
jobs.append((aussen, namen[k:k + 4], eigene, ziel))
summe = {}
with mp.Pool(prozesse) as pool:
for st in pool.imap_unordered(teil, jobs):
for k, v in st.items():
summe[k] = summe.get(k, 0) + v
print(json.dumps(summe), flush=True)
print("fertig", json.dumps(summe))
if __name__ == "__main__":
main()