score: basis_antworten.py turns the field basis of a version's answers into an answer file for the judge (line Basis of the layered scorecard)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3737c15a5c
commit
aa2831706f
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Zweizeilige Scorecard aus EINEM Lauf (Owner 05.12.: Basis ohne Ausbeute, Ausbeute als eigene Ebene): aus den Antworten einer Fassung die Antworten
|
||||
der Ebene "Basis" (Feld `basis` jeder Antwort) als eigene Antwortdatei, im Format, das der Richter liest (`werte`: [art, ziel_bb, anteil]).
|
||||
|
||||
python3 basis_antworten.py <antworten.jsonl> <anfragen.jsonl> <ziel.jsonl>
|
||||
|
||||
`basis` = {action, size[, mischung], vermischt}: mit `mischung` (Eintraege {zug: {action, size}, anteil, ...}) wird die Mischung uebernommen,
|
||||
sonst der eine Zug. art: 0 Fold, 1 Check/Call, 2 Einsatz/Erhoehung (Ziel in bb = size / bigBlind der Anfrage). Antworten ohne `basis` brechen ab.
|
||||
`vermischt` der Basis wird je Zeile mitgeschrieben (Auskunft; die Scorecard zaehlt die Zeilen mit offener Vermischung).
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
ART = {"FOLD": 0, "CHECK": 1, "CALL": 1, "BET": 2, "RAISE": 2, "ALL_IN": 2}
|
||||
|
||||
|
||||
def zug(action, size, bb):
|
||||
art = ART.get(action)
|
||||
if art is None:
|
||||
return None
|
||||
return [art, (float(size) / bb) if art == 2 and size is not None else 0.0]
|
||||
|
||||
|
||||
def basis_antwort(antwort, anfrage):
|
||||
b = antwort.get("basis")
|
||||
if not isinstance(b, dict):
|
||||
raise ValueError("Antwort ohne Feld basis")
|
||||
bb = float(anfrage["bigBlind"])
|
||||
werte = []
|
||||
for e in b.get("mischung") or []:
|
||||
z = e.get("zug") or {}
|
||||
w = zug(z.get("action"), z.get("size"), bb)
|
||||
if w is not None and float(e.get("anteil", 0.0)) > 0.0:
|
||||
werte.append(w + [float(e["anteil"])])
|
||||
if not werte:
|
||||
w = zug(b.get("action"), b.get("size"), bb)
|
||||
if w is not None:
|
||||
werte.append(w + [1.0])
|
||||
return {"action": b.get("action"), "size": b.get("size"), "werte": werte, "reason": "basis", "vermischt": b.get("vermischt")}
|
||||
|
||||
|
||||
def main(argv):
|
||||
quelle, anfragen, ziel = argv[:3]
|
||||
if os.path.exists(ziel):
|
||||
raise SystemExit("%s existiert; nie ueberschreiben" % ziel)
|
||||
a = [json.loads(z) for z in open(quelle) if z.strip()]
|
||||
q = [json.loads(z) for z in open(anfragen) if z.strip()]
|
||||
if len(a) != len(q):
|
||||
raise SystemExit("%d Antworten fuer %d Anfragen" % (len(a), len(q)))
|
||||
zeilen = [json.dumps(basis_antwort(x, y)) for x, y in zip(a, q)]
|
||||
with open(ziel + ".tmp", "w") as f:
|
||||
f.write("\n".join(zeilen) + "\n")
|
||||
os.replace(ziel + ".tmp", ziel)
|
||||
offen = sum(1 for x in a if (x.get("basis") or {}).get("vermischt"))
|
||||
print("%d Basis-Antworten -> %s (mit offener Vermischung: %d)" % (len(zeilen), ziel, offen))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
Reference in New Issue
Block a user