MOTOR_PI: spec for art_von_text, farm check scripts (nachspiel_pi, vergleich_pi, pibau, pilauf)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Marc Mintel
2026-12-05 18:17:08 +01:00
co-authored by Claude Sonnet 5.5
parent dd89644c0b
commit 74668c1d93
5 changed files with 181 additions and 0 deletions
+6
View File
@@ -191,6 +191,12 @@ mod tests {
assert!(!f.contains_key("pi_mischung"));
}
#[test]
fn art_des_tischzugs() {
assert_eq!([art_von_text("FOLD"), art_von_text("CHECK"), art_von_text("CALL"), art_von_text("RAISE")], [0, 1, 1, 2]);
assert_eq!([art_von_aktion(&Action::Fold), art_von_aktion(&Action::Check), art_von_aktion(&Action::Call), art_von_aktion(&Action::Bet(5))], [0, 1, 1, 2]);
}
#[test]
fn mischung_der_suche_in_bb_und_arten() {
let v = [(Action::Fold, 0.1), (Action::Call, 0.2), (Action::Bet(275), 0.3), (Action::AllIn(10_000), 0.4)];
+40
View File
@@ -0,0 +1,40 @@
"""Nachspiel fuer die Aus-/An-Pruefung von MOTOR_PI: wie messung/motor/schwachjam/nachspiel.py (gleiche Argumente, gleiche Auswahl,
gleiche Schalter), schreibt aber je Anfrage zusaetzlich die Feldnamen der Antwort und alle `pi*`-Felder.
Zeile: {"i", "a", "s", "r" (Grund, 600 Zeichen), "ms", "felder" (sortierte Schluessel der Antwort), "pi": {pi*-Felder}}.
python -X utf8 nachspiel_pi.py <nachspiel.py> <exe> <anfragen.jsonl> <aus.jsonl> [Argumente von nachspiel.py]
"""
import importlib.util
import json
import sys
import time
spec = importlib.util.spec_from_file_location("nachspiel", sys.argv[1])
n = importlib.util.module_from_spec(spec)
spec.loader.exec_module(n)
def teil(exe, extra, stueck, ausg, sperre):
p = n.starte(exe, extra)
for i, q, seed in stueck:
q = {k: v for k, v in q.items() if k != "frist_rest_s"}
t = time.time()
p.stdin.write(json.dumps(dict(q, seed=seed or 1)) + "\n")
p.stdin.flush()
z = p.stdout.readline()
if not z:
ausg.append({"i": i, "fehler": "Prozess tot"})
break
a = json.loads(z)
x = {"i": i, "a": a.get("action"), "s": a.get("size"), "r": (a.get("reason") or "")[:600], "ms": round((time.time() - t) * 1000),
"felder": sorted(a), "pi": {k: v for k, v in a.items() if k.startswith("pi")}}
ausg.append(x)
if n.TEIL:
with n.LOCK, open(n.TEIL, "a", encoding="utf-8", newline="\n") as f:
f.write(json.dumps(x, ensure_ascii=False) + "\n")
p.kill()
n.teil = teil
sys.argv = [sys.argv[0]] + sys.argv[2:]
n.main()
+24
View File
@@ -0,0 +1,24 @@
# Aus-Pruefung MOTOR_PI: Exe je Stand (basis = 53a4a84aa, kandidat = Zweig motor-pi) aus dem Quell-Archiv C:\pf-arbeit\pi\<n>.tar,
# Loeserkopie aus postflop-solver-mess + loeser-temp.patch des Stands. $args[0] = basis|kandidat
$ErrorActionPreference = "Stop"
$n = $args[0]
$arbeit = "C:\pf-arbeit\pi"
$wt = "$arbeit\$n"
$temp = "$arbeit\solver-$n"
if (-not (Test-Path "$wt\entscheiden\motor\Cargo.toml")) { New-Item -ItemType Directory $wt -Force | Out-Null; tar -xf "$arbeit\$n.tar" -C $wt; if ($LASTEXITCODE -ne 0) { throw "tar fehlgeschlagen" } }
$toml = "$wt\entscheiden\motor\Cargo.toml"
(Get-Content $toml) -replace 'D:/Projects/fremd/postflop-solver-temp"', ("C:/pf-arbeit/pi/solver-" + $n + '"') | Set-Content $toml -Encoding utf8
Select-String -Path $toml -Pattern "postflop-solver"
$patchexe = "C:\Program Files\Git\usr\bin\patch.exe"
if (-not (Test-Path $temp)) {
robocopy "D:\Projects\fremd\postflop-solver-mess" $temp /E /XD target .git /NFL /NDL /NJH /NJS | Out-Null
Push-Location $temp; & $patchexe -p1 --binary -i "$wt\entscheiden\motor\loeser-temp.patch"; $rc = $LASTEXITCODE; Pop-Location
if ($rc -ne 0) { throw "patch fehlgeschlagen" }
}
Push-Location "$wt\entscheiden\motor"
cargo build --release --locked -j 4
$rc = $LASTEXITCODE; Pop-Location
if ($rc -ne 0) { throw "cargo build fehlgeschlagen" }
Copy-Item "$wt\entscheiden\motor\target\release\motor.exe" "$arbeit\pokerbench-pi-$n.exe" -Force
"EXE $arbeit\pokerbench-pi-$n.exe"
"SHA256 " + (Get-FileHash "$arbeit\pokerbench-pi-$n.exe" -Algorithm SHA256).Hash
+40
View File
@@ -0,0 +1,40 @@
"""Farm-Auftrag: Aus-/An-Pruefung MOTOR_PI. Baut basis und kandidat (pibau.ps1), spielt die 600 Anfragen aus C:\\pf-arbeit\\zb nach
(nachspiel_pi.py, Schalter wie zb\\zeile.txt) und vergleicht: basis gegen basis (Rauschen), kandidat ohne Schalter, kandidat mit MOTOR_PI=1."""
import os
import subprocess
import sys
A = r"C:\pf-arbeit\pi"
Z = open(r"C:\pf-arbeit\zb\zeile.txt", encoding="utf-8").read().strip().split(";")
NS = r"D:\Projects\pf-schwachjam\messung\motor\schwachjam\nachspiel.py"
env = dict(os.environ, NACHSPIEL_LIVE=r"C:\pf-arbeit\zb\live")
os.makedirs(A + r"\aus", exist_ok=True)
def lauf(name, exe, extra):
aus = rf"{A}\aus\{name}.jsonl"
if os.path.exists(aus):
print("vorhanden:", aus, flush=True)
return
subprocess.run([sys.executable, "-X", "utf8", A + r"\nachspiel_pi.py", NS, exe, r"C:\pf-arbeit\zb\schatten.jsonl", aus, "--teile", "2", "--mische", "1",
"--ids", r"C:\pf-arbeit\zb\ids.txt", *Z, *extra], check=True, env=env)
def vergleich(b, k, *opt):
r = subprocess.run([sys.executable, "-X", "utf8", A + r"\vergleich_pi.py", rf"{A}\aus\{b}.jsonl", rf"{A}\aus\{k}.jsonl", *opt], capture_output=True, text=True, encoding="utf-8")
t = f"== {b} gegen {k} {' '.join(opt)}\n{r.stdout}{r.stderr}"
print(t, flush=True)
open(A + r"\aus\ergebnis.txt", "a", encoding="utf-8").write(t + "\n")
for n in ("basis", "kandidat"):
subprocess.run(["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", rf"{A}\pibau.ps1", n], check=True)
BASIS, KAND = rf"{A}\pokerbench-pi-basis.exe", rf"{A}\pokerbench-pi-kandidat.exe"
lauf("basis", BASIS, [])
lauf("basis2", BASIS, [])
lauf("kandidat_aus", KAND, [])
lauf("kandidat_an", KAND, ["MOTOR_PI=1"])
vergleich("basis", "basis2")
vergleich("basis", "kandidat_aus")
vergleich("basis", "kandidat_an", "--pi-an")
print("FERTIG", flush=True)
+71
View File
@@ -0,0 +1,71 @@
"""Vergleicht zwei Laeufe von nachspiel_pi.py (Basis gegen Kandidat) und prueft die pi-Felder des Kandidaten.
python -X utf8 vergleich_pi.py <basis.jsonl> <kandidat.jsonl> [--pi-an]
Zugabweichung: Aktion oder Groesse verschieden. Grundabweichung: Zuggrund verschieden (Zeiten "<n> ms" gleichgesetzt).
Feldabweichung: andere Feldnamen der Antwort (ohne pi*; mit --pi-an muessen genau die pi*-Felder dazukommen).
Mit --pi-an: jede Antwort mit Zug (Aktion nicht ABSTAIN) hat pi mit 0 < pi <= 1 und pi_weg; kommt pi_mischung vor, ist pi = Masse des gezogenen Eintrags.
Ohne --pi-an: kein pi*-Feld in keiner Antwort.
"""
import json
import re
import sys
from collections import Counter
def lade(pfad):
return {x["i"]: x for x in map(json.loads, open(pfad, encoding="utf-8")) if "i" in x}
def grund(r):
return re.sub(r"\d+ ms", "N ms", r or "")
def main():
b, k = lade(sys.argv[1]), lade(sys.argv[2])
pi_an = "--pi-an" in sys.argv
gemeinsam = sorted(set(b) & set(k))
zug, gr, feld, ohne_pi, schlecht, wege, fehler = [], [], [], [], [], Counter(), []
for i in gemeinsam:
x, y = b[i], k[i]
if "fehler" in x or "fehler" in y:
fehler.append(i)
continue
if (x["a"], x["s"]) != (y["a"], y["s"]):
zug.append(i)
if grund(x["r"]) != grund(y["r"]):
gr.append(i)
eigene = [f for f in y["felder"] if not f.startswith("pi")]
pi_felder = [f for f in y["felder"] if f.startswith("pi")]
if eigene != x["felder"]:
feld.append(i)
if pi_an:
if y["a"] == "ABSTAIN":
continue
p = y["pi"].get("pi")
ok = isinstance(p, (int, float)) and 0 < p <= 1 and isinstance(y["pi"].get("pi_weg"), str)
if ok and "pi_mischung" in y["pi"]:
m = y["pi"]["pi_mischung"]
g = y["pi"]["pi_gezogen"]
ok = abs(m[g][2] - p) < 1e-9 and abs(sum(e[2] for e in m) - 1) < 1e-4
if not ok:
schlecht.append(i)
else:
wege[y["pi"]["pi_weg"].split(" ")[0]] += 1
elif pi_felder:
ohne_pi.append(i)
print(f"gemeinsam {len(gemeinsam)} (Basis {len(b)}, Kandidat {len(k)}), Fehlerzeilen {len(fehler)}")
print(f"Zugabweichungen {len(zug)} {zug[:10]}")
print(f"Grundabweichungen {len(gr)} {gr[:10]}")
print(f"Feldabweichungen {len(feld)} {feld[:10]}")
if pi_an:
print(f"pi fehlt oder ungueltig: {len(schlecht)} {schlecht[:10]}")
print("pi_weg:", dict(wege))
else:
print(f"Antworten mit pi*-Feld: {len(ohne_pi)} {ohne_pi[:10]}")
bad = len(zug) + len(gr) + len(feld) + len(schlecht) + len(ohne_pi) + len(fehler)
print("ERGEBNIS", "OK" if bad == 0 and gemeinsam else "ABWEICHUNG")
sys.exit(0 if bad == 0 and gemeinsam else 1)
main()