Files
pokerfreak-shell/tests/spielplan_formate_spec.py
T
mmintelandClaude Opus 5.5 9f67abbd64 Formate: Tische je Format im Spielplan, Format je Hand, Vergleich je Format
The user wants to choose what the bot plays (several formats at once) and
learn which works best. Each table now knows its format from roomProperties
(lesen/formate.py: cash, aof, bombpot, turnier, kpoker), every hand records
it, and the stats compare formats with a 95 % span; a "best" verdict only
when one span lies above all others. The plan holds tables per format; the
runner fills per format and never sits at an unchosen one. Lobby tabs other
than Cash/Practice are unmeasured, so those formats are selectable but the
runner says why it opens nothing. All-In or Fold hands now count as AOF in
the stats (they were dropped); the runner still abstains there until the
AoF buttons are measured - spielart_spec's exact reason text is updated.

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

137 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""Spielplan je Format (plans/2026-10-30_formate.md): Tischzahl je Format, der Läufer füllt je Format.
* `formate` {format: tische}: unbekannte Formate und Unsinn fallen weg, die Summe bleibt unter
HOECHSTENS (spätere Formate in der Reihenfolge von formate.ALLE werden gekürzt).
* Ein alter Plan ohne `formate` heißt: Cash mit seiner Tischzahl.
* naechster_schritt mit `offen_je_format`: das erste Format unter seiner Zahl, dessen Reiter im
Modus gemessen ist, öffnet; ungemessene sagen warum - nie raten.
* format_passt: an einem Tisch eines Formats mit 0 Tischen wird nicht gesetzt (unbekannt: kein Urteil).
* Der Tisch kennt sein Format (hand/sitzen.Lage.format) aus roomProperties - echter Log.
python3 tests/spielplan_formate_spec.py -v
"""
import gzip
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 ("betrieb", "lesen", "hand"):
sys.path.insert(0, os.path.join(_w, _u))
import formate
import sitzen
import spielplan
from spielplan import Spielplan
def plan(d):
return spielplan.aus_dict(dict({"modus": "echt", "tische": 1}, **d))
def schritt(p, offen_je_format, guthaben=5000.0):
return spielplan.naechster_schritt(p, offen=sum(offen_je_format.values()), in_arbeit=False, schluss=False,
gestoppt=False, letzter_versuch=None, jetzt=1000.0, fehlversuche=0,
guthaben=guthaben, offen_je_format=offen_je_format)
class Formate(unittest.TestCase):
def test_alter_plan_ist_cash(self):
p = plan({"tische": 3})
self.assertEqual(spielplan.formate_von(p), {"cash": 3})
self.assertEqual(p.tische, 3)
def test_formate_und_summe(self):
p = plan({"formate": {"cash": 2, "aof": 1, "bombpot": 0, "erfunden": 4, "vip": -2, "turnier": "x"}})
self.assertEqual(spielplan.formate_von(p), {"cash": 2, "aof": 1})
self.assertEqual(p.tische, 3)
def test_summe_bleibt_unter_hoechstens(self):
p = plan({"formate": {"cash": 10, "aof": 10}})
self.assertEqual(spielplan.formate_von(p), {"cash": 10, "aof": spielplan.HOECHSTENS - 10})
self.assertEqual(p.tische, spielplan.HOECHSTENS)
def test_alles_null_oeffnet_nichts(self):
p = plan({"formate": {"cash": 0}})
self.assertEqual(p.tische, 0)
self.assertEqual(schritt(p, {})[0], "warten")
def test_datei_rundweg(self):
p = plan({"formate": {"cash": 2, "aof": 1}})
self.assertEqual(spielplan.aus_dict(spielplan.als_dict(p)), p)
class Auffuellen(unittest.TestCase):
def test_cash_unter_der_zahl_oeffnet_cash(self):
self.assertEqual(schritt(plan({"formate": {"cash": 2}}), {"cash": 1}), ("oeffnen", "Cash Games"))
def test_uebung_oeffnet_practice(self):
p = spielplan.aus_dict({"modus": "uebung", "tische": 1, "formate": {"cash": 1}})
self.assertEqual(schritt(p, {}), ("oeffnen", "Practice Games"))
def test_ungemessenes_format_sagt_warum(self):
was, text = schritt(plan({"formate": {"cash": 1, "aof": 1}}), {"cash": 1})
self.assertEqual(was, "warten")
self.assertIn("All-In or Fold", text)
self.assertIn("nicht gemessen", text)
def test_gemessenes_format_vor_ungemessenem(self):
# aof steht in der Reihenfolge nach cash - auch umgekehrt geplant öffnet erst das Gemessene
self.assertEqual(schritt(plan({"formate": {"aof": 1, "cash": 1}}), {}), ("oeffnen", "Cash Games"))
def test_jedes_format_voll(self):
was, text = schritt(plan({"formate": {"cash": 1, "aof": 1}}), {"cash": 1, "aof": 1})
self.assertEqual(was, "warten")
self.assertIn("Tischzahl erreicht", text)
def test_ohne_formatangabe_wie_bisher(self):
# der Läufer ohne offen_je_format: wie bisher nach der Gesamtzahl
p = plan({"formate": {"cash": 2}})
self.assertEqual(spielplan.naechster_schritt(p, offen=1, in_arbeit=False, schluss=False, gestoppt=False,
letzter_versuch=None, jetzt=0.0, fehlversuche=0,
guthaben=10.0), ("oeffnen", "Cash Games"))
class FormatPasst(unittest.TestCase):
def test_gewaehltes_format(self):
self.assertTrue(spielplan.format_passt(plan({"formate": {"cash": 1}}), "cash"))
def test_nicht_gewaehltes_format(self):
self.assertFalse(spielplan.format_passt(plan({"formate": {"cash": 1}}), "aof"))
def test_ohne_plan_oder_unbekannt(self):
self.assertTrue(spielplan.format_passt(None, "aof"))
self.assertTrue(spielplan.format_passt(plan({"formate": {"cash": 1}}), None))
MAIN6 = os.path.join(_w, "archiv", "echt", "main.6.log.gz")
@unittest.skipUnless(os.path.exists(MAIN6), "Archiv fehlt")
class FormatAmTisch(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.text = gzip.open(MAIN6, "rt", encoding="utf-8", errors="replace").read()
def test_echter_ring_tisch_ist_cash(self):
lagen, _ = sitzen.lesen(self.text)
self.assertEqual(lagen["Big Ben 1664572"].format, "cash")
def test_echter_aof_tisch(self):
lagen, _ = sitzen.lesen(self.text)
self.assertEqual(lagen["Statue of Liberty 224829"].format, "aof")
def test_format_bleibt_im_gedaechtnis(self):
g = {}
sitzen.lesen(self.text, gedaechtnis=g)
ohne = "\n".join(z for z in self.text.splitlines() if "game.game_alldata" not in z)
lagen, _ = sitzen.lesen(ohne, gedaechtnis=g)
self.assertEqual(lagen["Big Ben 1664572"].format, "cash")
if __name__ == "__main__":
unittest.main()