#!/usr/bin/env bash # H3: the balance pass. Plays BALANCE_MATCHES bot-only matches (default 200) from seed # BALANCE_FIRST (default 1001) in BALANCE_JOBS processes side by side (default 4), under # nice, then writes build/balance/report.txt and judges it against the targets in # docs/GDD.md ("Balance"). Each match is about half a minute of one core. # # tools/balance.sh # BALANCE_MATCHES=30 BALANCE_JOBS=2 tools/balance.sh a quick look; fails the count # BALANCE_REPORT_ONLY=1 tools/balance.sh report on what's in build/balance set -uo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." matches="${BALANCE_MATCHES:-200}" first="${BALANCE_FIRST:-1001}" jobs="${BALANCE_JOBS:-4}" out="${BALANCE_DIR:-build/balance}" if [[ "${BALANCE_REPORT_ONLY:-0}" != "1" ]]; then mkdir -p "$out" rm -f "$out"/*.jsonl "$out"/report.txt "$out"/job-*.log per=$(( (matches + jobs - 1) / jobs )) pids=() for (( j = 0; j < jobs; j++ )); do start=$(( first + j * per )) count=$(( matches - j * per )) (( count > per )) && count=$per (( count <= 0 )) && break nice -n 15 tools/godot.sh --script res://tools/balance.gd -- --run --first="$start" --seeds="$count" \ --out="$PWD/$out/job-$j.jsonl" > "$out/job-$j.log" 2>&1 & pids+=("$!") done failed=0 for pid in "${pids[@]}"; do wait "$pid" || failed=1 done if grep -lE 'SCRIPT ERROR|^ERROR' "$out"/job-*.log >/dev/null 2>&1; then echo "balance FAIL: engine or script errors in $(grep -lE 'SCRIPT ERROR|^ERROR' "$out"/job-*.log | tr '\n' ' ')" failed=1 fi if (( failed )); then echo "balance FAIL: a batch process failed; see $out/job-*.log" exit 1 fi fi tools/godot.sh --script res://tools/balance.gd -- --report="$PWD/$out"