Files
pokerfreak/messung/pruef/slumbot_jam.py
T

157 lines
6.3 KiB
Python

"""Zwei Skript-Strategien gegen Slumbot (Owner-Hypothese, ohne Kern), eine Verbindung, maessige Rate.
jam jede Hand preflop all-in (SB eroeffnet b20000; BB raist all-in, callt einen Slumbot-Jam).
chart preflop nur die besten ~50 % der Kombos (Rangfolge nach Equity gegen eine Zufallshand) eroeffnen bzw.
callen, sonst Fold (Check, wenn frei). Am Flop: Equity gegen eine Zufallshand < 50 % -> bei der ersten
Gelegenheit all-in, sonst bis zum Showdown check/call (auch gegen All-ins).
python messung/pruef/slumbot_jam.py <jam|chart> <haende>
python messung/pruef/slumbot_jam.py auswertung jam chart
Log: slumbot/haende-<art>.jsonl (gleiches Format wie slumbot.py, kern = Liste unserer Zuege).
"""
import json
import os
import random
import sys
import time
HIER = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HIER)
sys.path.insert(0, os.path.join(HIER, "..", "..", "entscheiden"))
sys.dont_write_bytecode = True
import eval7 # noqa: E402
import slumbot as S # noqa: E402
RAENGE = "23456789TJQKA"
def klasse(k):
a, b = sorted(k, key=lambda c: RAENGE.index(c[0]), reverse=True)
if a[0] == b[0]:
return a[0] + b[0]
return a[0] + b[0] + ("s" if a[1] == b[1] else "o")
def chart_oben(anteil=0.5):
"""Die 169 Klassen nach Equity gegen eine Zufallshand; oben bis `anteil` der 1326 Kombos."""
pfad = os.path.join(HIER, "slumbot", "chart169.json")
if os.path.exists(pfad):
eq = json.load(open(pfad, encoding="utf-8"))
else:
eq = {}
for i, r1 in enumerate(RAENGE):
for r2 in RAENGE[: i + 1]:
for art in ("s", "o") if r1 != r2 else ("",):
hand = [r1 + "s", r2 + ("s" if art == "s" else "h")]
rng = random.Random(hash(r1 + r2 + art) & 0xFFFF)
deck = [c for c in (r + f for r in RAENGE for f in "shdc") if c not in hand]
w = 0.0
for _ in range(1500):
v = rng.sample(deck, 2)
w += eval7.equity_mc(hand, [], [v], laeufe=1, seed=rng.random())
eq[r1 + r2 + art if r1 != r2 else r1 + r2] = w / 1500
json.dump(eq, open(pfad, "w", encoding="utf-8"))
kombos = lambda k: 6 if len(k) == 2 else (4 if k[2] == "s" else 12)
oben, n = set(), 0
for k in sorted(eq, key=lambda x: -eq[x]):
if n >= anteil * 1326:
break
oben.add(k)
n += kombos(k)
return oben
def eq_zufall(loch, brett):
rng = random.Random(hash(tuple(loch + brett)) & 0xFFFFFFFF)
deck = [c for c in (r + f for r in RAENGE for f in "shdc") if c not in loch + brett]
w = 0.0
for _ in range(400):
v = rng.sample(deck, 2 + 5 - len(brett))
w += eval7.equity_vs(loch, brett + v[2:], [v[:2]])
return w / 400
def zug(art, r, oben):
z = S.zerlege(r["action"])
ich = 0 if r["client_pos"] == 1 else 1
du = 1 - ich
bei, ges = z["strasse_bei"], z["gesamt"]
zu = bei[du] - bei[ich]
jam = "b%d" % (bei[ich] + S.STACK - ges[ich])
du_allin = ges[du] >= S.STACK
if art == "jam":
return "c" if du_allin else jam
loch, brett = r["hole_cards"], r.get("board") or []
if z["st"] == 0:
if klasse(loch) not in oben:
return "k" if zu == 0 else "f"
if ich == 0 and zu > 0 and not z["strassen"][0]:
return "b250" # SB eroeffnet
return "c" if zu > 0 else "k"
if z["st"] == 1 and eq_zufall(loch, brett[:3]) < 0.5:
return "c" if du_allin else jam
return "c" if zu > 0 else "k"
def auswertung(art):
"""bb/Hand +-SE, Slumbots Fold-Quote gegen unseren Jam (Preflop/Flop), Busts bei 100 bb Budget mit Re-Entry."""
import math
hs = [json.loads(z) for z in open(os.path.join(HIER, "slumbot", "haende-%s.jsonl" % art), encoding="utf-8") if z.strip()]
w = [h["gewinn"] / S.BB for h in hs]
n = len(w)
m = sum(w) / n
se = math.sqrt(sum((x - m) ** 2 for x in w) / (n - 1) / n)
print("%s: %d Haende, %+.3f bb/Hand +-%.3f (SE), = %+.0f mbb/Hand" % (art, n, m, se, 1000 * m))
for p, name in ((1, "SB"), (0, "BB")):
t = [h["gewinn"] / S.BB for h in hs if h["pos"] == p]
print(" %s %+.3f bb/Hand (n=%d)" % (name, sum(t) / len(t), len(t)))
for st, name in ((0, "Preflop"), (1, "Flop")):
jams = folds = 0
for h in hs:
z = S.zerlege(h["aktion"])["strassen"][st]
ich = 0 if h["pos"] == 1 else 1
for k, (wer, a, b) in enumerate(z):
if wer == ich and a == "b" and b != 250: # unser b250 ist der Open, jeder andere Einsatz ein Jam
jams += 1
folds += k + 1 < len(z) and z[k + 1][1] == "f"
break
if jams:
print(" Jam %s: %d, Slumbot foldet %d = %.1f %%" % (name, jams, folds, 100.0 * folds / jams))
konto, busts = 100.0, 0
for x in w:
konto += x
if konto <= 0:
busts += 1
konto = 100.0
print(" Busts bei 100 bb Budget mit Re-Entry: %d (Rest %.0f bb)" % (busts, konto))
def main():
if sys.argv[1] == "auswertung":
for art in sys.argv[2:]:
auswertung(art)
return
art, haende = sys.argv[1], int(sys.argv[2])
oben = chart_oben() if art == "chart" else set()
datei = os.path.join(HIER, "slumbot", "haende-%s.jsonl" % art)
schon = sum(1 for _ in open(datei, encoding="utf-8")) if os.path.exists(datei) else 0
api = S.Api(0.25)
with open(datei, "a", encoding="utf-8") as aus:
for nr in range(schon, haende):
if os.path.exists(os.path.join(HIER, "slumbot", "STOP")):
break
r = api.neue_hand()
zuege = []
while "winnings" not in r:
incr = zug(art, r, oben)
zuege.append({"str": S.STRASSEN[S.zerlege(r["action"])["st"]], "incr": incr})
r = api.zug(incr)
aus.write(json.dumps({"nr": nr, "lauf": art, "pos": r.get("client_pos"), "loch": r.get("hole_cards"),
"bot": r.get("bot_hole_cards"), "brett": r.get("board"), "aktion": r.get("action"),
"gewinn": r["winnings"], "kern": zuege, "zeit": int(time.time())}, separators=(",", ":")) + "\n")
aus.flush()
if __name__ == "__main__":
main()