sts2.py: thin client for the mod's localhost HTTP API, maps state_type -> legal actions (the action space), strict observe -> act once -> observe-again loop. capture.py: manual state snapshot tool for building facts.py.
27 lines
908 B
Python
27 lines
908 B
Python
#!/usr/bin/env python3
|
|
"""Save game state snapshots to ./capture/<label>.json while building facts.py.
|
|
|
|
usage: python3 capture.py <label> [--wait SECONDS]
|
|
"""
|
|
import json, sys, time, pathlib
|
|
sys.path.insert(0, str(pathlib.Path(__file__).parent))
|
|
import sts2
|
|
|
|
def snap(label, wait=1.0):
|
|
if wait: time.sleep(wait)
|
|
obs = sts2.state()
|
|
out = pathlib.Path(__file__).parent / "capture"
|
|
out.mkdir(exist_ok=True)
|
|
path = out / f"{label}.json"
|
|
path.write_text(json.dumps(obs, indent=2))
|
|
print(f"[{label}] state_type={obs.get('state_type')!r} "
|
|
f"msg={str(obs.get('message'))[:60]!r} -> {path.name} ({path.stat().st_size}B)")
|
|
return obs
|
|
|
|
if __name__ == "__main__":
|
|
args = [a for a in sys.argv[1:] if not a.startswith("--")]
|
|
wait = 1.0
|
|
if "--wait" in sys.argv:
|
|
wait = float(sys.argv[sys.argv.index("--wait") + 1])
|
|
for lbl in args:
|
|
snap(lbl, wait)
|