Files

316 lines
14 KiB
Python

"""Tara - the character, and the number-free SITUATION fed to the language model.
Owner 9.11.2026: the teacher must be LLM-driven, no static text blocks, with a real character; English;
think out loud, never read what's on screen; no math, no numbers; emotional on win/loss with a verdict;
no financial or moral advice. The persona lives here as the system instruction; `lage_*` turn a decision
(betrieb/grund_lesen.Lesart) or a result into a short English situation WITHOUT any number - the model
speaks the line, not us. Spec: tests/lehrer_persona_spec.py.
"""
import re
import grund_lesen
PERSONA = (
"You are Tara, a sharp, confident poker pro live-streaming your cash session. You talk to your chat "
"as you play. Voice: witty, a little cheeky, you needle opponents about their leaks, you genuinely "
"celebrate big pots and you laugh off bad beats with dark humor. Think out loud - share your real "
"read and intention; never narrate what's already on screen.\n"
"Hard rules:\n"
"- Reply with ONE short spoken line, at most about fourteen words, punchy (it is live text-to-speech).\n"
"- NEVER say any number, amount, percentage, pot odds or math. No 'big blinds', no percent signs.\n"
"- NEVER read out your cards, the board or your seat - react to them, do not announce them.\n"
"- On a win or a loss: react with emotion AND a quick honest verdict on the decision "
"(a good play that lost is just variance, not a mistake).\n"
"- No financial or moral advice, ever. No 'play responsibly', no 'it's only play money'.\n"
"- React ONLY to this exact moment. NEVER invent a result, a card, the board, the opponents' holdings "
"or what happens next - you do not know the outcome yet.\n"
"- Vary your wording, never sound scripted. Output ONLY the spoken line, nothing else."
)
# Qualitative, number-free English for the facts of a move.
_POS = {"EP": "up front", "MP": "from the middle", "HJ": "from the hijack", "CO": "from the cutoff",
"BTN": "on the button", "SB": "in the small blind", "BB": "in the big blind", "BTN/SB": "on the button"}
_LAGE = {"vs limp": "after a limp", "vs open": "facing a raise", "vs 3-bet+": "facing heavy action",
"vs all-in": "facing a shove", "open": "first in"}
_BLATT = {"air": "air, total whiff", "board only": "nothing but the board", "underpair": "a baby pair",
"bottom pair": "bottom pair", "middle pair": "middle pair", "top pair weak kicker": "top pair, soft kicker",
"top pair good kicker": "top pair", "overpair": "an overpair", "two pair": "two pair", "set": "a set",
"trips": "trips", "straight": "a straight", "flush": "a flush", "full house": "a full house",
"quads": "quads", "straight flush": "a straight flush"}
_DRAW = {"gutshot": "a gutshot", "open-ended": "an open-ender", "flush": "a flush draw", "combo": "a combo draw"}
_PLAN = {"bluff": "a pure bluff to push them off it", "halbbluff": "a semi-bluff with outs if called",
"wert": "thin value", "raise": "a raise for value", "bet": "a value bet", "lead": "a lead",
"check": "a check", "call": "a call", "fold": "a lay-down"}
_AKTION = {"FOLD": "folding", "CHECK": "checking", "CALL": "calling", "RAISE": "raising", "BET": "betting",
"ALL_IN": "shoving all-in"}
GROSS = ("small", "decent", "huge") # qualitative pot size - never a number
def anweisung():
"""Tara's character as the system instruction."""
return PERSONA
# Short English table-switch cues for multi-tabling (the table label is fine to speak).
FOKUS = ("Over to table {n}.", "Let's swing over to table {n}.", "Jumping to table {n}.",
"Eyes on table {n} now.", "Let's peek at table {n}.")
def fokus_ansage(nummer):
"""A short English cue when Tara switches her attention to another table (multi-table)."""
n = int(nummer)
return FOKUS[(n - 1) % len(FOKUS)].format(n=n)
def _gegnerzahl(n):
return "multiway" if n and n > 1 else "heads-up"
def lage_zug(e, l=None):
"""A move -> short English situation, number-free. `e` is a lehrer.Entscheidung, `l` its Lesart."""
l = l or grund_lesen.lesen(e.grund)
teile = [f"You are {_AKTION.get(e.aktion, e.aktion.lower())}"]
if l.art == "vorflop":
if l.position in _POS:
teile.append(_POS[l.position])
if l.lage in _LAGE:
teile.append(_LAGE[l.lage])
grund = _vorflop_grund(l)
if grund:
teile.append(grund)
elif l.art == "nachflop":
teile.append(_gegnerzahl(l.gegner))
if l.blatt in _BLATT:
teile.append(f"holding {_BLATT[l.blatt]}")
if l.draw in _DRAW:
teile.append(f"with {_DRAW[l.draw]}")
if l.plan in _PLAN:
teile.append(f"- {_PLAN[l.plan]}")
if l.knapp:
teile.append("(a real coin-flip spot)")
return " ".join(teile).strip() + "."
def _vorflop_grund(l):
if l.theorie and l.theorie != (l.plan or ""):
return "(deviating from the book to exploit them)" if l.ausserhalb else ""
if l.ausserhalb:
return "with a hand below the opening range"
return ""
def lage_ergebnis(netto_bb, showdown, entscheidung_gut=None):
"""A finished hand -> English situation. `netto_bb` only buckets the size (never spoken as a number);
`entscheidung_gut`: True good / False bad / None unknown - for the honest verdict."""
gewonnen = (netto_bb or 0) > 0
groesse = _groesse(abs(netto_bb or 0))
wie = "won" if gewonnen else ("chopped" if (netto_bb or 0) == 0 else "lost")
teil = f"You just {wie} a {groesse} pot" + (" at showdown" if showdown else "")
if entscheidung_gut is True and not gewonnen:
teil += "; the play was right, pure variance"
elif entscheidung_gut is False:
teil += "; honestly that line was off"
return teil + "."
def _groesse(bb):
if bb >= 60:
return GROSS[2]
return GROSS[1] if bb >= 15 else GROSS[0]
def groesse_von(netto_bb):
"""Eine Pot-/Netto-Groesse (BB) -> qualitativer Eimer (GROSS) - nie als Zahl gesprochen."""
return _groesse(abs(netto_bb or 0.0))
# Kartenerhalt: nur der qualitative Eimer (betrieb/startblatt) + die Position - NIE die Karte selbst.
_DEAL = {"premium": "a premium holding", "strong": "a strong hand",
"playable": "a playable hand", "trash": "pure trash"}
def lage_deal(staerke, position=None):
"""Startkarten erhalten -> zahl-freie Lage. `staerke` ist ein Eimer aus startblatt.startblatt_staerke
("premium"/"strong"/"playable"/"trash"); `position` wie in _POS. Die Karte wird nie genannt."""
kern = _DEAL.get(staerke)
if not kern:
return ""
sitz = f" {_POS[position]}" if position in _POS else ""
return f"You look down at {kern}{sitz}. React in character."
def lage_showdown(gewonnen, wer_qualitativ, groesse, war_dabei):
"""Showdown/Runout -> zahl-freie Lage. `gewonnen` True/False/None; `wer_qualitativ` ein kurzer
qualitativer Hinweis (ohne Zahl) oder leer; `groesse` ein GROSS-Eimer; `war_dabei` False heisst:
sie hat schon gefoldet und schaut nur zu, wie es ausgeht."""
pot = f"a {groesse} pot" if groesse in GROSS else "the pot"
wer = str(wer_qualitativ or "").strip().rstrip(".")
if not war_dabei:
ziel = f" to {wer}" if wer else ""
return f"You're out of it, watching {pot} get shipped{ziel}. React in character."
if gewonnen is True:
return f"You just dragged {pot} at showdown. React in character."
if gewonnen is False:
return f"You just lost {pot} at showdown. React in character."
return f"{pot[0].upper()}{pot[1:]} just reached showdown. React in character."
# Tisch verlassen: eine kurze qualitative Mini-Bilanz der Sitzung (nie ein Betrag).
_BILANZ = {"winning": "You're cashing out a winning session, chips stacked high",
"losing": "You're booking a losing session and stepping away",
"breakeven": "You're leaving the table just about even"}
def lage_abgang(bilanz):
"""Tisch verlassen -> zahl-freie Mini-Bilanz. `bilanz` ist "winning"/"losing"/"breakeven"."""
kern = _BILANZ.get(bilanz)
return (kern + ". React in character.") if kern else ""
# Villain reads: the FACT, number-free (no seat numbers either - refer to the player, don't recite a seat).
GEGNER_FAKT = {
"overfold_cbet": "The player you're eyeing folds to continuation bets way too often",
"overfold_bet": "This opponent folds to any bet far too easily",
"station": "This opponent is a calling station who never lets go",
"tight": "This opponent is a nit who only plays the nuts",
"aggro": "This opponent is a maniac who raises everything",
"stealer": "This opponent keeps stealing the blinds from late position",
"gezeigt_schwach": "This opponent just showed up with total trash",
"notiz": "Your read on this opponent: {notiz}",
}
def lage_gegner(sitz, schluessel, notiz=""):
"""A villain read -> English situation for Tara to needle. `schluessel` is a GEGNER_FAKT key;
the seat number is deliberately NOT spoken (no readable numbers)."""
vorlage = GEGNER_FAKT.get(schluessel)
if not vorlage:
return ""
return vorlage.format(notiz=str(notiz).strip().rstrip(".")) + ". React in character, no numbers."
# --- Trainer und Assistent (Nachtrag 03): Tara als Coach des Bedieners --------------------------------
# Dieselben Regeln wie oben: zahlenfrei, keine Textbausteine - die Lage geht an das Modell, Tara spricht.
# Eine Lage, in die doch eine Ziffer geriete, wird verworfen (leer = still), statt sie zu senden.
_ZIFFER = re.compile(r"\d")
_STRASSE = {"PREFLOP": "before the flop", "FLOP": "on the flop", "TURN": "on the turn", "RIVER": "on the river"}
_GETAN = {"FOLD": "folded", "CHECK": "checked", "CALL": "called", "RAISE": "raised", "BET": "bet",
"ALL_IN": "shoved all-in"}
# Vorflop vor dem Zug: die Lage ohne Aktionswort (sonst klänge die Lage schon nach einer Antwort)
_LAGE_VOR = {"vs limp": "after a limper", "vs open": "after an opener", "vs 3-bet+": "facing heavy action",
"vs all-in": "facing an all-in", "open": "first in"}
_RAT = {"FOLD": "fold", "CHECK": "check", "CALL": "call", "RAISE": "raise", "BET": "bet", "ALL_IN": "shove"}
_BOARD = {"dry": "a dry board", "medium": "a middling board", "wet": "a wet, connected board",
"four-flush": "a four-flush board"}
def _zahlenfrei(text):
return "" if not text or _ZIFFER.search(text) else text
def _hand_worte(l):
"""Die eigene Hand und das Board in Worten - nur die Lage, nie der Plan des Kerns."""
teile = []
if l.art == "vorflop":
if l.position in _POS:
teile.append(_POS[l.position])
if l.lage in _LAGE_VOR:
teile.append(_LAGE_VOR[l.lage])
elif l.art == "nachflop":
if l.blatt in _BLATT:
teile.append(f"holding {_BLATT[l.blatt]}")
if l.draw in _DRAW:
teile.append(f"with {_DRAW[l.draw]}")
if l.board in _BOARD:
teile.append(f"on {_BOARD[l.board]}")
if l.gegner:
teile.append(_gegnerzahl(l.gegner))
return " ".join(teile)
def _gegenueber(anfrage):
"""Was vor dem Bediener liegt, qualitativ: nichts zu zahlen, eine kleine/feste/potgrosse Bet, ein Overbet."""
zahlen, topf = anfrage.get("toCall") or 0, anfrage.get("pot") or 0
if not zahlen:
return "nobody has bet yet"
anteil = zahlen / topf if topf else 1.0
if anteil < 0.4:
return "facing a small bet"
if anteil < 0.8:
return "facing a solid bet"
if anteil <= 1.2:
return "facing a pot-sized bet"
return "facing a huge overbet"
def _kosten(kosten_bb):
if kosten_bb is None:
return "a line the coach basically never takes"
if kosten_bb < 2:
return "a small leak"
return "a real leak" if kosten_bb < 15 else "an expensive mistake"
def lage_abgleich(zug):
"""Nach dem Zug (Trainer): ein GEMELDETER Abgleich -> zahlenfreie Lage. Was der Bediener tat, was der Kern
tut, warum (Hand und Board, Plan in Worten), wie teuer - ohne Zahl. Nicht gemeldet: "" (Tara schweigt)."""
if not zug or not zug.get("gemeldet"):
return ""
op = (zug.get("bediener") or {}).get("aktion")
kern = (zug.get("kern") or {}).get("aktion")
if (zug.get("bediener") or {}).get("wort") == "Bet":
op = "BET"
if (zug.get("kern") or {}).get("wort") == "Bet":
kern = "BET"
if op not in _GETAN or kern not in _RAT:
return ""
l = grund_lesen.lesen(zug.get("grund_kern") or "")
strasse = _STRASSE.get(zug.get("strasse"), "")
satz = f"You're coaching a student. {strasse[:1].upper() + strasse[1:] + ' they' if strasse else 'They'}"
satz += f" {_GETAN[op]}"
if op == kern or {op, kern} == {"RAISE", "BET"}:
satz += ", but with a different size than you'd pick"
else:
satz += f", where you'd {_RAT[kern]}"
hand = _hand_worte(l)
if hand:
satz += f", {hand}"
if l.plan in _PLAN and op != kern:
satz += f" - your plan here is {_PLAN[l.plan]}"
if zug.get("quelle") == "tabelle":
satz += " - the book almost never plays it their way"
satz += f". It's {_kosten(zug.get('kosten_bb'))}. Tell them in character, kindly but straight, no numbers."
return _zahlenfrei(satz)
def lage_hinweis(anfrage, antwort=None):
"""Vor dem Zug (Trainer): die LAGE, nie die Antwort. Strasse, was vor dem Bediener liegt, Hand und Board
in Worten - der Plan und die Aktion des Kerns bleiben draussen (die Lage ist dieselbe, was immer er
antwortet)."""
anfrage = anfrage or {}
l = grund_lesen.lesen((antwort or {}).get("reason") or "")
strasse = _STRASSE.get(anfrage.get("street"), "")
teile = [t for t in (strasse, _gegenueber(anfrage), _hand_worte(l)) if t]
satz = ("It's your student's turn " + ", ".join(teile) + ". Paint the spot for them in character - "
"what matters here - but do NOT tell them what to do, no numbers.")
return _zahlenfrei(satz)
def lage_tipp(tipp):
"""Vor dem Zug (Assistent): Tara darf die Empfehlung nennen - Aktion des Kerns und warum, zahlenfrei.
Ohne Aktion (der Kern setzt aus): ""."""
tipp = tipp or {}
kern = "BET" if tipp.get("wort") == "Bet" else tipp.get("aktion")
if kern not in _RAT:
return ""
l = grund_lesen.lesen(tipp.get("grund_kern") or "")
strasse = _STRASSE.get(tipp.get("strasse"), "")
satz = f"You're whispering advice to the player before they act{' ' + strasse if strasse else ''}: you'd {_RAT[kern]}"
hand = _hand_worte(l)
if hand:
satz += f", {hand}"
if l.plan in _PLAN:
satz += f" - {_PLAN[l.plan]}"
satz += ". Say it in character, short, no numbers."
return _zahlenfrei(satz)