Files
mmintel c3786dba7c Turnier-Engine: ICM-Bubble-Aggression (jam_bonus) + Nash/ICM-Referenz
Open-Jam weitet sich an der Bubble nach dem ICM-Druck des deckenden
Callers (icm/risk.jam_pressure, Gegenstueck zu call_premium). Konvexer
jam_width_factor (1 + 3.4*(p/MAX)^3) - gemessen gegen ICM-Nash: Engine
97/76/66% vs 97/79/65% (vorher 59% payout-blind, +38pp Luecke).

- advise_widened neben unveraendertem advise (null Test-Churn)
- jam_widen nur im Open/ueber-Limp-Zweig, nie FacingAllIn; Cash neutral
- turnier_referenz.py: eingefrorene Equity-Tabelle + Nash/ICM Fictitious
  Play; turnier_benchmark.py: nash_push_score + icm_jam_score
- Kurzstack-Push/Fold-Fix + HeadsUpButton 0.60 Nash-kalibriert
- Micro-only-Schalter (spielplan.mikro_band + Cockpit-Toggle)

Verifiziert: Cash-Benchmark 0.00/0 Deals, nash_push_score unveraendert,
kurzstack_jam+aof 40 gruen, Preflop 9 gruen. 2 rote pipeline_tournament
bei neutralisiertem jam_bonus identisch rot = vorbestehende Call-Raender.
2026-11-08 01:22:57 +01:00

225 lines
9.5 KiB
Python

