218 lines
8.9 KiB
Python
218 lines
8.9 KiB
Python
"""Regeln eines Tisches aus `roomProperties` - was dieser Tisch anders macht als Standard.
|
|
|
|
Quelle der Namen: Client-Code (`archiv/mitschrieb/CLIENT-LUECKEN.md`), Form aus dem
|
|
Log. Reine Funktion; Spezifikation: tests/funde_spec.py.
|
|
|
|
regeln(text) -> dict der Schalter, die gesetzt sind klartext(regeln) -> ein Satz
|
|
|
|
Dazu die **Sonderregel-Tafel** weiter unten: welche Sonderfaelle traegt ein Raum - aus den
|
|
Raumdaten UND aus dem Namen. Spezifikation: tests/tischregeln_spec.py.
|
|
"""
|
|
import re
|
|
|
|
import evchop
|
|
|
|
SCHALTER = {
|
|
"mustShow": ("must_show", "man muss aufdecken"),
|
|
"anonymous": ("anonymous", "Namen verdeckt"),
|
|
"noLimp": ("no_limp", "kein Limp - pot-gross oder folden"),
|
|
"isNoLimp": ("no_limp", "kein Limp - pot-gross oder folden"),
|
|
"straddle": ("straddle", "Straddle moeglich"),
|
|
"antiBanking": ("anti_banking", "Anti-Banking mit Frist"),
|
|
"evCashout": ("ev_cashout", "EV-Auszahlung im All-in"),
|
|
"isEvChop": ("ev_chop", "EV-Chop moeglich"),
|
|
"splash": ("splash", "Splash-Pot"),
|
|
"bombPot": ("bomb_pot", "Bomb Pot"),
|
|
"kPoker": ("k_poker", "K-Poker-Menue"),
|
|
"isBombpotHand": ("bomb_pot_hand", "diese Hand ist ein Bomb Pot"),
|
|
"dynamicRakeBattleCap": ("dynamic_rake", "Rake-Cap haengt am Battle"),
|
|
}
|
|
|
|
|
|
def regeln(text):
|
|
t = (text or "").replace('\\"', '"')
|
|
raus = {}
|
|
for muster, (name, satz) in SCHALTER.items():
|
|
if re.search(rf'"{muster}"\s*:\s*(true|True|1)|"{muster}"\s*:\s*\{{', t):
|
|
raus[name] = satz
|
|
for muster, name in (("ante", "ante"), ("minPotPf", "min_pot_vorflop")):
|
|
m = re.search(rf'"{muster}"\s*:\s*([\d.]+)', t)
|
|
if m and float(m.group(1)) > 0:
|
|
raus[name] = float(m.group(1))
|
|
return raus
|
|
|
|
|
|
def klartext(r):
|
|
if not r: return "Standardtisch"
|
|
fest = [v for v in r.values() if isinstance(v, str)]
|
|
zahlen = [f"{k}={v:g}" for k, v in r.items() if isinstance(v, float)]
|
|
return " · ".join(fest + zahlen)
|
|
|
|
|
|
STARTS = ("LIMP", "MIN", "POT", "FOLD")
|
|
|
|
|
|
def startarten(text):
|
|
"""Welche Startarten dieser Tisch zulaesst.
|
|
|
|
An einem No-Limp-Tisch faellt Limpen und das kleine Open weg: pot-gross oder folden
|
|
(`AppStaticConfig.noLimpConfig`, Tischfeld `isNoLimp`).
|
|
"""
|
|
return ("POT", "FOLD") if regeln(text).get("no_limp") else STARTS
|
|
|
|
|
|
def start_erlaubt(text, art):
|
|
"""Darf ein uneroeffneter Topf so angegangen werden?"""
|
|
return (art or "").upper() in startarten(text)
|
|
|
|
|
|
def pot_raise_to(anfrage):
|
|
"""Ein pot-grosser Raise: auf den Call noch den Topf draufsetzen - gedeckelt."""
|
|
pot = anfrage.get("pot") or 0.0
|
|
toCall = anfrage.get("toCall") or 0.0
|
|
ziel = pot + 2 * toCall
|
|
if anfrage.get("minRaiseTo"):
|
|
ziel = max(ziel, anfrage["minRaiseTo"])
|
|
if anfrage.get("maxRaiseTo"):
|
|
ziel = min(ziel, anfrage["maxRaiseTo"])
|
|
return round(ziel, 4)
|
|
|
|
|
|
def no_limp_anpassen(anfrage, antwort, zahlen):
|
|
"""Der erste freie Einsatz an einem No-Limp-Tisch: pot-gross oder folden.
|
|
|
|
Ein Limp (Call, wenn noch nichts eroeffnet ist) und ein zu kleines Open werden zu einem
|
|
pot-grossen Raise. Wer schon einem Raise gegenuebersteht, ist nicht mehr der erste freie
|
|
Einsatz - sein Call bleibt. Ohne den Schalter bleibt alles, wie der Kern es gesagt hat.
|
|
"""
|
|
if not (zahlen or {}).get("kein_limp"):
|
|
return antwort
|
|
if (anfrage.get("street") or "").upper() != "PREFLOP":
|
|
return antwort
|
|
toCall = anfrage.get("toCall") or 0.0
|
|
bb = anfrage.get("bigBlind") or 0.0
|
|
eroeffnet = toCall > 0 and toCall > bb + 1e-9 # ein Raise steht schon im Topf
|
|
if toCall <= 0 or eroeffnet:
|
|
return antwort
|
|
art = (antwort.get("action") or "").upper()
|
|
if "RAISE" not in (anfrage.get("legalActions") or []):
|
|
if art != "CALL": # Fold oder Aussetzen bleibt
|
|
return antwort
|
|
return dict(antwort, action="FOLD", size=None,
|
|
reason=(antwort.get("reason") or "").strip() + " | kein Limp: kein Raise moeglich")
|
|
ziel = pot_raise_to(anfrage)
|
|
if art == "RAISE" and (antwort.get("size") or 0.0) >= ziel - 1e-9:
|
|
return antwort # schon pot-gross oder groesser
|
|
if art not in ("CALL", "RAISE"):
|
|
return antwort
|
|
return dict(antwort, action="RAISE", size=ziel,
|
|
reason=(antwort.get("reason") or "").strip() + " | kein Limp: pot-gross statt Limp")
|
|
|
|
|
|
def antwort_an_tisch(antwort, anfrage, zahlen):
|
|
"""Die Antwort des Kerns an die Regeln dieses Tisches anpassen.
|
|
|
|
No-Limp zuerst (der erste freie Einsatz ist pot-gross oder folden), dann das RIT-Fenster.
|
|
Beides greift nur, wenn der Tisch es sagt - sonst kommt die Antwort unveraendert zurueck.
|
|
"""
|
|
return evchop.rit_anpassen(tischregeln_no_limp(antwort, anfrage, zahlen), anfrage, zahlen)
|
|
|
|
|
|
def tischregeln_no_limp(antwort, anfrage, zahlen):
|
|
"""Nur die No-Limp-Regel - eigener Name, damit die Reihenfolge lesbar bleibt."""
|
|
return no_limp_anpassen(anfrage, antwort, zahlen)
|
|
|
|
|
|
# ---- Sonderregel-Tafel ----
|
|
#
|
|
# Der Katalog der Sonderfaelle auf den Tischen. Zwei Quellen, beide noetig und beide belegt:
|
|
# die maschinenlesbaren Raumdaten (`roomProperties`) UND der Raumname. Der Name nennt Teile, die
|
|
# es als Feld nicht gibt (HU, MAX, MS, PLO5, PLO6); die Daten nennen Schalter, die der Name
|
|
# verschweigt. Geraten wird nichts: fehlt die Quelle, fehlt das Merkmal.
|
|
#
|
|
# aus_daten(rp) -> Merkmale aus den Feldern (Wert True oder die Ante-Zahl)
|
|
# aus_name(name) -> Merkmale aus den Namensteilen
|
|
# tafel(rp, name) -> {Merkmal: (Wert, Quelle)} mit Quelle "daten", "name" oder "beide"
|
|
# klartext_tafel(tafel) -> ein Satz
|
|
MERKMALE = {
|
|
"rit": "Run-it-twice angeboten", "ev_chop": "EV-Chop angeboten", "ante": "Ante im Topf",
|
|
"no_limp": "kein Limp - pot-gross oder folden", "k_poker": "K-Poker-Menue",
|
|
"must_show": "Aufdecken verlangt", "bomb_pot": "Bomb Pot",
|
|
"doppelbrett": "zweites Brett (Double Board)", "straddle": "Straddle moeglich",
|
|
"anonym": "Namen verdeckt", "mega_splash": "Mega-Splash", "plo5": "PLO5 - fuenf Lochkarten",
|
|
"plo6": "PLO6 - sechs Lochkarten", "hu": "Kopf-an-Kopf", "max": "Sieben-Max-Tisch",
|
|
}
|
|
FELDER = {
|
|
"isEVChopAllowed": "ev_chop", "isNoLimp": "no_limp", "isKPoker": "k_poker",
|
|
"isMustShowEnabled": "must_show", "isBombpot": "bomb_pot",
|
|
"bombpotInducesDoubleBoard": "doppelbrett", "isDoubleBoard": "doppelbrett",
|
|
"isStraddle": "straddle", "isAnonymous": "anonym",
|
|
}
|
|
NAMENSTEILE = {
|
|
"INRIT": "rit", "EV": "ev_chop", "ANTE": "ante", "NOLP": "no_limp", "KP": "k_poker",
|
|
"MS": "mega_splash", "PLO5": "plo5", "PLO6": "plo6", "HU": "hu", "MAX": "max",
|
|
}
|
|
|
|
|
|
def _rit_optionen(wert):
|
|
"""Bietet der Raum Run-it-twice an? `iRitOptions` ist eine Liste oder ein Komma-Text; nur
|
|
eine Option groesser Null zaehlt (`[0]` ist "aus", `[0,1,2]` ist "once/twice/any")."""
|
|
if isinstance(wert, (list, tuple)):
|
|
return any(str(x).strip().isdigit() and int(x) > 0 for x in wert)
|
|
if isinstance(wert, str):
|
|
return any(t.strip().isdigit() and int(t) > 0 for t in wert.split(","))
|
|
return False
|
|
|
|
|
|
def aus_daten(rp):
|
|
"""Sonderfaelle aus den Raumdaten (`roomProperties`). Nur gesetzte Felder, plus die Ante-Zahl."""
|
|
rp = rp or {}
|
|
raus = {}
|
|
for feld, merkmal in FELDER.items():
|
|
if rp.get(feld) is True:
|
|
raus[merkmal] = True
|
|
if _rit_optionen(rp.get("iRitOptions")):
|
|
raus["rit"] = True
|
|
ante = rp.get("ante")
|
|
if isinstance(ante, (int, float)) and ante > 0:
|
|
raus["ante"] = float(ante)
|
|
return raus
|
|
|
|
|
|
def aus_name(name):
|
|
"""Sonderfaelle aus den Namensteilen des Raums (`ANTE`, `NOLP`, `PLO6`, `MS`...).
|
|
|
|
Getrennt an Nicht-Buchstaben/-Ziffern; ein Teil trifft als ganzes Wort oder als Endung
|
|
(so faengt `7MAX` den Teil `MAX`, `"NL"` aber nicht `NOLP`)."""
|
|
teile = [t for t in re.split(r"[^A-Za-z0-9]+", (name or "").upper()) if t]
|
|
raus = {}
|
|
for teil, merkmal in NAMENSTEILE.items():
|
|
if any(t == teil or t.endswith(teil) for t in teile):
|
|
raus[merkmal] = True
|
|
return raus
|
|
|
|
|
|
def tafel(rp, name=None):
|
|
"""Welche Sonderfaelle hat dieser Raum - aus den Daten UND aus dem Namen, mit Quelle je Merkmal.
|
|
|
|
-> {Merkmal: (Wert, Quelle)}; `Wert` ist der Datenwert, wo es einen gibt (sonst True).
|
|
Sortiert nach Merkmal, Eingaben bleiben unveraendert."""
|
|
aus_d, aus_n = aus_daten(rp), aus_name(name)
|
|
raus = {}
|
|
for merkmal in set(aus_d) | set(aus_n):
|
|
beide = merkmal in aus_d and merkmal in aus_n
|
|
quelle = "beide" if beide else ("daten" if merkmal in aus_d else "name")
|
|
raus[merkmal] = (aus_d.get(merkmal, True), quelle)
|
|
return dict(sorted(raus.items()))
|
|
|
|
|
|
def klartext_tafel(t):
|
|
"""Die Tafel als ein Satz - je Merkmal Wert (wenn Zahl) und Quelle."""
|
|
if not t:
|
|
return "Standardtisch"
|
|
teile = []
|
|
for merkmal, (wert, quelle) in t.items():
|
|
wie = f"{merkmal}={wert:g}" if isinstance(wert, float) else merkmal
|
|
teile.append(f"{wie} ({quelle})")
|
|
return " · ".join(teile)
|