spots.py --live: spots from our live hand sets (welt_v5/live, card field k); our own cards always known, no own-hand exclusion, no player holdout, tag from the hand time
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4991ed38c4
commit
8dd4783ceb
@@ -249,10 +249,14 @@ def ist_aggression(z):
|
||||
return z[2] in ("b", "r")
|
||||
|
||||
|
||||
def spots_aus_satz(satz, tag, vpip, eigene=frozenset(), zaehler=None, muck=False):
|
||||
"""Alle Spots einer Hand (Liste von dicts). `zaehler`: optionaler Counter fuer die Diagnose."""
|
||||
def spots_aus_satz(satz, tag, vpip, eigene=frozenset(), zaehler=None, muck=False, live=False):
|
||||
"""Alle Spots einer Hand (Liste von dicts). `zaehler`: optionaler Counter fuer die Diagnose. `live`: Handsatz aus unserem Lauf
|
||||
(welt_v5/live): unser Sitz hat keine id (wird "uns"), der Spieler-Holdout `versiegelt` gilt nicht (Live ist ohnehin zurueckgehalten)."""
|
||||
z_ = zaehler if zaehler is not None else collections.Counter()
|
||||
k = satz.get("k") or {}
|
||||
k = dict(satz.get("k") or {})
|
||||
if live and (satz.get("live") or {}).get("hole") and str(satz["live"]["hero"]) not in k:
|
||||
k[str(satz["live"]["hero"])] = satz["live"]["hole"] # unsere Karten kennen wir immer
|
||||
satz = dict(satz, k=k)
|
||||
n = len(satz["s"])
|
||||
if n > MAX_SITZE or n < 2:
|
||||
return []
|
||||
@@ -270,6 +274,8 @@ def spots_aus_satz(satz, tag, vpip, eigene=frozenset(), zaehler=None, muck=False
|
||||
drehung = int(satz["h"]) % n
|
||||
sitz = (lambda i: (i + drehung) % n + 1)
|
||||
ids = [s.get("id") or "" for s in satz["s"]]
|
||||
if live:
|
||||
ids = [x or "uns" for x in ids]
|
||||
if not all(ids):
|
||||
z_["verworfen_ohne_id"] += 1
|
||||
return []
|
||||
@@ -285,7 +291,7 @@ def spots_aus_satz(satz, tag, vpip, eigene=frozenset(), zaehler=None, muck=False
|
||||
continue
|
||||
elif str(held) not in k:
|
||||
continue
|
||||
if versiegelt(ids[gegner]) or versiegelt(ids[held]):
|
||||
if not live and (versiegelt(ids[gegner]) or versiegelt(ids[held])):
|
||||
z_["versiegelt_" + art] += 1
|
||||
continue
|
||||
if muck:
|
||||
@@ -297,6 +303,9 @@ def spots_aus_satz(satz, tag, vpip, eigene=frozenset(), zaehler=None, muck=False
|
||||
if muck:
|
||||
q["_held_gezogen"] = True
|
||||
q["_limp"] = ist_limp(verlauf, gegner)
|
||||
if live:
|
||||
tag = datetime.datetime.fromtimestamp(satz["t"]).strftime("%Y-%m-%d")
|
||||
q["_live"] = True
|
||||
q["_tag"] = tag
|
||||
q["_teil"] = teil_von(tag)
|
||||
q["_spieler"] = ids[gegner]
|
||||
@@ -377,6 +386,24 @@ def datei_spots(arg):
|
||||
return pfad, zeilen, zaehler
|
||||
|
||||
|
||||
def live_spots(pfad, aus, vpip_pfad):
|
||||
"""Live-Zeugnis: alle Spots aus einer Datei mit Live-Handsaetzen (unsere Haende, eigene nicht ausgeschlossen); append-only."""
|
||||
if os.path.exists(aus):
|
||||
sys.exit("%s existiert (nie ueberschreiben)" % aus)
|
||||
vpip = lade_vpip(vpip_pfad)
|
||||
zaehler = collections.Counter()
|
||||
n = 0
|
||||
with gzip.open(pfad, "rt", encoding="utf-8") as f, open(aus + ".tmp", "w", encoding="utf-8", newline="\n") as o:
|
||||
for zeile in f:
|
||||
zaehler["saetze"] += 1
|
||||
satz = json.loads(zeile)
|
||||
for q in spots_aus_satz(satz, None, vpip, frozenset(), zaehler, False, live=True):
|
||||
o.write(json.dumps(q, separators=(",", ":")) + "\n")
|
||||
n += 1
|
||||
os.replace(aus + ".tmp", aus)
|
||||
print(json.dumps({"diagnose": dict(zaehler), "spots": n}, indent=1, sort_keys=True))
|
||||
|
||||
|
||||
def kennzahlen(zeilen):
|
||||
z = collections.Counter()
|
||||
for t in zeilen:
|
||||
@@ -401,7 +428,10 @@ def main():
|
||||
ap.add_argument("--prozesse", type=int, default=4)
|
||||
ap.add_argument("--dateien", type=int, default=0)
|
||||
ap.add_argument("--anhaengen", action="store_true")
|
||||
ap.add_argument("--live", default="", help="Datei mit Live-Handsaetzen (welt_v5/live/handsaetze-karten-v2.jsonl.gz): Live-Zeugnis, braucht --aus")
|
||||
x = ap.parse_args()
|
||||
if x.live:
|
||||
return live_spots(x.live, x.aus, x.vpip)
|
||||
x.aus = x.aus or (STANDARD_AUS_MUCK if x.muck else STANDARD_AUS)
|
||||
if os.path.exists(x.aus) and not x.anhaengen:
|
||||
sys.exit("%s existiert; --anhaengen zum Erweitern (append-only, nie ueberschreiben)" % x.aus)
|
||||
|
||||
Reference in New Issue
Block a user