Files
pokerfreak-shell/betrieb/spielplan.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

196 lines
8.5 KiB
Python

"""Der Spielplan: Übung oder Live, und wie viele Tische - gesetzt im Cockpit, gelesen vom Läufer.
Ohne Spielplan öffnet der Läufer nie selbst einen Tisch (wie bisher: er setzt sich nur an offene).
Mit Spielplan füllt er bis zur Tischzahl auf - über die Lobby (mcp/lobby_adapter.py), im Live-Modus
mit Guthaben, Geldregel (lesen/geld.py: Fünftel-Regel) und Stakes-Leiter. Er setzt sich nie an
einen Tisch des anderen Modus. Spezifikation: tests/spielplan_spec.py.
Datei betrieb/scratch/spielplan.json {"modus": "uebung"|"echt", "tische": 1..HOECHSTENS,
"tische_bis": Obergrenze der Spanne (optional),
"budget": Chips (optional, nur Live), "maus": bool,
"zeitplan": betrieb/zeitplan.py, "geld": betrieb/geldplan.py}
Live öffnet nie blind: ohne Guthaben wählte die Lobby den weichsten Tisch in beliebiger Höhe. Das
wirksame Guthaben ist das kleinere aus dem echten (reserve_Seat) und dem Budget - mit dem Budget
deckelt man, was der Bot einsetzen darf; fehlt beides, wartet er.
"""
import json
import os
from dataclasses import dataclass, field
from typing import Optional
import formate
import geldplan
import zeitplan
from geldplan import Geldplan
from zeitplan import Zeitplan
UEBUNG, ECHT = "uebung", "echt" # wie lesen/geld.py (coinType)
REITER = {UEBUNG: "Practice Games", ECHT: "Cash Games"}
HOECHSTENS = 12 # wie geld.HOECHSTENS_TISCHE
ABSTAND = 30.0 # Sekunden zwischen zwei Versuchen, einen Tisch zu öffnen
FEHLVERSUCHE = 3 # so viele Versuche ohne neuen Tisch, dann aufgeben (warnen)
@dataclass(frozen=True)
class Spielplan:
modus: str
tische: int
budget: Optional[float] = None
maus: bool = True # Eingabe einheitlich für Lobby und Tisch: mit Maus oder ohne (hand/eingabe.py)
tische_bis: Optional[int] = None # Tischspanne tische..tische_bis, je Sitzung gewürfelt (betrieb/zeitplan.py)
zeitplan: Zeitplan = field(default_factory=Zeitplan)
geld: Geldplan = field(default_factory=Geldplan)
zeiger: bool = False # der lebende Zeiger zwischen den Zügen (hand/zeiger.py) - kann nerven
formate: tuple = () # ((format, tische), ...) in der Reihenfolge formate.ALLE; leer: nur Cash
def formate_von(plan):
"""{format: tische} - ein alter Plan ohne Formate ist Cash mit seiner Tischzahl."""
return dict(plan.formate) if plan.formate else {formate.CASH: plan.tische}
def _formate_aus(roh):
"""Formate aus der Datei: unbekannte und Unsinn fallen weg, Nullen auch; die Summe bleibt unter
HOECHSTENS (spätere Formate werden gekürzt). None, wenn keine Formatangabe da ist."""
if not isinstance(roh, dict):
return None
out, rest = [], HOECHSTENS
for fmt in formate.ALLE:
n = roh.get(fmt)
if isinstance(n, bool) or not isinstance(n, (int, float)) or n <= 0:
continue
n = min(int(n), rest)
if n > 0:
out.append((fmt, n))
rest -= n
return tuple(out)
def format_passt(plan, fmt) -> bool:
"""Darf an einem Tisch dieses Formats gesetzt werden? Ohne Plan oder Format unbekannt: kein Urteil."""
return plan is None or fmt is None or formate_von(plan).get(fmt, 0) > 0
def zeiger_lebt(plan):
"""Lebt der Zeiger? Nur eingeschaltet und mit Maus - ohne Maus bleibt dein Zeiger stehen."""
return plan is not None and plan.zeiger and plan.maus
def spanne(plan):
"""(kleinste, grösste) Tischzahl einer Sitzung."""
return plan.tische, max(plan.tische, plan.tische_bis or plan.tische)
def wirksames_guthaben(plan, guthaben):
"""Live: das kleinere aus echtem Guthaben und Budget (None: keines bekannt). Übung: None."""
if plan is None or plan.modus != ECHT:
return None
werte = [w for w in (guthaben, plan.budget) if w is not None]
return min(werte) if werte else None
def aus_dict(d) -> Optional[Spielplan]:
"""Aus der Datei/dem Knopf: unbekannter Modus oder keine Zahl -> None; Tischzahl geklemmt."""
if not isinstance(d, dict) or d.get("modus") not in REITER:
return None
n = d.get("tische")
if isinstance(n, bool) or not isinstance(n, (int, float)):
return None
b = d.get("budget")
budget = float(b) if isinstance(b, (int, float)) and not isinstance(b, bool) and b > 0 else None
maus = d.get("maus") if isinstance(d.get("maus"), bool) else True
tische = max(1, min(HOECHSTENS, int(n)))
fm = _formate_aus(d.get("formate"))
if fm is not None:
tische = sum(t for _, t in fm)
bis = d.get("tische_bis")
bis = min(HOECHSTENS, int(bis)) if isinstance(bis, (int, float)) and not isinstance(bis, bool) and bis > tische else None
return Spielplan(d["modus"], tische, budget, maus, bis,
zeitplan.aus_dict(d.get("zeitplan")), geldplan.aus_dict(d.get("geld")),
d.get("zeiger") is True, fm or ())
def lesen(pfad) -> Optional[Spielplan]:
try:
with open(pfad, encoding="utf-8") as f:
return aus_dict(json.load(f))
except (OSError, ValueError):
return None
def als_dict(plan: Spielplan) -> dict:
return {"modus": plan.modus, "tische": plan.tische, "tische_bis": plan.tische_bis, "budget": plan.budget,
"maus": plan.maus, "zeiger": plan.zeiger, "zeitplan": zeitplan.als_dict(plan.zeitplan),
"geld": geldplan.als_dict(plan.geld), **({"formate": dict(plan.formate)} if plan.formate else {})}
def schreiben(pfad, plan: Spielplan):
os.makedirs(os.path.dirname(pfad) or ".", exist_ok=True)
tmp = pfad + ".tmp"
with open(tmp, "w", encoding="utf-8") as f:
json.dump(als_dict(plan), f)
os.replace(tmp, pfad)
def naechster_schritt(plan, offen, in_arbeit, schluss, gestoppt, letzter_versuch, jetzt, fehlversuche,
guthaben=None, offen_je_format=None):
"""-> ("oeffnen", Reiter) | ("warten", Grund) | ("aufgeben", Grund). `offen`: Tische mit Fenster,
`guthaben`: das wirksame (wirksames_guthaben) - Live braucht eines. `offen_je_format`: offene
Tische je Format; damit füllt der Läufer je Format (ohne: nach der Gesamtzahl, erstes Format)."""
if plan is None:
return ("warten", "kein Spielplan")
if gestoppt:
return ("warten", "Not-Aus")
if schluss:
return ("warten", "Stop-Grenze erreicht")
if plan.tische <= 0:
return ("warten", "keine Tische geplant")
if offen >= plan.tische:
return ("warten", f"Tischzahl erreicht ({offen} von {plan.tische})")
if in_arbeit:
return ("warten", "ein Tisch wird gerade gesetzt")
if plan.modus == ECHT and guthaben is None:
return ("warten", "Live braucht ein Guthaben - Budget im Spielplan angeben")
if fehlversuche >= FEHLVERSUCHE:
return ("aufgeben", f"{fehlversuche} Versuche ohne neuen Tisch")
if letzter_versuch is not None and jetzt - letzter_versuch < ABSTAND:
return ("warten", "kurz warten bis zum nächsten Versuch")
return _format_waehlen(plan, offen_je_format)
def _format_waehlen(plan, offen_je_format):
"""Das erste Format (Reihenfolge formate.ALLE) unter seiner Zahl, dessen Reiter gemessen ist."""
gruende = []
for fmt, soll in formate_von(plan).items():
if offen_je_format is not None and offen_je_format.get(fmt, 0) >= soll:
continue
reiter, grund = formate.reiter(plan.modus, fmt)
if reiter:
return ("oeffnen", reiter)
gruende.append(grund)
return ("warten", "; ".join(gruende) or f"Tischzahl erreicht ({plan.tische})")
def modus_passt(plan, modus) -> bool:
"""Darf an einem Tisch dieses Modus gesetzt werden? Ohne Plan oder Modus unbekannt: kein Urteil."""
return plan is None or modus is None or modus == plan.modus
def darf_neuer_tisch(plan, offen):
"""Jeder Weg, der einen Tisch öffnet (Auffüllen, Selbstheilen, Find Seat), nur unter der
Tischzahl - live 23:01 öffneten Heilen und Find Seat zwei Tische über den Plan hinaus."""
return plan is None or offen < plan.tische
def ueberzaehlig(plan, raeume, sitzend):
"""Räume, die über die Tischzahl hinaus offen sind und an denen wir nicht sitzen - die
zuletzt genannten zuerst. Aufgestanden wird dafür nie."""
if plan is None:
return []
zu_viel = len(raeume) - plan.tische
if zu_viel <= 0:
return []
frei = [r for r in raeume if r not in sitzend]
return frei[-zu_viel:] if zu_viel < len(frei) else frei