pokersim (Klon, Cockpit, Ansicht, Leser, Mitschriebe) steht jetzt getrennt neben der Engine.
Der Grund, warum es vorher nicht allein stehen konnte, ist behoben:
* client/ (Adresse des Clients und seine zwei Sockets) liegt nicht mehr in hand/ - beide Seiten
finden es ueber die Naht; die Engine braucht dafuer nichts aus der Welt zu importieren
* die Wurzelmarke aller Dateien ist "lesen" statt "hand": damit findet jede Datei ihre Wurzel,
egal in welchem der beiden Baeume sie steht (126 Stellen)
* werkzeuge/hof.py kann beide Baeume bauen: HOF_ART=welt -> Projects/pokersim (Welt),
ohne -> Projects/pokerfreak-sim (Welt und Engine). Die Welt waehlt ihre Pruefungen nach
IMPORTEN (Prosa darf die gedockte Engine nennen), der volle Hof nach Erwaehnungen.
Abnahme: Engine-Baum schneller Lauf 1444 Faelle (1 Flatterer, allein gruen); Welt-Baum 38 Pruefungen
333 Faelle rot 0, Bericht 9 Stellen. swift run Pruefung 132 gruen.
113 lines
3.6 KiB
Python
113 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Erstellt ein Verzeichnis aller aufgezeichneten Formate (Korpus-Index).
|
|
|
|
Ordnet jeden Raum einem Format zu und zählt, was da ist: Hände, Kartenanzahl,
|
|
Bedenkzeit, Aktionsmenü, Sonderfälle. Grundlage für die Reihenfolge des Baus.
|
|
|
|
python3 formats.py [logdatei]
|
|
"""
|
|
import os as _os, sys as _sys
|
|
_w = _os.path.dirname(_os.path.abspath(__file__))
|
|
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "lesen")):
|
|
_w = _os.path.dirname(_w)
|
|
WURZEL = _w
|
|
for _u in ("lesen", "entscheiden", "hand", "client", "lobby", "korpus", "betrieb"):
|
|
_q = _os.path.join(_w, _u)
|
|
if _os.path.isdir(_q) and _q not in _sys.path:
|
|
_sys.path.insert(0, _q)
|
|
import collections
|
|
import json
|
|
import os
|
|
|
|
import umgebung
|
|
import sys
|
|
import re
|
|
import sys
|
|
|
|
LOG = umgebung.log()
|
|
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "scratch",
|
|
"korpus-index.txt")
|
|
|
|
PAT = re.compile(r'"BeanData":"((?:[^"\\]|\\.)*)","Cmd":"(game\.[a-z_]+)","RoomName":"((?:[^"\\]|\\.)*)"')
|
|
|
|
VARIANTS = [
|
|
("PLO6", "PLO6"), ("PLO5", "PLO5"), ("PLO", "PLO"), ("6+", "Short Deck"),
|
|
("SD", "Short Deck"), ("AOF", "All-In or Fold"), ("KP-", "K-Poker"),
|
|
("Bomb", "Bomb Pot"), ("Hyper", "Turnier Hyper"), ("Turbo", "Turnier Turbo"),
|
|
("NL", "NLHE"),
|
|
]
|
|
|
|
|
|
def label(room):
|
|
for needle, name in VARIANTS:
|
|
if needle in room:
|
|
return name
|
|
return "unbekannt"
|
|
|
|
|
|
def main():
|
|
path = sys.argv[1] if len(sys.argv) > 1 else LOG
|
|
text = open(path, errors="replace").read()
|
|
rooms = collections.defaultdict(lambda: {
|
|
"hands": 0, "holes": collections.Counter(), "clock": set(),
|
|
"menu": None, "flags": collections.Counter(), "last": ""})
|
|
|
|
for m in PAT.finditer(text):
|
|
room = m.group(3)
|
|
try:
|
|
d = json.loads(json.loads('"' + m.group(1) + '"'))
|
|
except Exception:
|
|
continue
|
|
cmd = m.group(2)
|
|
R = rooms[room]
|
|
if cmd == "game.hole_cards":
|
|
R["hands"] += 1
|
|
R["holes"][len(d.get("holeCards") or [])] += 1
|
|
if cmd == "game.user_turn":
|
|
if d.get("turnTime"):
|
|
R["clock"].add(d["turnTime"])
|
|
if d.get("kpokerActions"):
|
|
R["menu"] = "K-Poker-Menü mit Beträgen"
|
|
elif d.get("userTurnOptions"):
|
|
R["menu"] = "Betragsgrößen je Sitz"
|
|
else:
|
|
R["menu"] = "keine Größen (nur fold/call)"
|
|
for flag in ("isBombpotHand", "isMegaSplash", "straddle"):
|
|
if d.get(flag):
|
|
R["flags"][flag] += 1
|
|
|
|
lines = []
|
|
def out(s=""):
|
|
lines.append(s)
|
|
|
|
out("# Korpus-Index: aufgezeichnete Formate")
|
|
out(f"# Quelle: {path}")
|
|
out()
|
|
by_format = collections.defaultdict(lambda: [0, 0])
|
|
for room, R in sorted(rooms.items(), key=lambda x: -x[1]["hands"]):
|
|
fmt = label(room)
|
|
by_format[fmt][0] += R["hands"]
|
|
by_format[fmt][1] += 1
|
|
if R["hands"] == 0 and not R["clock"]:
|
|
continue
|
|
out(f"[{fmt}] {room}")
|
|
out(f" Hände {R['hands']} | Handkarten {dict(R['holes']) or '-'} | "
|
|
f"Bedenkzeit {sorted(R['clock']) or '-'} | Menü: {R['menu'] or '-'}")
|
|
if R["flags"]:
|
|
out(f" Sonderfälle: {dict(R['flags'])}")
|
|
|
|
out()
|
|
out("# Übersicht nach Format")
|
|
for fmt, (hands, tables) in sorted(by_format.items(), key=lambda x: -x[1][0]):
|
|
out(f" {fmt:<16} Hände {hands:<5} Tische {tables}")
|
|
|
|
text_out = "\n".join(lines)
|
|
print(text_out)
|
|
os.makedirs(os.path.dirname(OUT), exist_ok=True)
|
|
open(OUT, "w").write(text_out + "\n")
|
|
print(f"\n(gespeichert: {OUT})")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|