11,3 Mio. CoinPoker-NL2-Haende (nur Aggregate), Spieler-Holdout, EV ueber gemessene Fortsetzungen. Schalter (aus = bitgleich, in BEKANNTE_SCHALTER): Blind-3-Bet gegen EP/MP 3x, gegen CO/BTN 4x das Open (bisher 1,5-2,4x: 3 x to_call ohne eigenen Blind), Iso in Position 5 bb + 1 je weiteren Limper (bisher 2,5 bb). VORFLOP_BAND, Iso aus den Blinds, HU unveraendert. Tor: Eigen-Replay 1130 Spots 0 Aktionen anders (nur Groessen), Pflichtfaelle 35/43 wie live, Mehrweg-LBR -16,65 +-32,05 (nicht schlechter), 6-max-Leiter +16,87 +-3,28 ohne schlechtere Position. Nicht live geschaltet. Bericht messung/vorflop_population/BERICHT.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
224 lines
9.1 KiB
Python
224 lines
9.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Vorflop-Knoten der NL2-Population aus den Saetzen von scan.py.
|
|
|
|
Schritt 1 `profile`: je Spieler (pid) Haende, vpip, pfr, 3-Bet-Gelegenheiten/-Treffer ueber das ganze Jahr
|
|
-> <daten>/profile.npz (pid sortiert).
|
|
Schritt 2 `knoten`: je Vorflop-Aktion eine Zeile mit Lage und Ausgang (ein Teil je Tagesarchiv, parallel, Idle)
|
|
-> <daten>/knoten/<teil>.npz.
|
|
|
|
Lage (ctx): 0 ungeoeffnet, 1 gelimpter Topf (keine Erhoehung), 2 gegen ein Open (Akteur noch ohne Einsatz ausser Blind),
|
|
3 Opener gegen 3-Bet, 4 kalt gegen 3-Bet, 5 3-Bettor gegen 4-Bet, 6 Limper gegen Erhoehung, 7 Caller gegen 3-Bet,
|
|
8 sonst.
|
|
Spielertyp (stufe) nach vpip (ab 100 Haenden): 0 <0.18, 1 <0.26, 2 <0.36, 3 <0.50, 4 >=0.50; 5 = unter 100 Haenden.
|
|
Holdout: Spieler mit (pid >> 13) % 10 < 3 sind versiegelt (`vers`), eigene Teilung (nicht die des Gegnernetzes).
|
|
|
|
python -I -X utf8 lesen/vorflop_population/knoten.py profile <daten>
|
|
python -I -X utf8 lesen/vorflop_population/knoten.py knoten <daten> [--prozesse 12]
|
|
"""
|
|
import os
|
|
import sys
|
|
from multiprocessing import Pool
|
|
|
|
import numpy as np
|
|
|
|
STUFEN = (0.18, 0.26, 0.36, 0.50)
|
|
MIN_HAENDE = 100
|
|
|
|
|
|
def _idle():
|
|
try:
|
|
import ctypes
|
|
ctypes.windll.kernel32.SetPriorityClass(ctypes.windll.kernel32.GetCurrentProcess(), 0x40)
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def teile(daten):
|
|
d = os.path.join(daten, "teile")
|
|
return [os.path.join(d, n) for n in sorted(os.listdir(d)) if n.endswith(".npz") and ".tmp" not in n]
|
|
|
|
|
|
def gueltig(t):
|
|
return (t["ok"] == 1) & (t["eigen"] == 0)
|
|
|
|
|
|
def _profil_teil(pfad):
|
|
_idle()
|
|
t = np.load(pfad)
|
|
g = gueltig(t)
|
|
pid = t["pid"][g]
|
|
da = t["da"][g].astype(bool)
|
|
ap, aa = t["a_pos"][g], t["a_art"][g]
|
|
vp = np.zeros_like(da)
|
|
pf = np.zeros_like(da)
|
|
for p in range(6):
|
|
an = ap == p
|
|
vp[:, p] = (an & (aa >= 2)).any(1)
|
|
pf[:, p] = (an & (aa == 3)).any(1)
|
|
p = pid[da]
|
|
u, inv = np.unique(p, return_inverse=True)
|
|
s = np.zeros((len(u), 3), np.int64)
|
|
np.add.at(s, inv, np.stack([np.ones(len(p), np.int64), vp[da], pf[da]], 1))
|
|
return u, s
|
|
|
|
|
|
def profile(daten, prozesse):
|
|
with Pool(prozesse) as pool:
|
|
res = pool.map(_profil_teil, teile(daten))
|
|
p = np.concatenate([r[0] for r in res])
|
|
s = np.concatenate([r[1] for r in res])
|
|
u, inv = np.unique(p, return_inverse=True)
|
|
g = np.zeros((len(u), 3), np.int64)
|
|
np.add.at(g, inv, s)
|
|
np.savez(os.path.join(daten, "profile.npz"), pid=u, haende=g[:, 0], vpip=g[:, 1], pfr=g[:, 2])
|
|
print("spieler", len(u), "haende-sitze", g[:, 0].sum())
|
|
|
|
|
|
def stufe_von(haende, vpip):
|
|
v = vpip / np.maximum(haende, 1)
|
|
st = np.digitize(v, STUFEN).astype(np.int8)
|
|
st[haende < MIN_HAENDE] = 5
|
|
return st
|
|
|
|
|
|
SPALTEN = ("h", "pos", "ctx", "nr", "nlimp", "ncall", "agg", "opener", "face", "prev", "mine", "art", "to", "allin",
|
|
"stack", "eff", "stufe", "vers", "k1", "k2", "flop", "netto", "n", "ante", "hinter", "erste",
|
|
"r_fold", "r_calls", "r_next", "r_npos", "r_nallin", "r_ncall_pos")
|
|
|
|
|
|
def _knoten_teil(args):
|
|
pfad, daten = args
|
|
_idle()
|
|
ziel = os.path.join(daten, "knoten", os.path.basename(pfad))
|
|
if os.path.exists(ziel):
|
|
return 0
|
|
pr = np.load(os.path.join(daten, "profile.npz"))
|
|
ppid, pst = pr["pid"], stufe_von(pr["haende"], pr["vpip"])
|
|
t = np.load(pfad)
|
|
g = np.nonzero(gueltig(t))[0]
|
|
PID = t["pid"]
|
|
idx = np.searchsorted(ppid, PID)
|
|
idx = np.clip(idx, 0, len(ppid) - 1)
|
|
STUFE = np.where(ppid[idx] == PID, pst[idx], 5).astype(np.int8)
|
|
VERS = ((PID >> np.uint64(13)) % np.uint64(10) < np.uint64(3)).astype(np.int8)
|
|
DA, STACK, K1, K2, FLOP, NETTO = t["da"], t["stack"], t["k1"], t["k2"], t["flop"], t["netto"]
|
|
N, ANTE = t["n"], t["ante"]
|
|
AP, AA, AB, AL = t["a_pos"], t["a_art"], t["a_bis"], t["a_allin"]
|
|
zeilen = {k: [] for k in SPALTEN}
|
|
for h in g:
|
|
ap, aa, ab, al = AP[h], AA[h], AB[h], AL[h]
|
|
m = int((ap >= 0).sum())
|
|
beitrag = [0.0] * 6
|
|
beitrag[0], beitrag[1] = 0.5, 1.0
|
|
da = DA[h]
|
|
raus = [not da[p] for p in range(6)]
|
|
gehandelt = [False] * 6
|
|
nr = 0
|
|
nlimp = 0
|
|
ncall = 0
|
|
agg = -1
|
|
opener = -1
|
|
dreier = -1
|
|
hoch = 1.0
|
|
prev = 0.0
|
|
limper = set()
|
|
caller = set()
|
|
stack = STACK[h]
|
|
reihen = [p for p in (2, 3, 4, 5, 0, 1) if da[p]]
|
|
if N[h] == 2:
|
|
reihen = [0, 1]
|
|
for k in range(m):
|
|
p, art, bis, allin = int(ap[k]), int(aa[k]), float(ab[k]), int(al[k])
|
|
if nr == 0:
|
|
ctx = 0 if nlimp == 0 else 1
|
|
elif nr == 1:
|
|
ctx = 6 if p in limper else (2 if p not in caller and p != opener else 8)
|
|
elif nr == 2:
|
|
ctx = 3 if p == opener else (7 if p in caller else 4)
|
|
elif nr == 3:
|
|
ctx = 5 if p == dreier else 8
|
|
else:
|
|
ctx = 8
|
|
leb = [q for q in range(6) if not raus[q] and q != p]
|
|
eff = min(float(stack[p]), max([float(stack[q]) for q in leb], default=0.0))
|
|
# wer handelt nach p noch (nicht gefoldet, nicht p)
|
|
i0 = reihen.index(p) if p in reihen else 0
|
|
hinter = sum(1 for q in reihen[i0 + 1:] if not raus[q])
|
|
zeilen["h"].append(h); zeilen["pos"].append(p); zeilen["ctx"].append(ctx); zeilen["nr"].append(nr)
|
|
zeilen["nlimp"].append(nlimp); zeilen["ncall"].append(ncall); zeilen["agg"].append(agg)
|
|
zeilen["opener"].append(opener); zeilen["face"].append(hoch); zeilen["prev"].append(prev)
|
|
zeilen["mine"].append(beitrag[p]); zeilen["art"].append(art); zeilen["to"].append(bis if art == 3 else 0.0)
|
|
zeilen["allin"].append(allin); zeilen["stack"].append(float(stack[p])); zeilen["eff"].append(eff)
|
|
zeilen["stufe"].append(STUFE[h, p]); zeilen["vers"].append(VERS[h, p]); zeilen["k1"].append(K1[h, p])
|
|
zeilen["k2"].append(K2[h, p]); zeilen["flop"].append(FLOP[h, p]); zeilen["netto"].append(NETTO[h, p])
|
|
zeilen["n"].append(N[h]); zeilen["ante"].append(ANTE[h]); zeilen["hinter"].append(hinter)
|
|
zeilen["erste"].append(0 if gehandelt[p] else 1)
|
|
# Ausgang einer Erhoehung: was folgt bis zur naechsten Erhoehung
|
|
if art == 3:
|
|
calls, nxt, npos, nal, cpos = 0, 0.0, -1, 0, -1
|
|
for j in range(k + 1, m):
|
|
if aa[j] == 3:
|
|
nxt, npos, nal = float(ab[j]), int(ap[j]), int(al[j])
|
|
break
|
|
if aa[j] == 2:
|
|
calls += 1
|
|
if cpos < 0:
|
|
cpos = int(ap[j])
|
|
zeilen["r_fold"].append(1 if (calls == 0 and npos < 0) else 0)
|
|
zeilen["r_calls"].append(calls); zeilen["r_next"].append(nxt); zeilen["r_npos"].append(npos)
|
|
zeilen["r_nallin"].append(nal); zeilen["r_ncall_pos"].append(cpos)
|
|
else:
|
|
zeilen["r_fold"].append(0); zeilen["r_calls"].append(0); zeilen["r_next"].append(0.0)
|
|
zeilen["r_npos"].append(-1); zeilen["r_nallin"].append(0); zeilen["r_ncall_pos"].append(-1)
|
|
# Zustand fortschreiben
|
|
gehandelt[p] = True
|
|
if art == 0:
|
|
raus[p] = True
|
|
elif art == 2:
|
|
beitrag[p] = bis
|
|
if nr == 0:
|
|
nlimp += 1
|
|
limper.add(p)
|
|
else:
|
|
ncall += 1
|
|
caller.add(p)
|
|
elif art == 3:
|
|
beitrag[p] = bis
|
|
prev = hoch
|
|
hoch = bis
|
|
nr += 1
|
|
agg = p
|
|
ncall = 0
|
|
caller = set()
|
|
if nr == 1:
|
|
opener = p
|
|
elif nr == 2:
|
|
dreier = p
|
|
typ = {"h": np.int32, "pos": np.int8, "ctx": np.int8, "nr": np.int8, "nlimp": np.int8, "ncall": np.int8,
|
|
"agg": np.int8, "opener": np.int8, "face": np.float32, "prev": np.float32, "mine": np.float32,
|
|
"art": np.int8, "to": np.float32, "allin": np.int8, "stack": np.float32, "eff": np.float32,
|
|
"stufe": np.int8, "vers": np.int8, "k1": np.int8, "k2": np.int8, "flop": np.int8, "netto": np.float32,
|
|
"n": np.int8, "ante": np.float32, "hinter": np.int8, "erste": np.int8, "r_fold": np.int8,
|
|
"r_calls": np.int8, "r_next": np.float32, "r_npos": np.int8, "r_nallin": np.int8, "r_ncall_pos": np.int8}
|
|
out = {k: np.array(v, typ[k]) for k, v in zeilen.items()}
|
|
out["zeit_h"] = t["zeit"]
|
|
tmp = ziel + ".tmp.npz"
|
|
np.savez_compressed(tmp, **out)
|
|
os.replace(tmp, ziel)
|
|
return len(out["h"])
|
|
|
|
|
|
def knoten(daten, prozesse):
|
|
os.makedirs(os.path.join(daten, "knoten"), exist_ok=True)
|
|
gesamt = 0
|
|
with Pool(prozesse) as pool:
|
|
for m in pool.imap_unordered(_knoten_teil, [(p, daten) for p in teile(daten)]):
|
|
gesamt += m
|
|
print("knoten", gesamt)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
was, daten = sys.argv[1:3]
|
|
prozesse = int(sys.argv[sys.argv.index("--prozesse") + 1]) if "--prozesse" in sys.argv else 12
|
|
{"profile": profile, "knoten": knoten}[was](daten, prozesse)
|