#!/usr/bin/env python3
"""Nash/ICM-Referenz für den Turnier-Benchmark: die eingefrorene Preflop-Equity-Tabelle der Engine
(`src/cfr/generated_equity.rs`) + ein Nash-Push/Fold-Solver + Harville-ICM - die WAHRHEIT, gegen die
die Engine-Entscheidungen gemessen werden.
Keine neue Pokermathematik: die Equity kommt aus derselben Tabelle wie die Engine (60000 Monte-Carlo-
Runouts je Klassenpaar). Klassen-Schema wie src/cfr/hand_class.rs (id = row*13+col, Two=0..Ace=12,
Diagonale = Paare, row>col = suited, row<col = offsuit).
python3 entscheiden/turnier_referenz.py # Selbsttest: bekannte Equities
"""
import os
import re
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EQUITY_RS = os.path.join(BASE, "src", "cfr", "generated_equity.rs")
RANKS = 13
SYM = "23456789TJQKA" # Index 0..12 -> Two..Ace
def _triangle():
"""Die TRIANGLE-u16-Liste aus generated_equity.rs (14365 Werte, 1/10000)."""
text = open(EQUITY_RS, encoding="utf-8").read()
roh = text.split("TRIANGLE", 1)[1].split("[", 2)[2].split("]", 1)[0]
werte = [int(x) for x in re.findall(r"\d+", roh)]
if len(werte) != RANKS * RANKS * (RANKS * RANKS + 1) // 2:
raise ValueError(f"unerwartete TRIANGLE-Länge {len(werte)}")
return werte
def equity_matrix():
"""Volle 169x169-Equity (float, Equity von i gegen j). Diagonale 0.5, Antisymmetrie."""
tri = _triangle()
n = RANKS * RANKS
m = [[0.5] * n for _ in range(n)]
k = 0
for i in range(n):
for j in range(i, n):
v = tri[k] / 10000.0
k += 1
if i != j:
m[i][j] = v
m[j][i] = 1.0 - v
return m
def klasse(label):
"""Label ("AA","AKs","72o") -> Klassen-id wie hand_class.class_id."""
a, b = SYM.index(label[0]), SYM.index(label[1])
high, low = max(a, b), min(a, b)
if high == low:
return high * RANKS + high
suited = len(label) == 3 and label[2] == "s"
return high * RANKS + low if suited else low * RANKS + high
def label_von(cid):
row, col = divmod(cid, RANKS)
if row == col:
return SYM[row] * 2
high, low, suited = (row, col, True) if row > col else (col, row, False)
return f"{SYM[high]}{SYM[low]}{'s' if suited else 'o'}"
def combos(cid):
row, col = divmod(cid, RANKS)
return 6 if row == col else (4 if row > col else 12)
ALLE_KLASSEN = list(range(RANKS * RANKS))
TOTAL_COMBOS = 1326.0
def nash_hu_push(stack, m=None, runden=300):
"""Nash-Gleichgewicht Heads-Up Push/Fold (Chip-EV) bei `stack` bb effektiv. Hero (SB, postet 0.5)
jammt oder foldet; Villain (BB, postet 1.0) callt oder foldet. FICTITIOUS PLAY: jede Seite
best-responded gegen den DURCHSCHNITT der Gegnerstrategie (reine Best-Response oszilliert bei
gemischten Gleichgewichten). -> (jam_klassen:set, call_klassen:set) mit Frequenz > 1/2."""
m = m or equity_matrix()
S = float(stack)
co = [combos(c) for c in ALLE_KLASSEN]
jam_f = [1.0] * (RANKS * RANKS) # Durchschnitts-Jam-Frequenz je Klasse
call_f = [0.3] * (RANKS * RANKS) # Durchschnitts-Call-Frequenz je Klasse
for t in range(runden):
# Villain-Best-Response gegen die Durchschnitts-Jam-Range.
jw = sum(co[h] * jam_f[h] for h in ALLE_KLASSEN) or 1.0
call_br = [0.0] * (RANKS * RANKS)
for v in ALLE_KLASSEN:
veq = sum(co[h] * jam_f[h] * (1.0 - m[h][v]) for h in ALLE_KLASSEN) / jw
call_br[v] = 1.0 if S * (2.0 * veq - 1.0) >= -1.0 else 0.0
# Hero-Best-Response gegen die Durchschnitts-Call-Range.
cw = sum(co[v] * call_f[v] for v in ALLE_KLASSEN)
ff = 1.0 - cw / TOTAL_COMBOS
jam_br = [0.0] * (RANKS * RANKS)
for h in ALLE_KLASSEN:
heq = (sum(co[v] * call_f[v] * m[h][v] for v in ALLE_KLASSEN) / cw) if cw > 0 else 0.0
jam_br[h] = 1.0 if ff * 1.0 + (1.0 - ff) * S * (2.0 * heq - 1.0) >= -0.5 else 0.0
# Durchschnitt fortschreiben (Fictitious Play).
w = 1.0 / (t + 2.0)
jam_f = [jam_f[c] * (1.0 - w) + jam_br[c] * w for c in ALLE_KLASSEN]
call_f = [call_f[c] * (1.0 - w) + call_br[c] * w for c in ALLE_KLASSEN]
jam = {c for c in ALLE_KLASSEN if jam_f[c] > 0.5}
call = {c for c in ALLE_KLASSEN if call_f[c] > 0.5}
return jam, call
def icm_equities(stacks, payouts):
"""Harville/Malmuth-ICM: Geldwert jedes Stacks (Reihenfolge wie `stacks`). Rekursiv über die
bezahlten Plätze - wie src/icm/harville.rs, klein genug fürs Bubble-Feld (<= 5)."""
n = len(stacks)
payouts = (list(payouts) + [0.0] * n)[:n]
def rec(idx, rest, prize):
total = sum(stacks[i] for i in rest)
if not prize or total <= 0:
return {i: 0.0 for i in rest}
p0 = prize[0]
out = {i: 0.0 for i in rest}
for i in rest:
share = stacks[i] / total
out[i] += share * p0
if len(prize) > 1:
sub = rec(idx + 1, [j for j in rest if j != i], prize[1:])
for j, v in sub.items():
out[j] += share * v
return out
return rec(0, list(range(n)), payouts)
def nash_icm_push(stacks, payouts, bb=1.0, m=None, runden=200):
"""ICM-Push/Fold-GLEICHGEWICHT an der Bubble: Hero (stacks[0], SB) jammt/foldet, Villain (stacks[1],
BB) callt/foldet - bewertet in ICM-GELD (Harville) statt Chips. stacks[2:] erzeugen den Bubble-Druck
(z. B. ein sehr kurzer Stack, der gleich ausscheidet). Fictitious Play. -> (jam_set, call_set).
Hier steckt die Aggression: der Villain callt ICM-eng (ein Bust vor dem Geld kostet viel), also
foldet er mehr - und Hero jammt dagegen WEITER als nach reiner Chip-EV."""
m = m or equity_matrix()
S = min(stacks[0], stacks[1])
rest = list(stacks[2:])
ih = lambda hs: icm_equities(hs, payouts)[0]
iv = lambda hs: icm_equities(hs, payouts)[1]
v_folds = [stacks[0] + bb, stacks[1] - bb] + rest
h_wins = [stacks[0] + S, max(stacks[1] - S, 1e-9)] + rest
h_loses = [max(stacks[0] - S, 1e-9), stacks[1] + S] + rest
H_fold = ih([max(stacks[0] - bb / 2.0, 1e-9), stacks[1] + bb / 2.0] + rest) # Hero foldet SB
H_vf, H_win, H_lose = ih(v_folds), ih(h_wins), ih(h_loses)
V_fold, V_hwin, V_hlose = iv(v_folds), iv(h_wins), iv(h_loses)
jam_f = [1.0] * (RANKS * RANKS)
call_f = [0.3] * (RANKS * RANKS)
for t in range(runden):
jw = sum(combos(h) * jam_f[h] for h in ALLE_KLASSEN) or 1.0
call_br = [0.0] * (RANKS * RANKS)
for v in ALLE_KLASSEN:
veq = sum(combos(h) * jam_f[h] * (1.0 - m[h][v]) for h in ALLE_KLASSEN) / jw
call_icm = veq * V_hlose + (1.0 - veq) * V_hwin # Villain gewinnt, wenn Hero verliert
call_br[v] = 1.0 if call_icm >= V_fold else 0.0
cw = sum(combos(v) * call_f[v] for v in ALLE_KLASSEN)
ff = 1.0 - cw / TOTAL_COMBOS
jam_br = [0.0] * (RANKS * RANKS)
for h in ALLE_KLASSEN:
heq = (sum(combos(v) * call_f[v] * m[h][v] for v in ALLE_KLASSEN) / cw) if cw > 0 else 0.0
jam_icm = ff * H_vf + (1.0 - ff) * (heq * H_win + (1.0 - heq) * H_lose)
jam_br[h] = 1.0 if jam_icm >= H_fold else 0.0
w = 1.0 / (t + 2.0)
jam_f = [jam_f[c] * (1.0 - w) + jam_br[c] * w for c in ALLE_KLASSEN]
call_f = [call_f[c] * (1.0 - w) + call_br[c] * w for c in ALLE_KLASSEN]
jam = {c for c in ALLE_KLASSEN if jam_f[c] > 0.5}
call = {c for c in ALLE_KLASSEN if call_f[c] > 0.5}
return jam, call
def jam_ev(h, stack, call, call_f_weight=None, m=None):
"""Chip-EV (bb), Hand `h` (Klassen-id) all-in zu jammen, gegen die Villain-Call-Range `call`
(set von Klassen-ids). Villain foldet außerhalb -> Hero gewinnt die BB (+1); gecallt -> Showdown
um `stack`. Fold-EV ist -0.5 (SB verloren)."""
m = m or equity_matrix()
S = float(stack)
cw = sum(combos(v) for v in call)
ff = 1.0 - cw / TOTAL_COMBOS
heq = (sum(combos(v) * m[h][v] for v in call) / cw) if cw > 0 else 0.0
return ff * 1.0 + (1.0 - ff) * S * (2.0 * heq - 1.0)
FOLD_EV = -0.5 # Hero foldet die Small Blind
def hu_push_verlust(stack, jammt, m=None):
"""EV-Verlust (bb/100) der Engine gegenüber Nash im HU-Open-Push/Fold bei `stack` bb.
`jammt`: Funktion Klassen-id -> bool (jammt die Engine diese Hand?). Nash liefert die richtige
Linie je Hand; jede falsche Linie kostet |jam_ev - fold_ev|, combo-gewichtet."""
m = m or equity_matrix()
nash_jam, nash_call = nash_hu_push(stack, m)
verlust = 0.0
falsch = 0
for h in ALLE_KLASSEN:
jev = jam_ev(h, stack, nash_call, m=m)
nash_line_jam = jev >= FOLD_EV # Nash: jammen wenn jam-EV >= fold-EV
if jammt(h) != nash_line_jam:
verlust += combos(h) * abs(jev - FOLD_EV)
falsch += 1
return 100.0 * verlust / TOTAL_COMBOS, falsch
def _selbsttest():
m = equity_matrix()
e = lambda x, y: m[klasse(x)][klasse(y)]
print("Selbsttest gegen bekannte Preflop-Equities (All-in):")
proben = [("AA", "72o", 0.88), ("AA", "KK", 0.82), ("AKs", "QQ", 0.46),
("AKo", "72o", 0.65), ("22", "AKs", 0.50), ("JTs", "A5o", 0.52),
("KK", "AA", 0.18), ("72o", "AA", 0.12)]
ok = True
for x, y, erwartet in proben:
wert = e(x, y)
gut = abs(wert - erwartet) < 0.04
ok = ok and gut
print(f" {x:>4} vs {y:<4} = {wert:.3f} (erwartet ~{erwartet:.2f}) {'OK' if gut else 'FALSCH'}")
print("MAPPING OK" if ok else "MAPPING FALSCH - Klassen-Schema prüfen")
# Summe der Combos = 1326
print("Combos-Summe:", sum(combos(c) for c in ALLE_KLASSEN), "(soll 1326)")
if __name__ == "__main__":
_selbsttest()