#!/bin/sh # Replay every case's win path through the headless engine and check it # reaches max_score and fires `won`. Deterministic: --script disables the AI # lane, so the same script always produces the same events. # # ./tools/verify.sh all cases # ./tools/verify.sh 07 one ENGINE="${MRPGI:-$HOME/Documents/MRPGI}" cd "$(dirname "$0")/.." MB="$ENGINE/target/debug/mrpgi-headless" [ -x "$MB" ] || cargo build --manifest-path "$ENGINE/Cargo.toml" -p mrpgi-core --bin mrpgi-headless || exit 1 fail=0 for f in tests/scripts/case-${1:-*}.jsonl; do n=$(basename "$f" .jsonl | sed 's/^case-//') dir=$(ls -d cases/case-"$n"-*/ 2>/dev/null | head -1) [ -n "$dir" ] || { echo " $n NO CASE DIR"; fail=1; continue; } printf ' %-4s ' "$n" "$MB" --script "$f" --game "$dir" 2>&1 | python3 -c " import sys, json sc = mx = 0; won = False for l in sys.stdin: try: e = json.loads(l) except Exception: continue if e.get('event') == 'score_changed': mx = e['max'] if e.get('event') == 'state': sc, won = e['state']['score'], e['state']['won'] ok = won and sc >= mx print(('%3d/%-3d won=%-5s %s' % (sc, mx, won, 'ok' if ok else 'FAIL'))) sys.exit(0 if ok else 1) " || fail=1 done [ $fail -eq 0 ] && echo "all win paths verified" || echo "SOME PATHS FAILED" exit $fail