Files
pokerfreak/tests/leckfinder_spec.py
T
mmintelandClaude Opus 5.5 67f94bc82e M6b-Zusatz: Leck-Finder auf echten PHH-Spots (Engine gegen bekannte Gegnerhand, realisierte Ausgaenge, Muck-Korrektur, gemessener NL2-Abstand)
River-Jams mit einem Paar: alt +42 923 bb Check besser (NL2-Sicht, Untergrenze +10 137), live +10 850 (+1 011).
A9o gegen tiefen Shove mit NL25-Daten nicht gefangen. Bericht messung/leckfinder/README.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 12:56:43 +01:00

92 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""Spezifikation lesen/leckfinder.py (Auftrag M6b-Zusatz, 17.11.).
python -I tests/leckfinder_spec.py -v
PHH-Block lesen, Spots mit beiden Händen (Anfrage auf NL2 skaliert), realer Ausgang (eine aufgedeckte Hand ist die
des Gewinners), All-in-Jams mit Fold und Klasse, Konfrontation gegen ein All-in, Muck-Korrektur des Jam-EV.
"""
import os
import sys
import unittest
_w = os.path.dirname(os.path.abspath(__file__))
while not os.path.isdir(os.path.join(_w, "lesen")):
_w = os.path.dirname(_w)
sys.path.insert(0, os.path.join(_w, "lesen"))
import leckfinder as lf # noqa: E402
def block(aktionen, stacks="25, 25", blinds="0.10, 0.25"):
return ("[1]\nvariant = 'NT'\nblinds_or_straddles = [%s]\nstarting_stacks = [%s]\nactions = [%s]\n"
"hand = 123\nplayers = ['a', 'b']\n" % (blinds, stacks, ", ".join("'%s'" % a for a in aktionen)))
# Heads-up: p1 SB (Knopf), p2 BB. Flop check/check, Turn check/check, River p2 jam 24.5, p1 callt.
RIVER_JAM = ["d dh p1 AhAc", "d dh p2 Kd6h", "p1 cc", "p2 cc", "d db Tc4d9s", "p2 cc", "p1 cc", "d db 6c",
"p2 cc", "p1 cc", "d db Kh", "p2 cbr 24.75", "p1 cc"]
class Lesen(unittest.TestCase):
def test_hand_und_karten(self):
h = lf.hand(block(RIVER_JAM))
self.assertEqual(h["n"], 2)
self.assertEqual(h["board"], ["Tc", "4d", "9s", "6c", "Kh"])
self.assertEqual(h["karten"], {0: ["Ah", "Ac"], 1: ["Kd", "6h"]})
def test_spot_gegen_allin_auf_nl2_skaliert(self):
h = lf.hand(block(RIVER_JAM))
spots = lf.spots_einer_hand(h, 25, "PS", None, 0)
river = [s for s in spots if s["strasse"] == 3]
self.assertEqual([s["p"] for s in river], [1, 0])
sp = river[1]
self.assertTrue(lf.gegen_allin(sp))
self.assertAlmostEqual(sp["topf"], 2 + 99) # 0,5 bb Topf + 24,75 $ = 99 bb
self.assertAlmostEqual(sp["req"]["toCall"], 0.02 * 99, places=3)
self.assertEqual(sp["req"]["legalActions"], ["FOLD", "CALL"])
self.assertIsNone(sp["req"]["allowedSizes"]) # [] verböte jeden Raise
self.assertEqual(sp["eq"], 0.0) # AA verliert gegen Zwei Paar
class Ausgang(unittest.TestCase):
def test_eine_aufgedeckte_hand_ist_die_des_gewinners(self):
h = lf.hand(block(["d dh p1 ????", "d dh p2 Kd6h"] + RIVER_JAM[2:]))
self.assertEqual(lf.ausgang(h, 1, 0), 1.0)
self.assertEqual(lf.ausgang(h, 0, 1), 0.0)
def test_beide_aufgedeckt(self):
h = lf.hand(block(RIVER_JAM))
self.assertEqual(lf.ausgang(h, 0, 1), 0.0)
class Jams(unittest.TestCase):
def test_jam_gecallt_mit_klasse_und_ertrag(self):
h = lf.hand(block(RIVER_JAM))
(z,) = lf.jams_einer_hand(h, 0)
self.assertEqual((z["street"], z["bucket"], z["fold"], z["klasse"], z["aus"]), ("river", "gt150", False,
"zwei_paar", 1.0))
self.assertGreater(z["netz_topf"], 1.0)
def test_jam_gefoldet(self):
h = lf.hand(block(RIVER_JAM[:-1] + ["p1 f"]))
(z,) = lf.jams_einer_hand(h, 0)
self.assertTrue(z["fold"])
def test_konfrontation_aus_sicht_des_callers(self):
h = lf.hand(block(RIVER_JAM))
self.assertEqual(lf.konfrontation(h), (3, 0.0, True))
def test_muck_korrektur(self):
jams = {"zellen": {"river|gt150": {"n": 100, "fold": 50, "fold_wert": 47.5, "j_verl_gezeigt": 10,
"j_verl_gemuckt": 10}},
"klassen": {"river|gt150|top_paar": {"sieg_n": 10, "sieg_s": 20.0, "verl_n": 10, "verl_s": -20.0}}}
ev, se, n = lf.jam_ev_topf(jams, "river", "gt150", "top_paar")
# gemuckte Verluste verdoppeln die gezeigten: (20 - 2·20) / 30 = -2/3 gecallt
self.assertAlmostEqual(ev, 0.5 * 0.95 + 0.5 * (-20.0 / 30.0))
self.assertEqual(n, 20)
if __name__ == "__main__":
unittest.main(verbosity=2)