Files
pokerfreak/tests/turnier_anfrage_spec.py
T
mmintel f3949b2d8f spielart: PLO5/PLO6/Short Deck uebersetzen, Allinfold als Ueberlagerung (Spec zuerst)
Der Leser bildet miniGameTypeId 17/18/20 auf PLO5/SHORT_DECK/PLO6 ab (Lochkarten-Zahl als
Gegenprobe, Widerspruch setzt aus) und behandelt Allinfold als Ueberlagerung: die Art bleibt
Holdem/Omaha, nur die Leiste ist FOLD/All-in (Vertrag: legalActions ist massgeblich).
2026-11-03 18:25:55 +01:00

201 lines
9.8 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.
* 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" ist eine
Ueberlagerung dieser Basisart: NLHE, aber nur Fold/All-in (legalActions ["FOLD", "RAISE"]).
* 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, "lesen")):
_w = os.path.dirname(_w)
for _u in ("lesen", "entscheiden", "hand", "client"):
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 Rangliste
with open(os.path.join(_w, "archiv", "mitschrieb", "beispiele", "turnier-bubble.txt"), encoding="utf-8") as _f:
BUBBLE = _f.read() # 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_ist_die_basisart_mit_fold_allin(self):
a, = anfragen(alldata(game_type="Allinfold") + BUBBLE + hand() + zug())
self.assertEqual(a["variant"], "NLHE")
self.assertEqual(a["legalActions"], ["FOLD", "RAISE"])
self.assertNotIn("_unklar", a)
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):
"""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()