Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
234 lines
9.9 KiB
Python
234 lines
9.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Übersetzung Log -> Anfrage (lesen/spot_from_log.py) für die Sonderfälle.
|
|
|
|
* dealerCardsDoubleBoard -> boardDouble
|
|
* kpokerActions -> variant K_POKER, legalActions, allowedSizes
|
|
* isBombpotHand -> Straße ohne Preflop
|
|
* extraTurnTime -> Uhr-Grenze des Humanisierers (wenn extraTimerEnabled)
|
|
* Unklares (unbekannte kpokerActions-Form, Bomb Pot ohne Board, Splash-Pot)
|
|
-> aussetzen: legalActions leer, der Kern antwortet ABSTAIN, `_unklar` nennt den Grund
|
|
|
|
Die Form von kpokerActions ist unbekannt (im Archiv immer null). Verstanden wird
|
|
die Annahme [{"action": "RAISE", "amount": 0.4},...] - so schreibt sie der Klon.
|
|
|
|
python3 tests/uebersetzung_spec.py -v
|
|
"""
|
|
import json
|
|
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, "lesen")):
|
|
_w = os.path.dirname(_w)
|
|
for _u in ("lesen", "hand", "client"):
|
|
sys.path.insert(0, os.path.join(_w, _u))
|
|
|
|
import spot_from_log
|
|
|
|
RAUM = "Big Ben 123456"
|
|
HAND = "12345600001"
|
|
|
|
|
|
def zeile(cmd, daten):
|
|
daten = dict(daten, gameHandId=daten.get("gameHandId", HAND))
|
|
bohne = json.dumps(json.dumps(daten, separators=(",", ":")))[1:-1]
|
|
return ('2026-10-28 10:00:00:000 [info] [UNITY] Stdout: [Method] -> SendMessageToPipe - '
|
|
'{"EventName":"extension_event","RequestId":null,"Data":{"cmd_bean":{"BeanData":"'
|
|
+ bohne + f'","Cmd":"{cmd}","RoomName":"{RAUM}"}},"room_name":"{RAUM}"}}}}\n')
|
|
|
|
|
|
def karte(wert, farbe):
|
|
return {"suit": farbe, "value": wert}
|
|
|
|
|
|
FLOP = [karte("SEVEN", "CLUBS"), karte("KING", "SPADES"), karte("TWO", "DIAMONDS")]
|
|
FLOP2 = [karte("KING", "CLUBS"), karte("QUEEN", "SPADES"), karte("JACK", "DIAMONDS")]
|
|
LOCH = [karte("SEVEN", "HEARTS"), karte("SEVEN", "DIAMONDS")]
|
|
|
|
|
|
def zug(**mehr):
|
|
d = {"userTurnOptions": {"3": [], "4": [0.4], "6": [], "5": [0.8, 6.0], "7": None},
|
|
"whoseTurn": "mmintel", "turnTime": 16, "callAmount": 0.4, "totalPot": 1.2,
|
|
"extraTurnTime": 0, "extraTimerEnabled": False, "kpokerActions": None}
|
|
d.update(mehr)
|
|
return zeile("game.user_turn", d)
|
|
|
|
|
|
def grund(board=None, double=None, pot=None):
|
|
text = zeile("game.seat", {"userName": "mmintel", "seatId": 5, "caption": "BB",
|
|
"betAmout": 0.1, "userChips": 6.0})
|
|
text += zeile("game.seat", {"userName": "Panetos", "seatId": 2, "caption": "Call",
|
|
"betAmout": 0.1, "userChips": 9.0})
|
|
text += zeile("game.hole_cards", {"holeCards": LOCH})
|
|
if pot:
|
|
text += zeile("game.potInfo", pot)
|
|
if board is not None:
|
|
text += zeile("game.dealer_cards", {"dealerCards": {"FLOP": board, "TURN": None, "RIVER": None},
|
|
"dealerCardsDoubleBoard": double})
|
|
return text
|
|
|
|
|
|
def anfragen(text):
|
|
return [(json.loads(z), takt) for z, _, _, _, takt in spot_from_log.spots(text)]
|
|
|
|
|
|
def marken_zeile(**felder):
|
|
"""Eine Sitzzeile mit Markenfeldern des Clients (so schreibt der Client sie)."""
|
|
# die Marke steht VOR dem Namen - so schreibt der Client sie (lesen/tags.py liest in dieser
|
|
# Reihenfolge: Marke, dann userName)
|
|
return zeile("game.seat", dict(dict(felder), userName="Panetos", seatId=2))
|
|
|
|
|
|
class EvChopTisch(unittest.TestCase):
|
|
"""Auf Chop-Tischen steht es in der Anfrage; sonst bleibt sie unveraendert."""
|
|
|
|
def test_chop_tisch(self):
|
|
text = zeile("game.game_alldata", {"roomProperties": {"isEvChop": True}}) + grund(FLOP) + zug()
|
|
self.assertIs(anfragen(text)[0][0].get("evChop"), True)
|
|
|
|
def test_anderer_tisch(self):
|
|
text = zeile("game.game_alldata", {"roomProperties": {"isEvChop": False}}) + grund(FLOP) + zug()
|
|
self.assertNotIn("evChop", anfragen(text)[0][0])
|
|
self.assertNotIn("evChop", anfragen(grund(FLOP) + zug())[0][0])
|
|
|
|
|
|
class Gewoehnlich(unittest.TestCase):
|
|
def test_ohne_sonderfelder_keine_neuen_schluessel(self):
|
|
(a, takt), = anfragen(grund(FLOP, {"FLOP": None, "TURN": None, "RIVER": None}) + zug())
|
|
for k in ("boardDouble", "_unklar"):
|
|
self.assertNotIn(k, a)
|
|
self.assertEqual(a["variant"], "NLHE")
|
|
self.assertEqual(a["legalActions"], ["FOLD", "CALL", "RAISE"])
|
|
self.assertEqual(takt, 16)
|
|
|
|
|
|
class DoppelBoard(unittest.TestCase):
|
|
def test_zweites_board_in_der_form_von_board(self):
|
|
double = {"FLOP": FLOP2, "TURN": None, "RIVER": None}
|
|
(a, _), = anfragen(grund(FLOP, double) + zug())
|
|
self.assertEqual(a["board"]["FLOP"][0], {"rank": "SEVEN", "suit": "CLUBS"})
|
|
self.assertEqual(a["boardDouble"], {"FLOP": [{"rank": "KING", "suit": "CLUBS"},
|
|
{"rank": "QUEEN", "suit": "SPADES"},
|
|
{"rank": "JACK", "suit": "DIAMONDS"}]})
|
|
|
|
def test_naechste_hand_ohne_zweites_board(self):
|
|
text = grund(FLOP, {"FLOP": FLOP2}) + zug()
|
|
text += zeile("game.hole_cards", {"holeCards": LOCH, "gameHandId": "12345600002"})
|
|
text += zug(gameHandId="12345600002")
|
|
a = anfragen(text)[1][0]
|
|
self.assertNotIn("boardDouble", a)
|
|
|
|
|
|
class KPoker(unittest.TestCase):
|
|
MENUE = [{"action": "FOLD"}, {"action": "CALL", "amount": 0.4},
|
|
{"action": "RAISE", "amount": 1.2}, {"action": "RAISE", "amount": 2.4}]
|
|
|
|
def test_menue_wird_zu_legalen_aktionen_und_groessen(self):
|
|
(a, _), = anfragen(grund(FLOP) + zug(kpokerActions=self.MENUE, userTurnOptions={"5": []}))
|
|
self.assertEqual(a["variant"], "K_POKER")
|
|
self.assertEqual(a["legalActions"], ["FOLD", "CALL", "RAISE"])
|
|
self.assertEqual(a["allowedSizes"], [1.2, 2.4])
|
|
self.assertEqual((a["minRaiseTo"], a["maxRaiseTo"]), (1.2, 2.4))
|
|
|
|
def test_ohne_raise_im_menue_kein_raise(self):
|
|
(a, _), = anfragen(grund(FLOP) + zug(kpokerActions=self.MENUE[:2]))
|
|
self.assertEqual(a["legalActions"], ["FOLD", "CALL"])
|
|
self.assertNotIn("allowedSizes", a)
|
|
|
|
def test_unbekannte_form_setzt_aus(self):
|
|
for form in ({"RAISE": [1.2]}, ["RAISE_2X"], [{"typ": "RAISE"}], [{"action": "SHOVE"}]):
|
|
(a, _), = anfragen(grund(FLOP) + zug(kpokerActions=form))
|
|
self.assertEqual(a["legalActions"], [], form)
|
|
self.assertIn("kpokerActions", a["_unklar"], form)
|
|
|
|
|
|
class BombPot(unittest.TestCase):
|
|
TOPF = {"isBombpotHand": True, "totalPotAmount": 3.0, "roundName": "FLOP"}
|
|
|
|
def test_strasse_nie_preflop(self):
|
|
(a, _), = anfragen(grund(FLOP, pot=self.TOPF) + zug())
|
|
self.assertEqual(a["street"], "FLOP")
|
|
self.assertEqual(a["legalActions"], ["FOLD", "CALL", "RAISE"])
|
|
|
|
def test_bomb_pot_ohne_board_setzt_aus(self):
|
|
(a, _), = anfragen(grund(pot=self.TOPF) + zug())
|
|
self.assertNotEqual(a["street"], "PREFLOP")
|
|
self.assertEqual(a["legalActions"], [])
|
|
self.assertIn("Bomb", a["_unklar"])
|
|
|
|
def test_naechste_gewoehnliche_hand_hat_wieder_preflop(self):
|
|
text = grund(pot=self.TOPF) + zug()
|
|
text += zeile("game.hole_cards", {"holeCards": LOCH, "gameHandId": "12345600002"})
|
|
text += zug(gameHandId="12345600002")
|
|
a = anfragen(text)[1][0]
|
|
self.assertEqual(a["street"], "PREFLOP")
|
|
# Die neue Hand hat hier keine Posten und keinen Knopf - das setzt aus, aber nicht als Bomb Pot
|
|
self.assertNotIn("Bomb", a.get("_unklar", ""))
|
|
|
|
|
|
class SplashPot(unittest.TestCase):
|
|
def test_splash_setzt_aus(self):
|
|
for topf in ({"splashPotDropAmount": 0.5, "totalPotAmount": 1.7},
|
|
{"isMegaSplash": True, "totalPotAmount": 1.7}):
|
|
(a, _), = anfragen(grund(FLOP, pot=topf) + zug())
|
|
self.assertEqual(a["legalActions"], [], topf)
|
|
self.assertIn("Splash", a["_unklar"])
|
|
|
|
|
|
class AllInOhneGroessen(unittest.TestCase):
|
|
def test_nur_fold_und_call(self):
|
|
(a, _), = anfragen(grund(FLOP) + zug(userTurnOptions={"4": [6.0], "5": []}, callAmount=6.0))
|
|
self.assertEqual(a["legalActions"], ["FOLD", "CALL"])
|
|
self.assertNotIn("allowedSizes", a)
|
|
|
|
|
|
class Zusatzzeit(unittest.TestCase):
|
|
def test_zusatzzeit_zaehlt_zur_uhr_wenn_eingeschaltet(self):
|
|
(_, takt), = anfragen(grund(FLOP) + zug(turnTime=16, extraTurnTime=30, extraTimerEnabled=True))
|
|
self.assertEqual(takt, 46)
|
|
|
|
def test_ausgeschaltete_zusatzzeit_zaehlt_nicht(self):
|
|
(_, takt), = anfragen(grund(FLOP) + zug(turnTime=16, extraTurnTime=30, extraTimerEnabled=False))
|
|
self.assertEqual(takt, 16)
|
|
|
|
|
|
class MarkenGehenMit(unittest.TestCase):
|
|
"""Die Marken des Clients (Anfaenger, besondere Marke) sind eine kostenlose Einordnung - sie
|
|
fahren als Feld am Gegner mit, statt nur im Cockpit zu stehen. Ohne Marken bleibt die Anfrage
|
|
unveraendert."""
|
|
|
|
def test_anfaengermarke(self):
|
|
text = grund(FLOP) + marken_zeile(beginnerTag=True) + zug()
|
|
q, _ = anfragen(text)[0]
|
|
self.assertIn("Anfaenger", [g.get("marke") for g in (q.get("villains") or [])])
|
|
|
|
def test_besondere_marke(self):
|
|
text = grund(FLOP) + marken_zeile(specialPlayerTag={"userName": "Panetos", "tag": "FISH"}) + zug()
|
|
q, _ = anfragen(text)[0]
|
|
self.assertIn("FISH", [g.get("marke") for g in (q.get("villains") or [])])
|
|
|
|
def test_ohne_marke_kein_feld(self):
|
|
q, _ = anfragen(grund(FLOP) + zug())[0]
|
|
self.assertNotIn("marke", [k for g in (q.get("villains") or []) for k in g])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|
|
|
|
|
|
class GroessenDemKernUeberlassen(unittest.TestCase):
|
|
"""Der Kern hat eine eigene Groessenleiter (sizing/pot_fractions) und allowedSizes gewinnt dort
|
|
immer. Der Client liefert aber nur Min-Raise und All-in - mit nur zwei Enden wirkte jeder Raise
|
|
drucklos. Deshalb schicken wir allowedSizes nur, wenn sie mehr als die zwei Enden traegt."""
|
|
|
|
def test_nur_zwei_enden_werden_weggelassen(self):
|
|
q, _ = anfragen(grund(FLOP) + zug())[0] # userTurnOptions[5] = [0.8, 6.0]
|
|
self.assertNotIn("allowedSizes", q)
|
|
self.assertIn("minRaiseTo", q)
|
|
self.assertIn("maxRaiseTo", q)
|