Tabellen statt Netze: je Knoten (Strasse, Topf, Vorflop-Aggressor, Position, Linie mit Groessenklassen, Textur, 12 Spielertypen) Range ueber Brett-Perzentil-Faecher, Aktionen, Strategie je Zelle und Fold-Range als Rest; Muck per IPW, hierarchische Glaettung. Holdout versiegelter Spieler: kalibriert, besser als BETTOR (River jede Groesse) und VORFLOP_BAND. Loader exploit::ranges_echt hinter RANGES_ECHT (aus). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
380 lines
14 KiB
Python
380 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""ranges_echt, Schritt 1: aus den gekauften CoinPoker-NL2-Haenden (hhDealer, 6-max, 09/2025-16.11.2026) je Tag
|
|
|
|
- Zaehler je Spieler (Hash): Haende, VPIP, PFR, Flop gesehen, Postflop Einsatz/Raise, Call, Fold, Check,
|
|
- jede Hand, die heads-up den Flop sieht, als kompakter Datensatz ohne Namen (Spieler als 64-Bit-Hash wie
|
|
`lesen/gegnernetz/daten.kennung`, Siegel-Bit wie `holdout.gegner_versiegelt`).
|
|
|
|
Ausgeschlossen: Haende mit Ante (andere Tische), eigene Hand-Ids (`eigene_ids.txt` aus daten-hhd), ab Stichtag 17.11.
|
|
|
|
Datensatz (eine JSON-Zeile je Hand), Index 0 = ausser Position (OOP), 1 = in Position (IP):
|
|
nr, t (Unix-Zeit), n (Spieler am Tisch), pid [2], sg [2] (versiegelt), pos [2] (SB BB UTG HJ CO BTN),
|
|
vr (Raises vorflop 0..), pfa (0/1 Vorflop-Aggressor, -1 Limp-Topf), pot (Topf am Flop in bb, mit Antes/Totgeld),
|
|
stk [2] (Rest-Stack am Flop in bb), b (Brett, so weit gesehen), a [[strasse 1-3, wer, art, ziel, topf, allin]]
|
|
art: x Check, b Einsatz, c Call, r Raise, f Fold; ziel = Beitrag auf der Strasse danach (bb),
|
|
topf = Topf vor der Aktion (bb, inkl. Beitraege der Strasse),
|
|
h [2] (gezeigte Karten oder ""), m [2] (gemuckt), w [2] (hat etwas gewonnen), sd (Showdown erreicht).
|
|
|
|
python -I -X utf8 messung/ranges_echt/extrakt.py <aussen.zip> <eigene_ids.txt> <aus> [--prozesse 2] [--nur k]
|
|
"""
|
|
import calendar
|
|
import gzip
|
|
import hashlib
|
|
import io
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
import zipfile
|
|
|
|
STICHTAG = calendar.timegm((2026, 11, 17, 0, 0, 0, 0, 0, 0))
|
|
B = r"₮([\d.,]+)"
|
|
RE_KOPF = re.compile(r"^CoinPoker Hand #(\d+): .*?\(₮([\d.]+)/₮([\d.]+).*?\) - (\d{4})/(\d{2})/(\d{2}) (\d{2}):(\d{2}):(\d{2})")
|
|
RE_KNOPF = re.compile(r"Seat #(\d+) is the button")
|
|
RE_SITZ = re.compile(r"^Seat (\d+): (.+) \(" + B + r" in chips")
|
|
RE_AKT = re.compile(r"^(.+?): (posts the ante|posts small blind|posts big blind|posts|calls|bets|raises|checks|folds)"
|
|
r"(?: " + B + r")?(?: to " + B + r")?( and is all-in)?")
|
|
RE_ZEIGT = re.compile(r"^(.+?): shows \[(\w\w) (\w\w)\]")
|
|
RE_MUCK = re.compile(r"^(.+?): mucks hand")
|
|
RE_SAMMELT = re.compile(r"^(.+?) collected " + B)
|
|
RE_ZURUECK = re.compile(r"^Uncalled bet \(" + B + r"\) returned to (.+)$")
|
|
RE_BRETT = re.compile(r"\[([^\]]*)\]")
|
|
POS6 = ("BTN", "CO", "HJ", "UTG", "EP", "EP", "EP", "EP")
|
|
NZ = 8 # Zaehler: haende vpip pfr flop aggr call fold check
|
|
|
|
|
|
def idle():
|
|
"""Prozess auf Idle (64-bit-sicher, s. side-session-notes idle-ctypes-fehler.md)."""
|
|
if os.name == "nt":
|
|
import ctypes
|
|
k = ctypes.windll.kernel32
|
|
k.GetCurrentProcess.restype = ctypes.c_void_p
|
|
k.SetPriorityClass.argtypes = [ctypes.c_void_p, ctypes.c_uint32]
|
|
k.SetPriorityClass(k.GetCurrentProcess(), 0x40)
|
|
|
|
|
|
def kennung(name):
|
|
return int.from_bytes(hashlib.blake2b(("CP|%s" % name).encode("utf-8"), digest_size=8).digest(), "little",
|
|
signed=True)
|
|
|
|
|
|
def versiegelt(name):
|
|
h = int.from_bytes(hashlib.blake2b(("CP|%s" % name).encode("utf-8"), digest_size=8).digest(), "little")
|
|
return h % 10 < 3
|
|
|
|
|
|
def zahl(s):
|
|
return float(s.replace(",", "")) if s else 0.0
|
|
|
|
|
|
def positionen(n):
|
|
if n == 2:
|
|
return ["SB", "BB"]
|
|
rest = [POS6[k] for k in range(n - 2)][::-1]
|
|
return ["SB", "BB"] + rest
|
|
|
|
|
|
def hand_lesen(zeilen, zaehler):
|
|
"""Zaehler fortschreiben; -> Datensatz (dict) fuer Heads-up-Flops, sonst None. Wirft bei Unlesbarem."""
|
|
m = RE_KOPF.match(zeilen[0])
|
|
if not m:
|
|
raise ValueError("kopf")
|
|
nr = int(m.group(1))
|
|
bb = float(m.group(3))
|
|
j, mo, t, hh, mi, se = (int(m.group(i)) for i in range(4, 10))
|
|
zeit = calendar.timegm((j, mo, t, hh, mi, se, 0, 0, 0))
|
|
knopf = None
|
|
sitze = {}
|
|
i = 1
|
|
for i in range(1, len(zeilen)):
|
|
z = zeilen[i]
|
|
if knopf is None:
|
|
mk = RE_KNOPF.search(z)
|
|
if mk:
|
|
knopf = int(mk.group(1))
|
|
continue
|
|
ms = RE_SITZ.match(z)
|
|
if ms:
|
|
sitze[ms.group(2)] = (int(ms.group(1)), zahl(ms.group(3)))
|
|
elif z.startswith("*** HOLE CARDS"):
|
|
break
|
|
if len(sitze) < 2 or knopf is None:
|
|
raise ValueError("sitze")
|
|
sb = bbn = None
|
|
ante = 0.0
|
|
for z in zeilen[1:i]:
|
|
a = RE_AKT.match(z)
|
|
if not a or a.group(1) not in sitze:
|
|
continue
|
|
if a.group(2) == "posts the ante":
|
|
ante += zahl(a.group(3))
|
|
elif a.group(2) == "posts small blind" and sb is None:
|
|
sb = a.group(1)
|
|
elif a.group(2) == "posts big blind" and bbn is None:
|
|
bbn = a.group(1)
|
|
if ante > 0:
|
|
return "ante"
|
|
if bbn is None:
|
|
raise ValueError("bb")
|
|
nach = sorted(sitze, key=lambda nm: (sitze[nm][0] - knopf - 1) % 10)
|
|
if sb is not None and nach[0] != sb:
|
|
nach = nach[nach.index(sb):] + nach[:nach.index(sb)]
|
|
if sb is None:
|
|
nach = nach[nach.index(bbn):] + nach[:nach.index(bbn)]
|
|
n = len(nach)
|
|
pos = {nm: k for k, nm in enumerate(nach)}
|
|
stack = [sitze[nm][1] for nm in nach]
|
|
posname = positionen(n)
|
|
# Zustand
|
|
s = 0
|
|
beitrag = [0.0] * n # auf der laufenden Strasse
|
|
gesamt = [0.0] * n # in der Hand
|
|
totgeld = 0.0
|
|
aktiv = [True] * n
|
|
vpip = [False] * n
|
|
pfr = [False] * n
|
|
nf = [[0, 0, 0, 0] for _ in range(n)] # aggr call fold check postflop
|
|
raises_vf = 0
|
|
letzter_raiser = None
|
|
flop_spieler = None
|
|
brett = []
|
|
akt = [] # postflop: (strasse, p, art, ziel, topf_vor, allin)
|
|
hoch = 0.0 # hoechster Beitrag auf der Strasse
|
|
gez, muck, sieger = {}, set(), set()
|
|
sd = False
|
|
topf_flop = 0.0
|
|
stk_flop = None
|
|
for z in zeilen[1:]:
|
|
if z.startswith("*** "):
|
|
if z.startswith("*** FLOP"):
|
|
s = 1
|
|
brett = RE_BRETT.findall(z)[0].split()
|
|
elif z.startswith("*** TURN"):
|
|
s = 2
|
|
brett = brett[:3] + RE_BRETT.findall(z)[-1].split()
|
|
elif z.startswith("*** RIVER"):
|
|
s = 3
|
|
brett = brett[:4] + RE_BRETT.findall(z)[-1].split()
|
|
elif z.startswith("*** SHOW"):
|
|
sd = True
|
|
continue
|
|
elif z.startswith("*** SUMMARY"):
|
|
break
|
|
else:
|
|
continue
|
|
if s == 1:
|
|
flop_spieler = [p for p in range(n) if aktiv[p]]
|
|
topf_flop = (sum(gesamt) + totgeld + ante) / bb
|
|
stk_flop = [(stack[p] - gesamt[p]) / bb for p in range(n)]
|
|
beitrag = [0.0] * n
|
|
hoch = 0.0
|
|
continue
|
|
mz = RE_ZEIGT.match(z)
|
|
if mz and mz.group(1) in pos:
|
|
gez[pos[mz.group(1)]] = mz.group(2) + mz.group(3)
|
|
continue
|
|
mm = RE_MUCK.match(z)
|
|
if mm and mm.group(1) in pos:
|
|
muck.add(pos[mm.group(1)])
|
|
continue
|
|
mc = RE_SAMMELT.match(z)
|
|
if mc and mc.group(1) in pos:
|
|
sieger.add(pos[mc.group(1)])
|
|
continue
|
|
mr = RE_ZURUECK.match(z)
|
|
if mr and mr.group(2) in pos:
|
|
p = pos[mr.group(2)]
|
|
x = zahl(mr.group(1))
|
|
beitrag[p] -= x
|
|
gesamt[p] -= x
|
|
continue
|
|
a = RE_AKT.match(z)
|
|
if not a or a.group(1) not in pos:
|
|
continue
|
|
p = pos[a.group(1)]
|
|
was = a.group(2)
|
|
allin = a.group(5) is not None
|
|
if was == "posts the ante":
|
|
continue
|
|
if was in ("posts small blind", "posts big blind"):
|
|
x = zahl(a.group(3))
|
|
beitrag[p] += x
|
|
gesamt[p] += x
|
|
hoch = max(hoch, beitrag[p])
|
|
continue
|
|
if was == "posts": # Nachzahler: Totgeld (SB-Anteil) oder BB
|
|
x = zahl(a.group(3))
|
|
if x >= bb - 1e-9:
|
|
beitrag[p] += bb
|
|
gesamt[p] += bb
|
|
totgeld += x - bb
|
|
hoch = max(hoch, beitrag[p])
|
|
else:
|
|
totgeld += x
|
|
continue
|
|
topf_vor = (sum(gesamt) + totgeld + ante) / bb
|
|
if was == "folds":
|
|
aktiv[p] = False
|
|
art, ziel = "f", beitrag[p]
|
|
if s > 0:
|
|
nf[p][2] += 1
|
|
elif was == "checks":
|
|
art, ziel = "x", beitrag[p]
|
|
if s > 0:
|
|
nf[p][3] += 1
|
|
elif was == "calls":
|
|
x = zahl(a.group(3))
|
|
beitrag[p] += x
|
|
gesamt[p] += x
|
|
art, ziel = "c", beitrag[p]
|
|
if s == 0:
|
|
vpip[p] = True
|
|
else:
|
|
nf[p][1] += 1
|
|
elif was == "bets":
|
|
x = zahl(a.group(3))
|
|
beitrag[p] += x
|
|
gesamt[p] += x
|
|
hoch = max(hoch, beitrag[p])
|
|
art, ziel = "b", beitrag[p]
|
|
if s > 0:
|
|
nf[p][0] += 1
|
|
else: # raises
|
|
ziel_abs = zahl(a.group(4))
|
|
x = ziel_abs - beitrag[p]
|
|
beitrag[p] = ziel_abs
|
|
gesamt[p] += x
|
|
hoch = max(hoch, beitrag[p])
|
|
art, ziel = "r", beitrag[p]
|
|
if s == 0:
|
|
vpip[p] = True
|
|
pfr[p] = True
|
|
raises_vf += 1
|
|
letzter_raiser = p
|
|
else:
|
|
nf[p][0] += 1
|
|
if s > 0:
|
|
akt.append((s, p, art, round(ziel / bb, 3), round(topf_vor, 3), allin))
|
|
# Zaehler
|
|
for p, nm in enumerate(nach):
|
|
k = kennung(nm)
|
|
c = zaehler.get(k)
|
|
if c is None:
|
|
c = zaehler[k] = [0] * NZ
|
|
c[0] += 1
|
|
c[1] += vpip[p]
|
|
c[2] += pfr[p]
|
|
if flop_spieler is not None and p in flop_spieler:
|
|
c[3] += 1
|
|
c[4] += nf[p][0]
|
|
c[5] += nf[p][1]
|
|
c[6] += nf[p][2]
|
|
c[7] += nf[p][3]
|
|
if flop_spieler is None or len(flop_spieler) != 2:
|
|
return None
|
|
if len(brett) != (0, 3, 4, 5)[s]:
|
|
raise ValueError("brett")
|
|
a0, a1 = flop_spieler
|
|
# Wer handelt nach dem Flop zuerst? Reihenfolge ab SB; heads-up am Tisch (n=2) handelt der BB zuerst.
|
|
oop, ip = (a1, a0) if n == 2 else (a0, a1)
|
|
wer = {oop: 0, ip: 1}
|
|
rec = {
|
|
"nr": nr, "t": zeit, "n": n,
|
|
"pid": [kennung(nach[oop]), kennung(nach[ip])],
|
|
"sg": [int(versiegelt(nach[oop])), int(versiegelt(nach[ip]))],
|
|
"pos": [posname[oop], posname[ip]],
|
|
"vr": raises_vf,
|
|
"pfa": wer.get(letzter_raiser, -1) if raises_vf else -1,
|
|
"pot": round(topf_flop, 3),
|
|
"stk": [round(stk_flop[oop], 3), round(stk_flop[ip], 3)],
|
|
"b": "".join(brett),
|
|
"a": [[st, wer[p], art, ziel, tv, int(al)] for st, p, art, ziel, tv, al in akt if p in wer],
|
|
"h": [gez.get(oop, ""), gez.get(ip, "")],
|
|
"m": [int(oop in muck), int(ip in muck)],
|
|
"w": [int(oop in sieger), int(ip in sieger)],
|
|
"sd": int(sd),
|
|
}
|
|
return rec
|
|
|
|
|
|
def _tag(args):
|
|
aussen, name, eigene_pfad, aus = args
|
|
idle()
|
|
ziel = os.path.join(aus, "tage", name.replace(".zip", ""))
|
|
if os.path.exists(ziel + ".fertig"):
|
|
return name, None
|
|
eigene = set(open(eigene_pfad, encoding="utf-8").read().split())
|
|
za = zipfile.ZipFile(aussen)
|
|
innen = zipfile.ZipFile(io.BytesIO(za.read(name)))
|
|
zaehler = {}
|
|
st = {"haende": 0, "unlesbar": 0, "ante": 0, "eigene_id": 0, "ab_stichtag": 0, "hu_flop": 0, "doppelt": 0}
|
|
gesehen = set()
|
|
with gzip.open(ziel + ".jsonl.gz", "wt", encoding="utf-8", compresslevel=3) as f:
|
|
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):
|
|
blk = blk.strip()
|
|
if not blk.startswith("CoinPoker Hand #"):
|
|
continue
|
|
zeilen = [z.rstrip("\r") for z in blk.splitlines()]
|
|
mk = RE_KOPF.match(zeilen[0])
|
|
if not mk:
|
|
st["unlesbar"] += 1
|
|
continue
|
|
nr = mk.group(1)
|
|
if nr in gesehen:
|
|
st["doppelt"] += 1
|
|
continue
|
|
gesehen.add(nr)
|
|
if nr in eigene:
|
|
st["eigene_id"] += 1
|
|
continue
|
|
try:
|
|
r = hand_lesen(zeilen, zaehler)
|
|
except (ValueError, IndexError, KeyError):
|
|
st["unlesbar"] += 1
|
|
continue
|
|
if r == "ante":
|
|
st["ante"] += 1
|
|
continue
|
|
st["haende"] += 1
|
|
if r is None:
|
|
continue
|
|
if r["t"] >= STICHTAG:
|
|
st["ab_stichtag"] += 1
|
|
continue
|
|
st["hu_flop"] += 1
|
|
f.write(json.dumps(r, separators=(",", ":")) + "\n")
|
|
import numpy as np
|
|
ks = np.fromiter(zaehler.keys(), dtype=np.int64, count=len(zaehler))
|
|
vs = np.asarray(list(zaehler.values()), dtype=np.int32).reshape(-1, NZ)
|
|
np.savez(ziel + ".zaehler.npz", pid=ks, z=vs)
|
|
json.dump(st, open(ziel + ".fertig", "w", encoding="utf-8"))
|
|
return name, st
|
|
|
|
|
|
def main(aussen, eigene, aus, prozesse, nur):
|
|
import multiprocessing as mp
|
|
os.makedirs(os.path.join(aus, "tage"), exist_ok=True)
|
|
namen = sorted(i.filename for i in zipfile.ZipFile(aussen).infolist())
|
|
if nur:
|
|
namen = namen[:nur]
|
|
idle()
|
|
gesamt = {}
|
|
jobs = [(aussen, nm, eigene, aus) for nm in namen]
|
|
with mp.Pool(prozesse, initializer=idle) as pool:
|
|
for k, (nm, st) in enumerate(pool.imap_unordered(_tag, jobs)):
|
|
if st:
|
|
for a, b in st.items():
|
|
gesamt[a] = gesamt.get(a, 0) + b
|
|
if k % 10 == 0:
|
|
print("%d/%d %s %s" % (k + 1, len(namen), nm, gesamt), flush=True)
|
|
print("fertig", gesamt, flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
a = sys.argv[1:]
|
|
pr = int(a[a.index("--prozesse") + 1]) if "--prozesse" in a else 2
|
|
nur = int(a[a.index("--nur") + 1]) if "--nur" in a else 0
|
|
main(a[0], a[1], a[2], pr, nur)
|