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>
90 lines
4.0 KiB
Python
90 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Kette Turnier: Klon im Turnier-Modus (mock/start.py --turnier), der Läufer spielt selbst.
|
|
|
|
Klon headless mit Klon-Maus (tests/klonlauf.py). Der Test klickt nie am Tisch; er öffnet den Tisch
|
|
in der Lobby und setzt die Bubble über den Prüfhebel `/api/turnier`.
|
|
|
|
Verlangt:
|
|
* Die Anfragen des Läufers tragen `tournament` (Lobby des Klons, lesen/turnier.py) - Level,
|
|
Ante und die Preise des Klons; der Big Blind folgt dem Level.
|
|
* Über mehrere Level: Entscheidungen auf mindestens zwei Levels, das Level steigt nie zurück.
|
|
* Bubble (Feld 15, 14 bezahlt): die nächste Anfrage hat 15 Stapel und 14 Preise; die Ansicht
|
|
(sicht/ansicht.modus) sagt "Bubble".
|
|
* Der Läufer lebt, das Schattenlog hat keine Verletzung.
|
|
|
|
python3 tests/turnier_kette_spec.py -v
|
|
"""
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from klonlauf import WURZEL, Klonlauf, warte # noqa: E402
|
|
|
|
for _u in ("sicht", "mock"):
|
|
sys.path.insert(0, os.path.join(WURZEL, _u))
|
|
import ansicht # noqa: E402
|
|
import turnier # noqa: E402
|
|
|
|
A = "Big Ben 123456"
|
|
LEVEL_S = 25 # Sekunden je Level im Klon
|
|
FRIST = 240
|
|
|
|
|
|
class TurnierKette(unittest.TestCase):
|
|
def setUp(self):
|
|
self.k = Klonlauf("--turnier", "--level-s", str(LEVEL_S))
|
|
self.addCleanup(self.k.aufraeumen)
|
|
self.k.starten()
|
|
|
|
def warte(self, bedingung, frist, was):
|
|
try:
|
|
return warte(bedingung, frist, was)
|
|
except AssertionError as e:
|
|
schwanz = "\n".join(f"--- Läufer {p.pid} (Rückgabe {p.poll()}) ---\n" + self.k.ausgabe(p)[-2500:]
|
|
for p in self.k.laeufer)
|
|
raise AssertionError(f"{e}\n{schwanz}") from None
|
|
|
|
def anfragen(self):
|
|
return [e["anfrage"] for e in self.k.zuege(A, geklickt=False) if isinstance(e.get("anfrage"), dict)]
|
|
|
|
def turnieranfragen(self):
|
|
return [a for a in self.anfragen() if a.get("tournament")]
|
|
|
|
def test_ueber_mehrere_level_und_die_bubble(self):
|
|
self.k.join(A)
|
|
p = self.k.laeufer_starten(seed="turnier")
|
|
self.warte(lambda: self.k.zustand(A)["buyin"].get("stack"), 90, "Läufer sitzt")
|
|
self.warte(lambda: self.turnieranfragen(), FRIST, "eine Anfrage mit Turnierlage")
|
|
self.assertEqual([a for a in self.anfragen() if not a.get("tournament") and not a.get("_unklar")], [],
|
|
"am Turniertisch geht keine Anfrage ohne Lage zum Kern")
|
|
|
|
# Levelwechsel: Entscheidungen auf zwei Levels, Big Blind und Ante wie die Leiter
|
|
self.warte(lambda: len({a["tournament"]["level"] for a in self.turnieranfragen()}) >= 2,
|
|
FRIST + 3 * LEVEL_S, "Entscheidungen auf zwei Levels")
|
|
stufen = [a["tournament"]["level"] for a in self.turnieranfragen()]
|
|
self.assertEqual(stufen, sorted(stufen), "das Level steigt nie zurück")
|
|
for a in self.turnieranfragen():
|
|
lv, sb, bb, ante = turnier.LEITER[a["tournament"]["level"] - 1]
|
|
self.assertEqual((a["bigBlind"], a["tournament"]["ante"]), (bb, ante))
|
|
self.assertEqual(len(a["tournament"]["payouts"]), self.k.zustand(A)["turnier"]["bezahlt"])
|
|
|
|
# Bubble über den Hebel: die nächste Anfrage sieht 15 im Feld und 14 Preise
|
|
vorher = len(self.turnieranfragen())
|
|
self.k.api("/api/turnier", {"feld": 15, "bezahlt": 14})
|
|
self.warte(lambda: len(self.turnieranfragen()) > vorher, FRIST, "Anfrage nach der Bubble")
|
|
a = self.turnieranfragen()[-1]
|
|
self.assertEqual((len(a["tournament"]["stacks"]), len(a["tournament"]["payouts"])), (15, 14))
|
|
m = ansicht.modus(a)
|
|
self.assertTrue(m["bubble"], m)
|
|
self.assertIn("Bubble", m["text"])
|
|
print(f"\nLevel der Entscheidungen: {sorted(set(stufen))}; Bubble: {m['text']}")
|
|
|
|
self.assertIsNone(p.poll(), self.k.ausgabe(p)[-3000:])
|
|
_, verletzungen = self.k.pruefen()
|
|
self.assertEqual([(v.regel, v.text) for v in verletzungen], [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|