H3: Balance pass from 200 bot matches (make balance)
make balance (tools/balance.sh, tools/balance.gd, BalanceReport) plays 200 bot-only matches in four processes under nice and reports match length, players standing over time, causes of death, eliminations by weapon and by difficulty, judged against the new BALANCE_* targets in Tuning and the GDD's Balance section. Before: median match 5.0 min, 3.4 of 24 standing at 2 min, the boathook 41% of eliminations. After, over seeds 1001-1200: median 13.1 min (p10 9.2, p90 14.6), top weapon the rivet repeater at 31.7%. Passes. Changes, each traced from single-match runs (docs/BALANCE.md): - Fix: bots leapt from the barge on a timer and landed hundreds of metres short of their spot; they now leap when it's in gliding reach or the barge starts drawing away from it. - Bots spread their landings, only brawl whoever hit them, pick out new opponents within 30 m, roam locally and hold ground, run from a gun when unarmed, and (normal and hard) break off when badly hurt. - Aim error widened; rivet repeater damage 17 to 15. - Tide: lower early levels, longer holds; every match ends within 17.75 min. Tests: BalanceReport, the new bot behaviours, the tide length. Tests that leaned on old bot luck now pin or set up what they check. make match moves to seed 29, where the scripted player still builds. Closes #56 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
## The balance pass (issue H3). Two modes:
|
||||
##
|
||||
## tools/godot.sh --script res://tools/balance.gd -- --run --first=1 --seeds=50 --out=PATH
|
||||
## plays bot-only matches and appends one JSON line per match to PATH;
|
||||
## tools/godot.sh --script res://tools/balance.gd -- --report=DIR
|
||||
## reads every DIR/*.jsonl, writes DIR/report.txt and judges it against the GDD's
|
||||
## balance targets (BALANCE_* in Tuning). Exits 1 if a target is missed.
|
||||
##
|
||||
## tools/balance.sh runs several --run processes side by side, then the report.
|
||||
extends SceneTree
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
var run: bool = false
|
||||
var first: int = 1
|
||||
var count: int = 10
|
||||
var out: String = ""
|
||||
var report_dir: String = ""
|
||||
for arg: String in OS.get_cmdline_user_args():
|
||||
if arg == "--run":
|
||||
run = true
|
||||
elif arg.begins_with("--first="):
|
||||
first = arg.trim_prefix("--first=").to_int()
|
||||
elif arg.begins_with("--seeds="):
|
||||
count = arg.trim_prefix("--seeds=").to_int()
|
||||
elif arg.begins_with("--out="):
|
||||
out = arg.trim_prefix("--out=")
|
||||
elif arg.begins_with("--report="):
|
||||
report_dir = arg.trim_prefix("--report=")
|
||||
if run and out != "":
|
||||
quit(_run(first, count, out))
|
||||
elif report_dir != "":
|
||||
quit(_report(report_dir))
|
||||
else:
|
||||
printerr("balance: give --run --first=N --seeds=N --out=PATH, or --report=DIR")
|
||||
quit(2)
|
||||
|
||||
|
||||
func _run(first: int, count: int, out: String) -> int:
|
||||
for seed_value: int in range(first, first + count):
|
||||
var result: Dictionary = BotBatch.run_match(seed_value)
|
||||
result.erase("slow_ticks")
|
||||
var file: FileAccess = FileAccess.open(out, FileAccess.READ_WRITE if FileAccess.file_exists(out) else FileAccess.WRITE)
|
||||
if file == null:
|
||||
printerr("balance: can't write %s" % out)
|
||||
return 1
|
||||
file.seek_end()
|
||||
file.store_line(JSON.stringify(result))
|
||||
file.close()
|
||||
print("balance: seed %d done, %.1f min" % [seed_value, float(result["ticks"]) / Tuning.TICK_RATE_HZ / 60.0])
|
||||
return 0
|
||||
|
||||
|
||||
func _report(dir_path: String) -> int:
|
||||
var results: Array[Dictionary] = []
|
||||
var dir: DirAccess = DirAccess.open(dir_path)
|
||||
if dir == null:
|
||||
printerr("balance: no directory %s" % dir_path)
|
||||
return 2
|
||||
var names: PackedStringArray = dir.get_files()
|
||||
names.sort()
|
||||
for file_name: String in names:
|
||||
if not file_name.ends_with(".jsonl"):
|
||||
continue
|
||||
for line: String in FileAccess.get_file_as_string(dir_path.path_join(file_name)).split("\n", false):
|
||||
var parsed: Variant = JSON.parse_string(line)
|
||||
if parsed is Dictionary:
|
||||
results.append(parsed)
|
||||
var analysis: Dictionary = BalanceReport.analyse(results)
|
||||
var text: String = BalanceReport.format(analysis)
|
||||
var file: FileAccess = FileAccess.open(dir_path.path_join("report.txt"), FileAccess.WRITE)
|
||||
file.store_string(text)
|
||||
file.close()
|
||||
print(text)
|
||||
return 0 if analysis["problems"].is_empty() else 1
|
||||
@@ -0,0 +1 @@
|
||||
uid://cy2gcehjr7d2p
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/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"
|
||||
+2
-2
@@ -4,12 +4,12 @@
|
||||
# checks the replay ends in the same state. Prints one JSON line per event and the
|
||||
# verdict. See tools/match.gd.
|
||||
#
|
||||
# tools/match.sh seed 2, where the scripted player also builds
|
||||
# tools/match.sh seed 29, where the scripted player also builds
|
||||
# MATCH_SEED=7 tools/match.sh
|
||||
set -uo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
|
||||
seed="${MATCH_SEED:-2}"
|
||||
seed="${MATCH_SEED:-29}"
|
||||
[[ "$seed" =~ ^[0-9]+$ ]] || { echo "match FAIL: bad MATCH_SEED '$seed'"; exit 2; }
|
||||
raw="$(timeout --signal=KILL 900 nice -n 15 tools/godot.sh --script res://tools/match.gd -- --seed="$seed" 2>&1)"
|
||||
code=$?
|
||||
|
||||
Reference in New Issue
Block a user