Unsinn-Pruefung: Nachbau von MOTOR_STAPEL_PREIS_VORFLOP (alles-0212m) an den Vorflop-Lagen gegen einen All-in, Richter echter Preis gegen die gemessene Schieb-Reichweite
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,273 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Was korrigiert MOTOR_STAPEL_PREIS_VORFLOP (claude/alles-0212m, vorflop_preis.rs) an den Vorflop-Lagen gegen einen All-in?
|
||||
|
||||
Nachbau der Schicht Teil 1 (lage_gegen_raise, j_zelle mit Rueckfall, Preis mit Rake, stapel_preis::urteil_a) in Python; die Gewinnchance
|
||||
gegen die J-Reichweite per Stichprobe (eval7). Bewertet wird mit den Zugwerten der Unsinn-Pruefung Fassung ii (Gegner-Range = Pool-
|
||||
Schieb-Range): Verlust der Tafel-Mischung vorher, nach dem Hebel (beide moeglichen gezogenen Zuege) und mit der reinen Regel
|
||||
"Call, wenn Gewinnchance > Preis".
|
||||
|
||||
python3 messung/motor/unsinn/stapel_vorflop.py <aus-ii-schieben.jsonl> <lagen-vorflop.jsonl> <meta.jsonl> <einsatzstaerke-v3.txt> --haende N [--dosis 0.5]
|
||||
"""
|
||||
import argparse
|
||||
import collections
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
|
||||
import eval7
|
||||
|
||||
RANG = "23456789TJQKA"
|
||||
FARBE = {"CLUBS": "c", "DIAMONDS": "d", "HEARTS": "h", "SPADES": "s"}
|
||||
RN = {"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"}
|
||||
MIN_N_GEZEIGT, VERTRAUEN_K = 50.0, 100.0
|
||||
MARGE_FOLD_ZU_CALL, MARGE_OHNE_SUCHE, FOLD_SE, MIN_CALL_GEWICHT = 0.06, 0.04, 1.0, 0.30
|
||||
GEBUNDEN_AB = 0.40
|
||||
BAND = [12, 20, 35, 60, 100, 150]
|
||||
|
||||
|
||||
def klasse(k1, k2):
|
||||
"""karten::vorflop fuer Karten wie 'As': Paar/gleichfarbig hoch*13+tief, sonst tief*13+hoch."""
|
||||
a, b = RANG.index(k1[0]), RANG.index(k2[0])
|
||||
h, l = max(a, b), min(a, b)
|
||||
return h * 13 + l if (h == l or k1[1] == k2[1]) else l * 13 + h
|
||||
|
||||
|
||||
def lies_j(pfad):
|
||||
j = {}
|
||||
for z in open(pfad):
|
||||
if z.startswith("J "):
|
||||
f = z.split()
|
||||
j[tuple(int(x) for x in f[1:6])] = (float(f[8]), [float(x) for x in f[9:]])
|
||||
return j
|
||||
|
||||
|
||||
def typ_von(p):
|
||||
n, v = (p or {}).get("hands"), (p or {}).get("vpip")
|
||||
if n is None or v is None or n < 100:
|
||||
return 0
|
||||
return 1 if v < 0.30 else 2 if v <= 0.44 else 3
|
||||
|
||||
|
||||
def lage(q):
|
||||
"""Nachbau von lage_gegen_raise: None mit Grund, wenn nicht genau ein lebender Gegner den letzten Raise gemacht hat."""
|
||||
lebt = [v for v in q.get("villains") or [] if not v.get("folded")]
|
||||
if len(lebt) != 1:
|
||||
return None, f"{len(lebt)} Gegner lebend"
|
||||
g = lebt[0]
|
||||
raises, limps, drin, hoch, sb = [], 0, {}, 0.0, None
|
||||
for h in q.get("history") or []:
|
||||
if h.get("street") != "PREFLOP":
|
||||
continue
|
||||
s, a, x = h.get("seat"), h.get("action"), h.get("amount") or 0.0
|
||||
if a in ("POST_SB", "POST_BB"):
|
||||
sb = s if a == "POST_SB" else sb
|
||||
drin[s] = x
|
||||
hoch = max(hoch, x)
|
||||
elif a == "CALL":
|
||||
limps += not raises
|
||||
drin[s] = max(drin.get(s, 0.0), x)
|
||||
elif a in ("RAISE", "ALL_IN", "BET"):
|
||||
drin[s] = max(drin.get(s, 0.0), x)
|
||||
if x > hoch + 1e-9:
|
||||
raises.append((s, x))
|
||||
hoch = x
|
||||
elif not raises:
|
||||
limps += 1
|
||||
if not raises or raises[-1][0] != g.get("seat"):
|
||||
return None, "letzter Raise nicht vom lebenden Gegner"
|
||||
letzter, to = raises[-1]
|
||||
mein = drin.get(q["heroSeat"], 0.0)
|
||||
sein = max(drin.get(letzter, to), to)
|
||||
eff = min(mein + q["heroStack"], sein + (g.get("stack") or 0.0))
|
||||
sitze = sorted({v["seat"] for v in q["villains"]} | {q["heroSeat"]})
|
||||
pos = 0
|
||||
if sb in sitze and letzter in sitze:
|
||||
n = len(sitze)
|
||||
idx = (sitze.index(letzter) - sitze.index(sb)) % n
|
||||
pos = 1 if idx <= 1 else 2 if (n >= 3 and idx + 2 >= n) else 3
|
||||
bb = q["bigBlind"]
|
||||
stufe = min(len(raises), 4)
|
||||
return {"stufe": stufe, "iso": int(stufe == 1 and limps > 0), "band": next((i + 1 for i, g_ in enumerate(BAND) if eff / bb <= g_), 7),
|
||||
"pos": pos, "typ": typ_von(g.get("profile")), "anteil": to / eff, "allin": (g.get("stack") or 1.0) <= 1e-9 or to >= eff - 1e-9,
|
||||
"zu": q["toCall"], "pot": q["pot"], "bb": bb}, None
|
||||
|
||||
|
||||
def j_zelle(j, l):
|
||||
for ba, po, ty in [(l["band"], l["pos"], l["typ"]), (l["band"], l["pos"], 0), (l["band"], 0, 0), (0, 0, 0)]:
|
||||
z = j.get((l["stufe"], l["iso"], ba, po, ty))
|
||||
if z and z[0] >= MIN_N_GEZEIGT:
|
||||
return z
|
||||
return None
|
||||
|
||||
|
||||
def gewinnchance(hand, w, versuche, rng):
|
||||
eigen = set(hand)
|
||||
deck = [r + f for r in RANG for f in "cdhs"]
|
||||
kombis, gew = [], []
|
||||
for i, x in enumerate(deck):
|
||||
for y in deck[:i]:
|
||||
if x in eigen or y in eigen:
|
||||
continue
|
||||
k = klasse(x, y)
|
||||
g = w[k] / (6 if RANG.index(x[0]) == RANG.index(y[0]) else 4 if x[1] == y[1] else 12)
|
||||
if g > 0:
|
||||
kombis.append((x, y))
|
||||
gew.append(g)
|
||||
ec = [eval7.Card(c) for c in hand]
|
||||
sieg = 0.0
|
||||
for (x, y) in rng.choices(kombis, weights=gew, k=versuche):
|
||||
rest = [c for c in deck if c not in eigen and c != x and c != y]
|
||||
b = [eval7.Card(c) for c in rng.sample(rest, 5)]
|
||||
s1, s2 = eval7.evaluate(ec + b), eval7.evaluate([eval7.Card(x), eval7.Card(y)] + b)
|
||||
sieg += 1.0 if s1 > s2 else 0.5 if s1 == s2 else 0.0
|
||||
return sieg / versuche
|
||||
|
||||
|
||||
def urteil(akt, gem, n, noetig, dosis, call_gewicht):
|
||||
"""stapel_preis::urteil_a ohne Gewinnchance der Suche (vorflop): neuer Zug oder None."""
|
||||
w = max(0.0, min(1.0, dosis)) * n / (n + VERTRAUEN_K)
|
||||
if w <= 0:
|
||||
return None, "Dosis 0"
|
||||
misch = noetig + w * (gem - noetig)
|
||||
se = math.sqrt(gem * (1 - gem) / n)
|
||||
if akt == "CALL":
|
||||
if gem < noetig - FOLD_SE * se and misch < noetig:
|
||||
return "FOLD", None
|
||||
return None, "Gewinnchance nicht klar unter Preis"
|
||||
hurde = MARGE_FOLD_ZU_CALL + MARGE_OHNE_SUCHE
|
||||
if call_gewicht < MIN_CALL_GEWICHT:
|
||||
return None, f"Tafel callt nur {call_gewicht:.0%} (< 30 %)"
|
||||
if gem > noetig + hurde and misch > noetig + hurde:
|
||||
return "CALL", None
|
||||
return None, f"Huerde: Rand {gem - noetig:+.2f}, gedaempft {w * (gem - noetig):+.2f} < {hurde:.2f}"
|
||||
|
||||
|
||||
def main():
|
||||
a = argparse.ArgumentParser()
|
||||
a.add_argument("aus")
|
||||
a.add_argument("lagen")
|
||||
a.add_argument("meta")
|
||||
a.add_argument("tafel")
|
||||
a.add_argument("--haende", type=int, required=True)
|
||||
a.add_argument("--dosis", type=float, default=0.5)
|
||||
a.add_argument("--versuche", type=int, default=8000)
|
||||
o = a.parse_args()
|
||||
erg = {}
|
||||
for l in open(o.aus):
|
||||
e = json.loads(l)
|
||||
if "q" in e:
|
||||
erg[e["id"]] = e
|
||||
qs = {}
|
||||
for l in open(o.lagen):
|
||||
d = json.loads(l)
|
||||
if d["id"] in erg:
|
||||
qs[d["id"]] = d["q"]
|
||||
mt = {}
|
||||
for l in open(o.meta):
|
||||
d = json.loads(l)
|
||||
if d["id"] in erg:
|
||||
mt[d["id"]] = d
|
||||
j = lies_j(o.tafel)
|
||||
rng = random.Random(7)
|
||||
summe = collections.Counter()
|
||||
gruende = collections.defaultdict(lambda: [0, 0.0])
|
||||
zeilen = []
|
||||
rake_kappe = {"sechs": 10.0, "hu": 2.5}
|
||||
for k, e in erg.items():
|
||||
q, m = qs[k], mt[k]
|
||||
hand = [RN[c["rank"]] + FARBE[c["suit"]] for c in q["heroCards"]]
|
||||
z = e["zuege"]
|
||||
if z[:2] != ["fold", "call"]:
|
||||
continue
|
||||
mix, qw = e["mix"], e["q"]
|
||||
best = max(qw[:2])
|
||||
v0 = mix[0] * (best - qw[0]) + mix[1] * (best - qw[1]) + sum(mix[i] * (best - qw[i]) for i in range(2, len(qw)))
|
||||
l, warum = lage(q)
|
||||
p_call_neu = mix[1]
|
||||
eq = noetig = None
|
||||
gr_f = gr_c = None
|
||||
echt = None
|
||||
if l is None:
|
||||
gr = "nicht abgedeckt: " + warum
|
||||
elif not (l["allin"] or l["anteil"] > GEBUNDEN_AB):
|
||||
gr = f"Schwelle: bindet {l['anteil']:.0%} < 40 %"
|
||||
else:
|
||||
zl = j_zelle(j, l)
|
||||
if zl is None:
|
||||
gr = "keine J-Zelle mit >= 50 gezeigten"
|
||||
else:
|
||||
eq = gewinnchance(hand, zl[1], o.versuche, rng)
|
||||
endtopf = l["pot"] + l["zu"]
|
||||
abzug = min(endtopf * 0.05, rake_kappe[e.get("tafel", "sechs")] * l["bb"])
|
||||
noetig = l["zu"] / max(endtopf - abzug, 1e-9)
|
||||
neu_f, gr_f = urteil("FOLD", eq, zl[0], noetig, o.dosis, mix[1])
|
||||
neu_c, gr_c = urteil("CALL", eq, zl[0], noetig, o.dosis, mix[1])
|
||||
p_call_neu = mix[1] * (neu_c != "FOLD") + mix[0] * (neu_f == "CALL")
|
||||
gr = "ok"
|
||||
# Richter mit echtem Preis: EV des Calls in bb gegen die gemessene Reichweite (Fold = 0); Unsicherheit aus n gezeigt
|
||||
ev = (eq * (endtopf - abzug) - l["zu"]) / l["bb"]
|
||||
se_ev = math.sqrt(eq * (1 - eq) / zl[0]) * (endtopf - abzug) / l["bb"]
|
||||
fc = mix[0] + mix[1]
|
||||
echt = {"ev": ev, "se": se_ev, "tafel": mix[0] * max(ev, 0) + mix[1] * max(-ev, 0),
|
||||
"hebel": (fc - p_call_neu) * max(ev, 0) + p_call_neu * max(-ev, 0), "n": zl[0]}
|
||||
# Verlust nach dem Hebel (nur fold/call umverteilt; uebrige Zuege bleiben)
|
||||
rest = sum(mix[2:])
|
||||
mix_neu = [1 - rest - p_call_neu, p_call_neu] + mix[2:]
|
||||
v1 = sum(mix_neu[i] * (best - qw[i]) for i in range(len(qw)))
|
||||
# reine Regel (nur wo der Hebel greifen kann): Call genau dann, wenn die Gewinnchance gegen die J-Reichweite ueber dem Preis liegt;
|
||||
# sonst bleibt die Tafel-Mischung. Bewertet mit den Zugwerten der Fassung ii.
|
||||
if eq is not None:
|
||||
j_rein = 1 if eq > noetig else 0
|
||||
v2 = sum(mix[i] * (best - qw[i]) for i in range(2, len(qw))) + (1 - rest) * (best - qw[j_rein])
|
||||
else:
|
||||
v2 = v0
|
||||
summe["vorher"] += v0
|
||||
if l and l["allin"]:
|
||||
summe["vorher_allin"] += v0
|
||||
summe["hebel_allin"] += v1
|
||||
summe["rein_allin"] += v2
|
||||
summe["hebel"] += v1
|
||||
summe["rein"] += v2
|
||||
richtig = "call" if qw[1] > qw[0] else "fold"
|
||||
if echt is not None:
|
||||
richtig = "call" if echt["ev"] > 0 else "fold"
|
||||
summe["e_n"] += 1
|
||||
summe["e_tafel"] += echt["tafel"]
|
||||
summe["e_hebel"] += echt["hebel"]
|
||||
summe["e_unsicher"] += abs(echt["ev"]) < echt["se"]
|
||||
if gr == "ok":
|
||||
if richtig == "call":
|
||||
gr = "korrigiert" if mix[0] > 0 and gr_f is None else ("nichts zu tun" if mix[0] < 1e-9 else gr_f)
|
||||
else:
|
||||
gr = "korrigiert" if mix[1] > 0 and gr_c is None else ("nichts zu tun" if mix[1] < 1e-9 else gr_c)
|
||||
if e["zeile"] != "gelernt":
|
||||
gr += " (gleichverteilte Zeile)"
|
||||
art_echt = "real all-in" if (l and l["allin"]) else ("real kein All-in" if l else "-")
|
||||
if l and not l["allin"]:
|
||||
gr += f" [real {l['anteil']:.0%} des Stacks, im Baum all-in]"
|
||||
key = (richtig, gr.split(":")[0].split(" [")[0], art_echt)
|
||||
gruende[key][0] += 1
|
||||
gruende[key][1] += v0 - v1
|
||||
zeilen.append((echt["tafel"] if echt else v0, "".join(hand), m["n"], richtig, mix[:2], qw[:2], eq, noetig, gr + (f"; EV Call echt {echt['ev']:+.1f} +-{echt['se']:.1f} bb, nach Hebel Verlust {echt['hebel']:.1f}" if echt else ""), v1))
|
||||
h = o.haende / 100
|
||||
print(f"{len(zeilen)} Lagen fold/call gegen All-in. Verlust gegen den Pool: vorher {summe['vorher']:.1f} bb = {summe['vorher'] / h:.3f} bb/100, "
|
||||
f"nach dem Hebel (Dosis {o.dosis}) {summe['hebel']:.1f} bb = {summe['hebel'] / h:.3f}, reine Regel (Call wenn Gewinnchance > Preis, wo der Hebel greift) "
|
||||
f"{summe['rein']:.1f} bb = {summe['rein'] / h:.3f}")
|
||||
print(f"Richter echter Preis gegen die gemessene Reichweite (nur wo der Hebel greift: zu zweit, bindet >= 40 %, Zelle vorhanden): "
|
||||
f"{summe['e_n']} Lagen, Verlust der Tafel {summe['e_tafel']:.1f} bb = {summe['e_tafel'] / h:.3f} bb/100, nach dem Hebel {summe['e_hebel']:.1f} bb = "
|
||||
f"{summe['e_hebel'] / h:.3f}, reine Regel 0 (Definition); davon |EV| unter einem Standardfehler: {summe['e_unsicher']}")
|
||||
print(f"Davon real all-in (Werte der Fassung ii dort sauber): vorher {summe['vorher_allin']:.1f} bb, Hebel {summe['hebel_allin']:.1f}, reine Regel {summe['rein_allin']:.1f}")
|
||||
print("\nWarum (richtiger Zug, Grund): Lagen, vom Hebel geholter Wert in bb")
|
||||
for k, (n, v) in sorted(gruende.items(), key=lambda x: -x[1][0]):
|
||||
print(f" {k[0]:5s} {k[1]:45s} {k[2]:17s} n {n:4d} geholt {v:+7.1f}")
|
||||
print("\nGroesste Einzelfaelle (Verlust vorher):")
|
||||
for z in sorted(zeilen, reverse=True)[:25]:
|
||||
v0, hand, n, richtig, mix, qw, eq, noetig, gr, v1 = z
|
||||
eqs = f"eq {eq:.0%} Preis {noetig:.0%}" if eq is not None else "-"
|
||||
print(f" {hand} {n}-weg richtig {richtig}: Tafel fold {mix[0]:.0%} call {mix[1]:.0%}, Werte {qw[0]:+.1f}/{qw[1]:+.1f}; {eqs}; "
|
||||
f"Verlust {v0:.1f} -> {v1:.1f}; {gr}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user