#!/usr/bin/env python3 """Replay-Benchmark: Evaluator, HH-Parser und Spot-Rekonstruktion. Der unabhaengige Evaluator (`eval7`) ist der Ground Truth des Benchmarks - er wird hier gegen bekannte Haende geprueft. Parser und Rekonstruktion laufen auf einer eingebetteten Mini-Session (Format wie der echte Export), deterministisch, ohne die Engine. Der Engine-Roundtrip wird nur geprueft, wenn das Binary schon gebaut ist (sonst uebersprungen - die schnelle Spur baut nicht). python3 tests/replay_spec.py -v """ import os import sys import unittest HIER = os.path.dirname(os.path.abspath(__file__)) WURZEL = os.path.dirname(HIER) sys.path.insert(0, os.path.join(WURZEL, "entscheiden")) import eval7 import replay # Eine Mini-Session im echten Export-Format: eine Hand, in der Hero (mmintel) Bottom Pair + Ass # gegen eine Bet foldet und der Gegner J-high als Bluff zeigt - der belegte Overfold. FIXTURE = """# CoinPoker Cash Game Export (Fixture) ### Hand #999000000001 - 2026-11-10 10:00:00 CET - `Test NL 0.01-0.02` - Net: **-0.06 (-3.0 bb)** - **Players (BTN S6):** S1 aha09 ($0.96, VPIP 0%/2h), S2 mmintel ($2.03, VPIP 0%/1h), S3 zambino78 ($0.42, VPIP 28%/82h), S6 Natalensis ($2.11, VPIP 45%/11h) - **Hero Hole Cards:** `As 2c` - **Engine Decisions:** - `PREFLOP` | board=`` | pot=$0.07 toCall=$0.02 | **CALL** | eq=None | BB vs open -> call - `FLOP` | board=`Kd 5s 2h` | pot=$0.09 toCall=$0.00 | **CHECK** | eq=0.418 | bottom pair - `FLOP` | board=`Kd 5s 2h` | pot=$0.15 toCall=$0.06 | **FOLD** | eq=0.246 | bottom pair: EV call -0.01 ```text PokerStars Hand #999000000001: Hold'em No Limit ($0.01/$0.02 USD) - 2026/11/10 10:00:00 CET Table 'Test NL 0.01-0.02' 6-max Seat #6 is the button Seat 1: aha09 ($0.96 in chips) Seat 2: mmintel ($2.03 in chips) Seat 3: zambino78 ($0.42 in chips) Seat 6: Natalensis ($2.11 in chips) aha09: posts small blind $0.01 mmintel: posts big blind $0.02 *** HOLE CARDS *** Dealt to mmintel [As 2c] zambino78: raises $0.02 to $0.04 Natalensis: folds aha09: folds mmintel: calls $0.02 *** FLOP *** [Kd 5s 2h] mmintel: checks zambino78: bets $0.06 mmintel: folds Uncalled bet ($0.06) returned to zambino78 zambino78: shows [Jh 9h] zambino78 collected $0.09 from pot *** SUMMARY *** Total pot $0.09 | Rake $0.00 Board [Kd 5s 2h] ``` """ class Evaluator(unittest.TestCase): def test_selbsttest_laeuft_beim_import(self): eval7._selftest() # wirft bei Fehler def test_river_showdown_exakt(self): # Top Pair Koenige schlaegt Paar Zehnen auf fertigem Board -> Equity 1.0 self.assertEqual(eval7.equity_vs("Kd 7d", "9c Tc Kc Qd 2h", ["Ah Td"]), 1.0) def test_bottom_pair_ass_vs_bluff(self): # As2c Bottom Pair + Ass gegen Jh9h (J-high) auf Kd5s2h: klar vorn eq = eval7.equity_vs("As 2c", "Kd 5s 2h", ["Jh 9h"]) self.assertGreater(eq, 0.6) class Parser(unittest.TestCase): def setUp(self): self.blocks = FIXTURE.split("### Hand ")[1:] self.hand = replay.parse_hand(self.blocks[0]) def test_hand_geparst(self): self.assertIsNotNone(self.hand) self.assertEqual(self.hand["hero_cards"], ["As", "2c"]) self.assertEqual(self.hand["seats"]["mmintel"], 2) self.assertEqual(self.hand["button"], 6) self.assertEqual(self.hand["shown"]["zambino78"], ["Jh", "9h"]) self.assertEqual(self.hand["prof"]["zambino78"], {"vpip": 0.28, "hands": 82}) def test_rekonstruktion_baut_wohlgeformte_spots(self): spots = replay.reconstruct(self.hand) # Drei Hero-Aktionen: Preflop CALL, Flop CHECK, Flop FOLD self.assertEqual(len(spots), 3) for req, dec in spots: for key in ("variant", "bigBlind", "heroSeat", "heroCards", "street", "pot", "toCall", "heroStack", "legalActions", "villains", "history"): self.assertIn(key, req) self.assertGreaterEqual(req["heroStack"], 0.0) def test_history_vor_dem_flop_fold(self): spots = replay.reconstruct(self.hand) _, _ = spots[0] flop_fold_req, dec = spots[2] self.assertEqual(dec["action"], "FOLD") self.assertEqual(dec["to_call"], 0.06) # Die History vor dem Fold enthaelt die Bet des Gegners (zambino78 auf Sitz 3) bet = [h for h in flop_fold_req["history"] if h["action"] == "BET"] self.assertTrue(bet and bet[0]["seat"] == 3) # und Profil geht mit auf die Reise v3 = [v for v in flop_fold_req["villains"] if v["seat"] == 3][0] self.assertAlmostEqual(v3["profile"]["vpip"], 0.28) class EngineRoundtrip(unittest.TestCase): def test_engine_entscheidet_rekonstruierten_spot(self): import decide if not decide.bereit() or not decide.frisch(): self.skipTest("Engine-Binary nicht frisch gebaut - schnelle Spur baut nicht") hand = replay.parse_hand(FIXTURE.split("### Hand ")[1:][0]) import json req = json.dumps(replay.reconstruct(hand)[2][0]) ans = decide.entscheide([req])[0] self.assertIn(ans.get("action"), {"FOLD", "CALL", "RAISE", "CHECK", "ABSTAIN"}) if __name__ == "__main__": unittest.main()