Files
pokerfreak/messung/pruef/tisch6_pool.py
T
mmintelandClaude Opus 5.5 1baada20c7 Merge claude/motor-gedaechtnis-fc711d (Gedaechtnis 2.0, Schnittstelle antwort_auf) in den FBL-Strang
Konflikte: BEKANNTE_SCHALTER vereint (MOTOR_FBL, MOTOR_FBL_TAFEL, MOTOR_GED_FBL), mod-Liste vereint, tisch6_pool TISCH_KAPPE neben TISCH_VERGLEICH, riverbr/KARTE.md unser Stand (fertig).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 09:32:16 +01:00

112 lines
5.4 KiB
Python

"""Motor (neu: alle Regeln / alt: alle aus) gegen den Trainer-Pool, gleiche Karten, gleiche Gegner, gleiche Saat.
tisch6_pool.py <von> <bis> <aus.jsonl> neu|neu0|stat <typen.json oder -> [typ]
Blatt b: fuenf Gegner aus 60 festen Personen; der Motor sitzt einmal auf jedem Platz. neu0 = Regeln an, Typ unbekannt.
Alt wird nur dort nachgespielt, wo eine Regel den Zug geaendert hat (`vor`); sonst ist das Ergebnis gleich.
"""
import json
import os
import random
import subprocess
import sys
import os, sys; sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../motor")); import sicher as SI
import pool_gegner as G
import tisch6 as T
von, bis, aus, arm, typd = int(sys.argv[1]), int(sys.argv[2]), sys.argv[3], sys.argv[4], sys.argv[5]
feld = sys.argv[6] if len(sys.argv) > 6 else "pool"
TYP = json.load(open(typd)) if typd != "-" else {}
env = {**os.environ, "RAYON_NUM_THREADS": os.environ.get("TISCH_FAEDEN", "2")}
D = T.D
motor = None
if arm != "stat":
motor = subprocess.Popen([os.path.join(T.T, os.environ.get("TISCH_EXE", "pokerbench-motor-pool.exe")), "dienst", "sechs100", D, "2000-600-400", "200", D + "/sechs100-v2.bin",
"genau", "hu=%s/hu100-v1.bin,%s/hu200-v2.bin" % (D, D)], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, env=env, text=True, encoding="utf-8", bufsize=1, creationflags=0x08004000)
T.ohne_eco(motor)
pool = G.Pool()
JAM = os.environ.get("TISCH_JAM") == "1"
# TISCH_VERGLEICH=riverbr (27.11.): alt = derselbe Motor ohne RIVERBR (Regeln bleiben an), nachgespielt nur wo RIVERBR kippte
# TISCH_KAPPE=1 (mit MOTOR_KAPPE=p): Vergleich nur der Kappe; alt = gleicher Motor ohne Kappe, Regeln bleiben an
VOR, AUS_ALT = ("vor_kappe", "ohne_kappe") if os.environ.get("TISCH_KAPPE") == "1" else {"riverbr": ("vor_riverbr", "ohne_riverbr"), "fbl": ("vor_fbl", "ohne_fbl")}.get(os.environ.get("TISCH_VERGLEICH", ""), ("vor", "nackt"))
# TISCH_PERSONEN=h: Holdout-Personen h0..h59 (eingefroren, nie zum Einstellen benutzt); sonst p0..p59
PERS = os.environ.get("TISCH_PERSONEN", "p")
# TISCH_GEGNER (27.11., Schutz gegen Starke): "motor" = die fuenf Gegner sind derselbe Motor ohne RIVERBR (eigene Anfrage,
# kein Gedaechtnis-Name), "py:<skript> <args>" = fremder Dienst je Zeile (z. B. SHARINGAN ueber sh6.py); sonst Pool-Personen
GEGNER = os.environ.get("TISCH_GEGNER", "")
fremd = None
if GEGNER.startswith("py:"):
fremd = subprocess.Popen([sys.executable, "-I"] + GEGNER[3:].split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True,
encoding="utf-8", bufsize=1, creationflags=0x08004000)
T.ohne_eco(fremd)
sitze, memo, alt, regeln = [], {}, [False], []
def frage(sp, q):
if sp.startswith("jam"): # geht jede Hand all-in
return {"action": "RAISE", "size": q["maxRaiseTo"]} if "RAISE" in q["legalActions"] else {"action": "CALL" if q["toCall"] > 0 else "CHECK"}
if sp != "motor" and GEGNER:
q = dict(q, ohne_riverbr=True, ohne_fbl=True)
p = fremd or motor
p.stdin.write(json.dumps(q) + "\n")
p.stdin.flush()
a = json.loads(p.stdout.readline())
if a.get("action") not in q["legalActions"]:
raise RuntimeError((q, a))
return a
if sp != "motor":
return pool.zug(q, sp, feld)
for v in q["villains"]:
v["vw"] = sitze[v["seat"] - 1]
t = TYP.get(sitze[v["seat"] - 1]) if arm == "neu" else None
if t:
v["typ"], v["typF"] = t
k = json.dumps(q["history"])
if alt[0]:
if k in memo:
a = dict(memo[k])
if VOR in a:
a["action"], a["size"] = a[VOR]
return a
q[AUS_ALT] = True
motor.stdin.write(json.dumps(q) + "\n")
motor.stdin.flush()
a = json.loads(motor.stdout.readline())
if a.get("action") not in q["legalActions"]:
raise RuntimeError((q, a))
if not alt[0]:
memo[k] = a
if VOR in a:
regeln.append([q["street"], a[VOR][0], a["action"], a["reason"].split(";")[0][:90]])
return a
T.frage = frage
with open(aus, "a", encoding="utf-8") as f:
for b in range(von, bis):
rng = random.Random(777000 + b)
blatt = T.DECK[:]
rng.shuffle(blatt)
g = rng.sample([PERS + "%d" % i for i in range(60)], 6)
for platz in range(6):
sitze[:] = [("motor" if i == platz and arm != "stat" else g[i]) for i in range(6)]
if JAM: # TISCH_JAM=1: ein Platz geht immer all-in, je 20 Blaetter (120 Haende) ein neuer solcher Spieler
sitze[(platz + 1 + b % 5) % 6] = "jam%d" % (b // 20)
memo.clear()
regeln.clear()
alt[0] = False
erg, hist, gr, ges = T.hand(blatt, sitze, b * 10 + platz)
e = round(erg[platz] / 100, 4)
z = {"b": b, "platz": platz, "neu": e, "alt": e, "zuege": sum(x[0] == platz for x in gr)}
if regeln:
alt[0] = True
erg, *_ = T.hand(blatt, sitze, b * 10 + platz)
z["alt"], z["r"] = round(erg[platz] / 100, 4), list(regeln)
if arm == "stat":
z = {"s": g, "h": [(e["street"][0], e["seat"] - 1, e["action"]) for e in hist]}
SI.warte_platz(aus); f.write(json.dumps(z) + "\n")
break
SI.warte_platz(aus); f.write(json.dumps(z, separators=(",", ":")) + "\n")
f.flush()