Files
pokerfreak-shell/tests/turnier_anfrage_spec.py
T
mmintelandClaude Opus 5.5 0fcf356c42 Modi: Turnierlage an den Kern, K-Poker setzt aus, Modus in der Ansicht
The tournament lobby was already parsed but never reached the core. Each
tournament table is now linked to its lobby (tourneyLobbyName or
tournamentId) and the request carries `tournament`; a missing price or
rank list makes the turn unclear instead of guessing. K-Poker tables
(roomProperties.isKPoker) abstain until the key table is measured
(mock/vorlage/kpoker-tasten.md). The clone writes the rank list with each
lobby update and the tournament ids where the real log has them; the
view shows level, field and bubble, or menu and clock.

klonmaus appends mock/ to sys.path so mock/turnier.py no longer shadows
lesen/turnier.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 09:50:12 +01:00

199 lines
9.7 KiB
Python

#!/usr/bin/env python3
"""Spezifikation: die Turnierlage geht mit der Anfrage zum Kern (Feld `tournament`).
Form (Erweiterung wie `history`, nicht in VERTRAG.md; der Kern liest sie in wire/decode_tournament):
"tournament": {"payouts": [Betrag Platz 1, 2, ...], "stacks": [wir, dann das Feld],
"heroIndex": 0, "ante": a, "level": l}
Fälle:
* Turniertisch + Lobby-Meldungen VOR dem Zug -> `tournament`:
payouts = `prizeList[].amount` nach Rang 1..n (Geld)
stacks = [unser Stapel bei Handbeginn] + jeder `rankList`-Eintrag mit Chips > 0 ausser uns
unser Stapel bei Handbeginn = Tisch-Chips + Antes + je Straße der höchste eigene Einsatz
ante, level = `currentBlindLevel` der letzten dynamic_lobby_data
* Welche Lobby zum Tisch gehört: `tourneyTableProperties.tourneyLobbyName` aus game_alldata,
sonst `Comm_Tournament_<tournamentId>` (tournamentId > 0). ANNAHME: Im Bestand gibt es keinen
Turniertisch (alle 18 game_alldata sind Ring, tournamentId 0) - die Felder selbst sind echt.
* Turniertisch, aber Preise oder Rangliste fehlen noch -> aussetzen, `_unklar` "Turnier: ...":
ohne Lage wäre jede Turnierentscheidung geraten.
* Meldungen NACH dem Zug zählen für diesen Zug nicht.
* Cash-Tisch (tournamentId 0, kein Lobbyname) -> kein `tournament`, Anfrage unverändert.
* gameType "Tournament" mit miniGameTypeId 1 ist NLHE (wie Ring); "Allinfold" setzt weiter aus.
* Ende zu Ende mit dem Kern: Lobbyzeilen aus dem Bestand (turnier-bubble: 15 im Feld, 14 bezahlt),
dieselbe Hand ohne Lobby: im Turnier callt der BB den Shove mit weniger Händen als im Cash.
python3 tests/turnier_anfrage_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", "entscheiden", "hand"):
sys.path.insert(0, os.path.join(_w, _u))
import decide
import spot_from_log
LOBBY = "Comm_Tournament_117632"
TISCH = "₮1.10 6-Max Hyper 117632 Tisch 3"
HAND = "11763200019"
HELD = "Williamson1986" # 20205.88 Chips in der echten Rangliste
with open(os.path.join(_w, "archiv", "echt", "beispiele", "turnier-bubble.txt"), encoding="utf-8") as _f:
BUBBLE = _f.read() # echte Lobbyzeilen: Level 19 (1250/2500/312), 15 im Feld, 14 bezahlt
PREISE = [27.76, 18.28, 12.22, 8.38, 5.96, 4.45, 3.49, 2.89, 2.89, 2.48, 2.48, 2.19, 2.19, 2.19]
FELD_OHNE_UNS = [181821.41, 62866.91, 47562.93, 42266.69, 41797.34, 41582.58, 31898.98, 30676.8,
30466.03, 27140.76, 25802.0, 24046.68, 22206.0, 20330.29, 14328.72]
def zeile(cmd, daten, raum=TISCH):
daten = dict(daten, gameHandId=daten.get("gameHandId", HAND))
bohne = json.dumps(json.dumps(daten, separators=(",", ":")))[1:-1]
return ('2026-10-28 12: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}
def alldata(lobby=LOBBY, nummer=117632, game_type="Tournament"):
sitze = [{"seatId": 1, "userName": HELD, "userChips": 20205.88, "isPlaying": True},
{"seatId": 2, "userName": "Leander77", "userChips": 20330.29, "isPlaying": True},
{"seatId": 3, "userName": "QaQom", "userChips": 42266.69, "isPlaying": True}]
return zeile("game.game_alldata", {
"gameInitResponseData": {"bigBlind": 2500.0, "dealerSeatId": 3, "gameHandId": None},
"seatInfoRsponseData": {"isGameStarted": False, "seatResponseDataList": sitze},
"roomProperties": {"gameType": game_type, "miniGameTypeId": 1, "tournamentType": "TOURNAMENT"},
"tourneyTableProperties": {"tournamentId": nummer, "tourneyLobbyName": lobby}})
def hand(loch=(karte("ACE", "SPADES"), karte("NINE", "HEARTS")), gameHandId=HAND):
"""Antes, SB 1250, BB 2500 (wir), Knopf foldet, SB schiebt 20018.29 (alles), wir am Zug."""
h = {"gameHandId": gameHandId}
text = zeile("game.pre_hand_start_info", dict(h, dealerSeatId=3, bbAmount=2500.0, sbAmount=1250.0,
anteAmount=312.0))
for sitz, name, nach in ((1, HELD, 19893.88), (2, "Leander77", 20018.29), (3, "QaQom", 41954.69)):
text += zeile("game.seat", dict(h, seatId=sitz, userName=name, caption="Ante", betAmout=312.0,
userChips=nach))
text += zeile("game.seat", dict(h, seatId=2, userName="Leander77", caption="SB", betAmout=1250.0,
userChips=18768.29))
text += zeile("game.seat", dict(h, seatId=1, userName=HELD, caption="BB", betAmout=2500.0,
userChips=17393.88))
text += zeile("game.seat", dict(h, seatId=3, userName="QaQom", caption="Fold", betAmout=0.0,
userChips=41954.69))
text += zeile("game.seat", dict(h, seatId=2, userName="Leander77", caption="AllIn", betAmout=20018.29,
userChips=0.0))
text += zeile("game.hole_cards", dict(h, holeCards=list(loch)))
return text
def zug(gameHandId=HAND):
return zeile("game.user_turn", {
"gameHandId": gameHandId, "userTurnOptions": {"3": [], "4": [17393.88], "6": [], "5": [], "7": None},
"whoseTurn": HELD, "turnTime": 16, "callAmount": 17393.88, "totalPot": 23454.29,
"extraTurnTime": 0, "extraTimerEnabled": False, "kpokerActions": None})
def anfragen(text):
return [json.loads(z) for z, _, _, _, _ in spot_from_log.spots(text)]
class Lage(unittest.TestCase):
def setUp(self):
self.a, = anfragen(alldata() + BUBBLE + hand() + zug())
def test_preise_nach_rang(self):
self.assertEqual(self.a["tournament"]["payouts"], PREISE)
def test_stapel_wir_zuerst_bei_handbeginn(self):
t = self.a["tournament"]
self.assertEqual(t["heroIndex"], 0)
self.assertAlmostEqual(t["stacks"][0], 17393.88 + 312 + 2500, places=2) # = 20205.88
self.assertEqual(sorted(t["stacks"][1:], reverse=True), FELD_OHNE_UNS) # Rangliste ohne uns, ohne 0-Chips
def test_level_und_ante(self):
self.assertEqual((self.a["tournament"]["level"], self.a["tournament"]["ante"]), (19, 312))
def test_spielt_normal(self):
self.assertEqual(self.a["variant"], "NLHE")
self.assertEqual(self.a["legalActions"], ["FOLD", "CALL"])
self.assertNotIn("_unklar", self.a)
class Zuordnung(unittest.TestCase):
def test_ueber_die_turniernummer(self):
a, = anfragen(alldata(lobby=None) + BUBBLE + hand() + zug())
self.assertEqual(a["tournament"]["payouts"], PREISE)
def test_fremde_lobby_gehoert_nicht_zum_tisch(self):
a, = anfragen(alldata(lobby="Comm_Tournament_999", nummer=999) + BUBBLE + hand() + zug())
self.assertNotIn("tournament", a)
self.assertEqual(a["legalActions"], [])
self.assertTrue(a["_unklar"].startswith("Turnier: "), a["_unklar"])
def test_cash_tisch_bleibt_cash(self):
a, = anfragen(alldata(lobby=None, nummer=0, game_type="Ring") + BUBBLE + hand() + zug())
self.assertNotIn("tournament", a)
self.assertEqual(a["legalActions"], ["FOLD", "CALL"])
def test_allinfold_setzt_weiter_aus(self):
a, = anfragen(alldata(game_type="Allinfold") + BUBBLE + hand() + zug())
self.assertEqual(a["legalActions"], [])
self.assertIn("Allinfold", a["_unklar"])
class Reihenfolge(unittest.TestCase):
def test_meldungen_nach_dem_zug_zaehlen_nicht(self):
a, b = anfragen(alldata() + hand() + zug() + BUBBLE + hand(gameHandId="11763200020")
+ zug(gameHandId="11763200020"))
self.assertEqual(a["legalActions"], [])
self.assertEqual(a["_unklar"], "Turnier: Preisliste fehlt")
self.assertEqual(b["tournament"]["payouts"], PREISE)
def test_ohne_rangliste_aussetzen(self):
ohne = "".join(z for z in BUBBLE.splitlines(True) if "tournamentlobby.rank_list" not in z)
a, = anfragen(alldata() + ohne + hand() + zug())
self.assertEqual(a["_unklar"], "Turnier: Rangliste fehlt")
RANG = "AKQJT98765432"
NAME = {"A": "ACE", "K": "KING", "Q": "QUEEN", "J": "JACK", "T": "TEN", "9": "NINE", "8": "EIGHT",
"7": "SEVEN", "6": "SIX", "5": "FIVE", "4": "FOUR", "3": "THREE", "2": "TWO"}
def haende():
aus = []
for i, a in enumerate(RANG):
for b in RANG[i:]:
zweite = "HEARTS" if a == b else "SPADES"
aus.append((karte(NAME[a], "SPADES"), karte(NAME[b], zweite)))
if a != b:
aus.append((karte(NAME[a], "SPADES"), karte(NAME[b], "HEARTS")))
return aus
@unittest.skipUnless(decide.bereit(), "Kern nicht gebaut")
class EndeZuEnde(unittest.TestCase):
"""Echte Lobby (Bubble: 15 im Feld, 14 bezahlt), dieselbe Hand mit 169 Startkarten."""
def test_bubble_callt_enger_als_cash(self):
turnier, cash = [], []
for n, loch in enumerate(haende()):
nr = f"1176320{n:04d}"
turnier.append(spot_from_log.spots(alldata() + BUBBLE + hand(loch, nr) + zug(nr))[0][0])
cash.append(spot_from_log.spots(alldata(lobby=None, nummer=0, game_type="Ring")
+ hand(loch, nr) + zug(nr))[0][0])
self.assertTrue(all("tournament" in json.loads(z) for z in turnier))
calls = [sum(a["action"] == "CALL" for a in decide.entscheide(z, timeout=300)) for z in (turnier, cash)]
print(f"\n8 BB im BB gegen Shove, 169 Hände: Turnier (Bubble) {calls[0]} Calls, Cash {calls[1]}")
self.assertLess(calls[0], calls[1])
if __name__ == "__main__":
unittest.main()