97 lines
4.1 KiB
Python
97 lines
4.1 KiB
Python
"""Sequenzieller Lauf mit Abbruch (KARTE.md, Felder decke/abbruch): startet lauf.sh, wertet alle `takt` Sekunden die
|
|
fertigen Blaetter aus und beendet den Lauf, sobald entschieden.
|
|
|
|
python sequenz.py <aus> <max-blaetter> <saat> <muster> <X> <Y> [--halb 5] [--min 50] [--takt 60] [--tor ueber0]
|
|
|
|
Wert je Blatt = X minus Y auf denselben Plaetzen (All-in-EV, je eigene Hand), bb/100; X allein zahlt Rake. Entschieden (nach mindestens `min` Blaettern):
|
|
- tor ueber0 (Abnahme): untere 95-%-Grenze > 0 -> bestanden; obere < 0 -> durchgefallen;
|
|
- tor info (Duell): Intervall schliesst 0 aus (Vorzeichen fest) oder halbe Breite <= halb (gleich auf +-halb).
|
|
Sonst bis max-blaetter. Ergebnis als eine Zeile nach daten/<aus>.ergebnis.
|
|
"""
|
|
import argparse
|
|
import json
|
|
import math
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
HIER = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def stand(pfad, n_je_blatt):
|
|
"""Wert je Blatt = Motor minus SHARINGAN auf denselben Plaetzen (All-in-EV, je eigene Hand), bb/100.
|
|
Nicht X allein: X allein zahlt Rake und sieht dadurch schlechter aus (Verlustkarte 27.11., verlust/KARTE.md)."""
|
|
sys.path.insert(0, os.path.join(HIER, "verlust"))
|
|
import verlust as v
|
|
je, gesehen = {}, set()
|
|
if os.path.exists(pfad):
|
|
for z in open(pfad, encoding="utf-8"):
|
|
try:
|
|
x = json.loads(z)
|
|
except ValueError:
|
|
continue
|
|
e = je.setdefault(x["blatt"], {"zeilen": 0, "M": [0.0, 0], "S": [0.0, 0]})
|
|
e["zeilen"] += 1
|
|
hk = (x["blatt"], x.get("dreh", x["platz"]))
|
|
if hk in gesehen:
|
|
continue
|
|
gesehen.add(hk)
|
|
motor = set(x.get("xplaetze") or [x["platz"]])
|
|
ev = v.nachspielen(x, motor)[2]
|
|
for j in range(len(ev)):
|
|
w = e["M" if j in motor else "S"]
|
|
w[0] += ev[j]
|
|
w[1] += 1
|
|
w = [(e["M"][0] / e["M"][1] - e["S"][0] / e["S"][1]) * 100 for e in je.values() if e["zeilen"] == n_je_blatt]
|
|
if len(w) < 2:
|
|
return len(w), 0.0, float("inf")
|
|
m = sum(w) / len(w)
|
|
return len(w), m, 1.96 * math.sqrt(sum((x - m) ** 2 for x in w) / (len(w) - 1) / len(w))
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
for k in ("aus", "max", "saat", "muster", "x", "y"):
|
|
ap.add_argument(k)
|
|
ap.add_argument("--halb", type=float, default=5.0)
|
|
ap.add_argument("--min", type=int, default=50)
|
|
ap.add_argument("--takt", type=int, default=60)
|
|
ap.add_argument("--tor", default="info")
|
|
a = ap.parse_args()
|
|
k = int(a.muster)
|
|
n_je = int(os.environ.get("TISCH_N", "6")) * k
|
|
pfad = os.path.join(HIER, "daten", a.aus + ".jsonl")
|
|
p = subprocess.Popen(["bash", os.path.join(HIER, "lauf.sh"), a.aus, a.max, a.saat, a.muster, a.x, a.y],
|
|
stdout=subprocess.DEVNULL, stderr=open(os.path.join(HIER, "daten", a.aus + ".log"), "a"))
|
|
with open(os.path.join(HIER, "daten", a.aus + ".pid"), "w") as f:
|
|
f.write(str(p.pid))
|
|
urteil = "max erreicht"
|
|
while p.poll() is None:
|
|
time.sleep(a.takt)
|
|
n, m, h = stand(pfad, n_je)
|
|
print("%s %d Blaetter %+.2f +-%.2f" % (time.strftime("%H:%M"), n, m, h), flush=True)
|
|
if n >= a.min:
|
|
if a.tor == "ueber0" and m - h > 0:
|
|
urteil = "bestanden (untere Grenze > 0)"
|
|
elif a.tor == "ueber0" and m + h < 0:
|
|
urteil = "durchgefallen (obere Grenze < 0)"
|
|
elif a.tor == "info" and (m - h > 0 or m + h < 0):
|
|
urteil = "entschieden (Vorzeichen fest)"
|
|
elif a.tor == "info" and h <= a.halb:
|
|
urteil = "gleich auf +-%.1f" % a.halb
|
|
else:
|
|
continue
|
|
# zuerst den Starter (bash), dann alle Kinder
|
|
subprocess.run(["taskkill", "/T", "/F", "/PID", str(p.pid)], capture_output=True)
|
|
break
|
|
n, m, h = stand(pfad, n_je)
|
|
z = "%s: %s gegen %s, Muster %s, %d Blaetter, X-Y %+.2f +-%.2f bb/100 (95 %%), %s" % (a.aus, a.x, a.y, a.muster, n, m, h, urteil)
|
|
print(z)
|
|
with open(os.path.join(HIER, "daten", a.aus + ".ergebnis"), "w", encoding="utf-8") as f:
|
|
f.write(z + "\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|