Files
tidewall/tools/balance.gd
T
claudeandClaude Opus 5.5 38812120df 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>
2026-11-14 06:28:15 -05:00

76 lines
2.7 KiB
GDScript

## 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