- lesen/spot_from_log: Turnierlage aus Beitrittszeile ODER Tisch-Rahmen (tournamentlobby.*); fehlt etwas, spielt der Tisch Chip-EV mit Grund in _turnier - entscheiden/decide.py: Modus in Antwort/Begründung; unbepreisbare Lage -> einmal als Chip-EV - src/icm/push_fold.rs: ICM-Nash Push/Fold (<=15bb first-in, Call gegen lone Jam <=25bb), fiktives Spiel über 169 Klassen, Antes im Pot; exploit_border ohne ICM-Doppelzählung - turnier_leiter ab: gepaarter A/B Solver vs kalibriert - tests/turnier_spots_spec: 8 Spots + Rückfall; Cash unberührt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
312 lines
16 KiB
Python
312 lines
16 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, Rangliste oder Lobby fehlen -> NICHT aussetzen (am echten Tisch hiesse das
|
|
blind folden/checken), sondern sicher Chip-EV: kein `tournament`, Leiste wie sonst, `_turnier`
|
|
"Chip-EV-Rückfall: Turnier: ..." nennt den Grund (decide.py haengt ihn an die Begruendung).
|
|
Mit Lage: `_turnier` "ICM".
|
|
* Die Lobby kommt auch auf dem TISCHkanal (`cmd_bean.Cmd` tournamentlobby.*, gemessen 04.11.): diese
|
|
Rahmen allein reichen fuer die Lage und machen den Tisch zum Turniertisch.
|
|
* 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": 3, "userName": HELD, "userChips": 20205.88, "isPlaying": True},
|
|
{"seatId": 2, "userName": "Leander77", "userChips": 20330.29, "isPlaying": True},
|
|
{"seatId": 1, "userName": "QaQom", "userChips": 42266.69, "isPlaying": True}]
|
|
return zeile("game.game_alldata", {
|
|
"gameInitResponseData": {"bigBlind": 2500.0, "dealerSeatId": 1, "gameHandId": None},
|
|
"seatInfoRsponseData": {"isGameStarted": False, "seatResponseDataList": sitze},
|
|
"roomProperties": {"gameType": game_type, "miniGameTypeId": 1, "tournamentType": "TOURNAMENT"},
|
|
"tourneyTableProperties": {"tournamentId": nummer, "tourneyLobbyName": lobby}})
|
|
|
|
|
|
def alldata_ohne_lobby():
|
|
"""game_alldata mit gameType 'Tournament', aber OHNE tourneyTableProperties: die Beitritts-Zeile
|
|
ist aus dem 4-MB-Tail gescrollt, self.lobby bleibt None. Die Uebersetzung muss TROTZDEM greifen -
|
|
sonst setzt die Engine aus und der Laeufer foldet/checkt blind (Owner 9.11.: JJ pot-committed weg)."""
|
|
sitze = [{"seatId": 3, "userName": HELD, "userChips": 20205.88, "isPlaying": True},
|
|
{"seatId": 2, "userName": "Leander77", "userChips": 20330.29, "isPlaying": True},
|
|
{"seatId": 1, "userName": "QaQom", "userChips": 42266.69, "isPlaying": True}]
|
|
return zeile("game.game_alldata", {
|
|
"gameInitResponseData": {"bigBlind": 2500.0, "dealerSeatId": 1, "gameHandId": None},
|
|
"seatInfoRsponseData": {"isGameStarted": False, "seatResponseDataList": sitze},
|
|
"roomProperties": {"gameType": "Tournament", "miniGameTypeId": 1, "tournamentType": "TOURNAMENT"}})
|
|
|
|
|
|
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=1, bbAmount=2500.0, sbAmount=1250.0,
|
|
anteAmount=312.0))
|
|
for sitz, name, nach in ((3, HELD, 19893.88), (2, "Leander77", 20018.29), (1, "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=3, userName=HELD, caption="BB", betAmout=2500.0,
|
|
userChips=17393.88))
|
|
text += zeile("game.seat", dict(h, seatId=1, 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)
|
|
self.assertEqual(self.a["_turnier"], "ICM")
|
|
|
|
|
|
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"], ["FOLD", "CALL"]) # Chip-EV, nicht aussetzen
|
|
self.assertNotIn("_unklar", a)
|
|
self.assertEqual(a["_turnier"], "Chip-EV-Rückfall: Turnier: Preisliste fehlt")
|
|
|
|
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"])
|
|
self.assertNotIn("_turnier", a)
|
|
|
|
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"], ["FOLD", "CALL"])
|
|
self.assertNotIn("tournament", a)
|
|
self.assertEqual(a["_turnier"], "Chip-EV-Rückfall: Turnier: Preisliste fehlt")
|
|
self.assertEqual(b["tournament"]["payouts"], PREISE)
|
|
|
|
def test_ohne_rangliste_chip_ev(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["legalActions"], ["FOLD", "CALL"])
|
|
self.assertNotIn("tournament", a)
|
|
self.assertEqual(a["_turnier"], "Chip-EV-Rückfall: Turnier: Rangliste fehlt")
|
|
|
|
|
|
def tischrahmen(text=BUBBLE, raum=TISCH):
|
|
"""Dieselben vier Lobby-Meldungen, aber als Rahmen auf dem TISCHkanal (cmd_bean.Cmd tournamentlobby.*)."""
|
|
import turnier
|
|
aus = ""
|
|
for _, _, art, d in turnier.meldungen(text):
|
|
cmd = {v: k for k, v in turnier.ARTEN.items()}[art]
|
|
bohne = json.dumps(json.dumps(d, separators=(",", ":")))[1:-1]
|
|
aus += ('2026-11-04 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')
|
|
return aus
|
|
|
|
|
|
class Tischkanal(unittest.TestCase):
|
|
"""Die Lobby auf dem Tischkanal (gemessen 04.11.: 11x tournamentlobby.dynamic_lobby_data am Tisch)."""
|
|
|
|
def test_rahmen_am_tisch_geben_die_lage(self):
|
|
a, = anfragen(alldata() + tischrahmen() + hand() + zug())
|
|
self.assertEqual(a["tournament"]["payouts"], PREISE)
|
|
self.assertEqual((a["tournament"]["level"], a["tournament"]["ante"]), (19, 312))
|
|
self.assertEqual(a["_turnier"], "ICM")
|
|
|
|
def test_rahmen_machen_den_tisch_zum_turniertisch_auch_ohne_beitritt(self):
|
|
a, = anfragen(alldata_ohne_lobby() + tischrahmen() + hand() + zug())
|
|
self.assertEqual(a["tournament"]["payouts"], PREISE)
|
|
|
|
def test_rahmen_eines_anderen_tisches_zaehlen_nicht(self):
|
|
a, = anfragen(alldata() + tischrahmen(raum="anderer Tisch 9") + hand() + zug())
|
|
self.assertNotIn("tournament", a)
|
|
self.assertEqual(a["_turnier"], "Chip-EV-Rückfall: Turnier: Preisliste 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()):
|
|
# Hand-IDs NACH der Beitrittszeile (alldata traegt HAND = ...0019): kleinere IDs sind fuer
|
|
# den Leser spaete Zeilen einer alten Hand - ohne Verlauf kein Angreifer, keine ICM-Praemie.
|
|
nr = f"1176321{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])
|
|
|
|
|
|
def zug_offen(gameHandId=HAND):
|
|
"""Unser Zug am Turniertisch, nichts zu callen - mit dem ECHTEN Freeroll-Optionsformat
|
|
(live 9.11. gemessen): callAmount 0, "5" leer, "4" null, eigene Schluessel 7/8/9. Im Cash
|
|
stehen hier die Raise-Groessen in "5"; im Turnier nicht - der Parser fand darum nie ein RAISE."""
|
|
return zeile("game.user_turn", {
|
|
"gameHandId": gameHandId, "whoseTurn": HELD, "turnTime": 16, "callAmount": 0.0,
|
|
"totalPot": 900.0, "extraTurnTime": 0, "extraTimerEnabled": False, "kpokerActions": None,
|
|
"userTurnOptions": {"3": [], "4": None, "6": [], "5": [], "7": [], "8": [], "9": []}})
|
|
|
|
|
|
def hand_offen(loch=(karte("ACE", "SPADES"), karte("QUEEN", "HEARTS")), gameHandId=HAND):
|
|
"""Wir sind BB mit Stapel, der SB limpt/ergaenzt - wir koennen checken ODER jammen (kein Shove gegen uns)."""
|
|
h = {"gameHandId": gameHandId}
|
|
text = zeile("game.pre_hand_start_info", dict(h, dealerSeatId=1, bbAmount=2500.0, sbAmount=1250.0))
|
|
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=3, userName=HELD, caption="BB", betAmout=2500.0,
|
|
userChips=17393.88))
|
|
text += zeile("game.seat", dict(h, seatId=2, userName="Leander77", caption="Call", betAmout=2500.0,
|
|
userChips=17518.29))
|
|
text += zeile("game.hole_cards", dict(h, holeCards=list(loch)))
|
|
return text
|
|
|
|
|
|
class JamAmTurniertisch(unittest.TestCase):
|
|
"""Am Turniertisch MUSS der Jam (All-in) verfuegbar sein: der Server listet die Raise-Groessen
|
|
nicht wie im Cash ("5" leer), sonst bekam der Bot nur Fold/Check und foldete/checkte JEDE Hand
|
|
(Owner 9.11.: 'er sitzt angemeldet, foldet aber alles; AQ -> Fold')."""
|
|
|
|
def test_raise_als_jam_verfuegbar(self):
|
|
a, = anfragen(alldata_ohne_lobby() + hand_offen() + zug_offen())
|
|
self.assertIn("RAISE", a["legalActions"])
|
|
self.assertEqual(a["minRaiseTo"], a["heroStack"]) # Jam = All-in (ganzer Stapel)
|
|
self.assertEqual(a["maxRaiseTo"], a["heroStack"])
|
|
|
|
def test_cashtisch_bleibt_ohne_erfundenes_raise(self):
|
|
# derselbe leere Optionssatz an einem RING-Tisch: KEIN erfundenes RAISE (nur Turnier-Rueckfall)
|
|
a, = anfragen(alldata(lobby=None, nummer=0, game_type="Ring") + hand_offen() + zug_offen())
|
|
self.assertNotIn("RAISE", a["legalActions"])
|
|
|
|
|
|
class OhneBeitrittsZeile(unittest.TestCase):
|
|
"""gameType 'Tournament', aber die Beitritts-Zeile (tourneyTableProperties) ist aus dem Tail
|
|
gescrollt - self.lobby None. Frueher setzte die Engine aus ('gameType Tournament nicht
|
|
abgebildet'), der Laeufer foldete/checkte blind (Owner 9.11.: JJ pot-committed weg, 180/910)."""
|
|
|
|
def test_turniertisch_uebersetzt_auch_ohne_lobby(self):
|
|
a, = anfragen(alldata_ohne_lobby() + hand() + zug())
|
|
self.assertEqual(a["variant"], "NLHE") # Turniertisch IST ein Pokertisch
|
|
self.assertTrue(a.get("legalActions")) # nicht leer = nicht ausgesetzt
|
|
self.assertNotIn("tournament", a) # ohne Lobby kein ICM-Feld - aber chip-EV spielt
|
|
self.assertEqual(a["_turnier"], "Chip-EV-Rückfall: Turnier: Lobby unbekannt")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|