"""Platz-Gegner fuer tisch6: uebersetzt die Vertragsanfrage in den Gegnerdienst des Trainers (pool/station/nit/reg/maniac). py:pool_gegner.py (Sitzung fest; die Person haengt an der Kennung) """ import json import os import subprocess import sys W = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")) EXE = os.path.join(W, "entscheiden", "motor", "target", "pokerbench-motor-gegner.exe") RK = {"TWO": "2", "THREE": "3", "FOUR": "4", "FIVE": "5", "SIX": "6", "SEVEN": "7", "EIGHT": "8", "NINE": "9", "TEN": "T", "JACK": "J", "QUEEN": "Q", "KING": "K", "ACE": "A"} k = lambda c: RK[c["rank"]] + c["suit"][0].lower() def lage(q, kenn, typ): bb, ich, n, st = q["bigBlind"], q["heroSeat"], q["seats"], q["street"] h = [e for e in q["history"] if e["street"] == st] ein, hoch, schritt = {}, 0.0, 1 raises = limper = eigene = 0 pf = None for e in q["history"]: if e["street"] == "PREFLOP" and e["action"] in ("RAISE", "BET", "ALL_IN"): pf = e["seat"] wetten, erster = 0, None for e in h: a = e["action"] if e.get("amount") is not None: ein[e["seat"]] = e["amount"] if a in ("RAISE", "BET", "ALL_IN"): raises += 1 eigene += e["seat"] == ich wetten += 1 erster = erster or e["seat"] if a == "CALL" and st == "PREFLOP" and raises == 0: limper += 1 hoch = max(hoch, ein.get(e["seat"], 0)) dabei = [v["seat"] for v in q["villains"] if not v.get("folded")] ab = lambda s: (s - q["buttonSeat"] - 1) % n # 0 = SB, n-1 = Button pos = ["SB", "BB", "UTG", "HJ", "CO", "BTN"][ab(ich)] d = {"id": kenn, "typ": typ, "sitzung": 1, "seed": q["seed"], "karten": [k(c) for c in q["heroCards"]], "board": [k(c) for s in ("FLOP", "TURN", "RIVER") for c in q["board"].get(s, [])], "topf": q["pot"] / bb, "eigener_einsatz": ein.get(ich, 0) / bb, "zu_zahlen": q["toCall"] / bb, "strasse": st.lower(), "gegner": len(dabei), "in_position": all(ab(s) < ab(ich) for s in dabei), "position": pos, "raises": raises, "limper": limper, "eigene_raises": eigene, "hoch": max(hoch / bb, 1.0) if st == "PREFLOP" else hoch / bb, "cbet": st == "FLOP" and wetten == 1 and erster == pf and pf != ich, "dreibet": st == "PREFLOP" and eigene > 0 and q["toCall"] > 0, "gecheckt": any(e["seat"] == ich and e["action"] == "CHECK" for e in h)} if "RAISE" in q["legalActions"]: d["min_raise"], d["max_raise"] = q["minRaiseTo"] / bb, q["maxRaiseTo"] / bb return d class Pool: def __init__(self): self.p = subprocess.Popen([EXE], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True, encoding="utf-8", bufsize=1, creationflags=0x4000) def zug(self, q, kenn, typ): self.p.stdin.write(json.dumps(lage(q, kenn, typ)) + "\n") self.p.stdin.flush() a = json.loads(self.p.stdout.readline()) if "fehler" in a: raise RuntimeError(a) t = a["aktion"] return {"action": t.upper(), "size": a["betrag"] * q["bigBlind"] if t == "raise" else None, "reason": typ}