#!/usr/bin/env python3 """Übersetzung Log -> Anfrage (lesen/spot_from_log.py) für die Sonderfälle. * dealerCardsDoubleBoard -> boardDouble * kpokerActions -> variant K_POKER, legalActions, allowedSizes * isBombpotHand -> Straße ohne Preflop * extraTurnTime -> Uhr-Grenze des Humanisierers (wenn extraTimerEnabled) * Unklares (unbekannte kpokerActions-Form, Bomb Pot ohne Board, Splash-Pot) -> aussetzen: legalActions leer, der Kern antwortet ABSTAIN, `_unklar` nennt den Grund Die echte Form von kpokerActions ist unbekannt (im Archiv immer null). Verstanden wird die Annahme [{"action": "RAISE", "amount": 0.4}, ...] - so schreibt sie der Klon. python3 tests/uebersetzung_spec.py -v """ import json import os import sys import unittest _w = os.path.dirname(os.path.abspath(__file__)) while _w != "/" and not os.path.isdir(os.path.join(_w, "hand")): _w = os.path.dirname(_w) for _u in ("lesen", "hand"): sys.path.insert(0, os.path.join(_w, _u)) import spot_from_log RAUM = "Big Ben 123456" HAND = "12345600001" def zeile(cmd, daten): daten = dict(daten, gameHandId=daten.get("gameHandId", HAND)) bohne = json.dumps(json.dumps(daten, separators=(",", ":")))[1:-1] return ('2026-10-28 10:00:00:000 [info] [UNITY] Stdout: [Method] -> SendMessageToPipe - ' '{"EventName":"extension_event","RequestId":null,"Data":{"cmd_bean":{"BeanData":"' + bohne + f'","Cmd":"{cmd}","RoomName":"{RAUM}"}},"room_name":"{RAUM}"}}}}\n') def karte(wert, farbe): return {"suit": farbe, "value": wert} FLOP = [karte("SEVEN", "CLUBS"), karte("KING", "SPADES"), karte("TWO", "DIAMONDS")] FLOP2 = [karte("KING", "CLUBS"), karte("QUEEN", "SPADES"), karte("JACK", "DIAMONDS")] LOCH = [karte("SEVEN", "HEARTS"), karte("SEVEN", "DIAMONDS")] def zug(**mehr): d = {"userTurnOptions": {"3": [], "4": [0.4], "6": [], "5": [0.8, 6.0], "7": None}, "whoseTurn": "mmintel", "turnTime": 16, "callAmount": 0.4, "totalPot": 1.2, "extraTurnTime": 0, "extraTimerEnabled": False, "kpokerActions": None} d.update(mehr) return zeile("game.user_turn", d) def grund(board=None, double=None, pot=None): text = zeile("game.seat", {"userName": "mmintel", "seatId": 5, "caption": "BB", "betAmout": 0.1, "userChips": 6.0}) text += zeile("game.seat", {"userName": "Panetos", "seatId": 2, "caption": "Call", "betAmout": 0.1, "userChips": 9.0}) text += zeile("game.hole_cards", {"holeCards": LOCH}) if pot: text += zeile("game.potInfo", pot) if board is not None: text += zeile("game.dealer_cards", {"dealerCards": {"FLOP": board, "TURN": None, "RIVER": None}, "dealerCardsDoubleBoard": double}) return text def anfragen(text): return [(json.loads(z), takt) for z, _, _, _, takt in spot_from_log.spots(text)] class Gewoehnlich(unittest.TestCase): def test_ohne_sonderfelder_keine_neuen_schluessel(self): (a, takt), = anfragen(grund(FLOP, {"FLOP": None, "TURN": None, "RIVER": None}) + zug()) for k in ("boardDouble", "_unklar"): self.assertNotIn(k, a) self.assertEqual(a["variant"], "NLHE") self.assertEqual(a["legalActions"], ["FOLD", "CALL", "RAISE"]) self.assertEqual(takt, 16) class DoppelBoard(unittest.TestCase): def test_zweites_board_in_der_form_von_board(self): double = {"FLOP": FLOP2, "TURN": None, "RIVER": None} (a, _), = anfragen(grund(FLOP, double) + zug()) self.assertEqual(a["board"]["FLOP"][0], {"rank": "SEVEN", "suit": "CLUBS"}) self.assertEqual(a["boardDouble"], {"FLOP": [{"rank": "KING", "suit": "CLUBS"}, {"rank": "QUEEN", "suit": "SPADES"}, {"rank": "JACK", "suit": "DIAMONDS"}]}) def test_naechste_hand_ohne_zweites_board(self): text = grund(FLOP, {"FLOP": FLOP2}) + zug() text += zeile("game.hole_cards", {"holeCards": LOCH, "gameHandId": "12345600002"}) text += zug(gameHandId="12345600002") a = anfragen(text)[1][0] self.assertNotIn("boardDouble", a) class KPoker(unittest.TestCase): MENUE = [{"action": "FOLD"}, {"action": "CALL", "amount": 0.4}, {"action": "RAISE", "amount": 1.2}, {"action": "RAISE", "amount": 2.4}] def test_menue_wird_zu_legalen_aktionen_und_groessen(self): (a, _), = anfragen(grund(FLOP) + zug(kpokerActions=self.MENUE, userTurnOptions={"5": []})) self.assertEqual(a["variant"], "K_POKER") self.assertEqual(a["legalActions"], ["FOLD", "CALL", "RAISE"]) self.assertEqual(a["allowedSizes"], [1.2, 2.4]) self.assertEqual((a["minRaiseTo"], a["maxRaiseTo"]), (1.2, 2.4)) def test_ohne_raise_im_menue_kein_raise(self): (a, _), = anfragen(grund(FLOP) + zug(kpokerActions=self.MENUE[:2])) self.assertEqual(a["legalActions"], ["FOLD", "CALL"]) self.assertNotIn("allowedSizes", a) def test_unbekannte_form_setzt_aus(self): for form in ({"RAISE": [1.2]}, ["RAISE_2X"], [{"typ": "RAISE"}], [{"action": "SHOVE"}]): (a, _), = anfragen(grund(FLOP) + zug(kpokerActions=form)) self.assertEqual(a["legalActions"], [], form) self.assertIn("kpokerActions", a["_unklar"], form) class BombPot(unittest.TestCase): TOPF = {"isBombpotHand": True, "totalPotAmount": 3.0, "roundName": "FLOP"} def test_strasse_nie_preflop(self): (a, _), = anfragen(grund(FLOP, pot=self.TOPF) + zug()) self.assertEqual(a["street"], "FLOP") self.assertEqual(a["legalActions"], ["FOLD", "CALL", "RAISE"]) def test_bomb_pot_ohne_board_setzt_aus(self): (a, _), = anfragen(grund(pot=self.TOPF) + zug()) self.assertNotEqual(a["street"], "PREFLOP") self.assertEqual(a["legalActions"], []) self.assertIn("Bomb", a["_unklar"]) def test_naechste_gewoehnliche_hand_hat_wieder_preflop(self): text = grund(pot=self.TOPF) + zug() text += zeile("game.hole_cards", {"holeCards": LOCH, "gameHandId": "12345600002"}) text += zug(gameHandId="12345600002") a = anfragen(text)[1][0] self.assertEqual(a["street"], "PREFLOP") # Die neue Hand hat hier keine Posten und keinen Knopf - das setzt aus, aber nicht als Bomb Pot self.assertNotIn("Bomb", a.get("_unklar", "")) class SplashPot(unittest.TestCase): def test_splash_setzt_aus(self): for topf in ({"splashPotDropAmount": 0.5, "totalPotAmount": 1.7}, {"isMegaSplash": True, "totalPotAmount": 1.7}): (a, _), = anfragen(grund(FLOP, pot=topf) + zug()) self.assertEqual(a["legalActions"], [], topf) self.assertIn("Splash", a["_unklar"]) class AllInOhneGroessen(unittest.TestCase): def test_nur_fold_und_call(self): (a, _), = anfragen(grund(FLOP) + zug(userTurnOptions={"4": [6.0], "5": []}, callAmount=6.0)) self.assertEqual(a["legalActions"], ["FOLD", "CALL"]) self.assertNotIn("allowedSizes", a) class Zusatzzeit(unittest.TestCase): def test_zusatzzeit_zaehlt_zur_uhr_wenn_eingeschaltet(self): (_, takt), = anfragen(grund(FLOP) + zug(turnTime=16, extraTurnTime=30, extraTimerEnabled=True)) self.assertEqual(takt, 46) def test_ausgeschaltete_zusatzzeit_zaehlt_nicht(self): (_, takt), = anfragen(grund(FLOP) + zug(turnTime=16, extraTurnTime=30, extraTimerEnabled=False)) self.assertEqual(takt, 16) if __name__ == "__main__": unittest.main()