Files
tidewall/test/bots/balance_report.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

122 lines
6.3 KiB
GDScript

## Adds up BotBatch.run_match() results for the balance pass (H3) and judges them
## against the targets in Tuning (BALANCE_*). Shared by tools/balance.gd and its test.
class_name BalanceReport
extends RefCounted
## Minutes at which the report counts who is still standing.
const STANDING_AT_MINUTES: Array[int] = [2, 4, 6, 8, 10, 12, 14]
## The value at fraction `q` (0 to 1) of a sorted list, interpolating between neighbours.
static func quantile(sorted: Array[float], q: float) -> float:
if sorted.is_empty():
return 0.0
var position: float = q * (sorted.size() - 1)
var low: int = floori(position)
var high: int = mini(low + 1, sorted.size() - 1)
return lerpf(sorted[low], sorted[high], position - low)
## Returns {"matches", "minutes": {"p10", "p25", "median", "p75", "p90", "min", "max"},
## "finished", "with_winner", "timed_out", "causes", "deaths", "tide_share",
## "weapon_kills", "weapon_share": {weapon: fraction of weapon eliminations},
## "top_weapon", "top_share", "wins", "eliminations", "mean_place",
## "standing": {minute: mean players standing}, "problems": [String]}.
static func analyse(results: Array[Dictionary]) -> Dictionary:
var minutes: Array[float] = []
var weapon_kills: Dictionary = {}
var standing: Dictionary = {}
for minute: int in STANDING_AT_MINUTES:
standing[minute] = 0.0
for result: Dictionary in results:
minutes.append(float(result["ticks"]) / Tuning.TICK_RATE_HZ / 60.0)
for weapon: String in result.get("weapon_kills", {}):
weapon_kills[weapon] = int(weapon_kills.get(weapon, 0)) + int(result["weapon_kills"][weapon])
var deaths: Array = result.get("death_seconds", [])
var players: int = Tuning.SOLO_PLAYERS
for minute: int in STANDING_AT_MINUTES:
var fallen: int = 0
for at: Variant in deaths:
if float(at) <= minute * 60.0:
fallen += 1
standing[minute] += float(players - fallen)
minutes.sort()
var typed: Array[Dictionary] = results
var total: Dictionary = BotBatch.summarise(typed)
var analysis: Dictionary = {
"matches": results.size(),
"minutes": {
"min": minutes[0] if not minutes.is_empty() else 0.0,
"p10": quantile(minutes, 0.1), "p25": quantile(minutes, 0.25),
"median": quantile(minutes, 0.5), "p75": quantile(minutes, 0.75),
"p90": quantile(minutes, 0.9), "max": minutes[-1] if not minutes.is_empty() else 0.0,
},
"finished": total["finished"], "with_winner": total["with_winner"], "timed_out": total["timed_out"],
"causes": total["causes"], "deaths": total["deaths"],
"tide_share": float(int(total["causes"].get("drown", 0)) + int(total["causes"].get("tide", 0))) / maxi(total["deaths"], 1),
"weapon_kills": weapon_kills, "weapon_share": {}, "top_weapon": "", "top_share": 0.0,
"wins": total["wins"], "eliminations": total["eliminations"], "mean_place": total["mean_place"],
"standing": {}, "problems": [],
}
var weapon_total: int = 0
for weapon: String in weapon_kills:
weapon_total += int(weapon_kills[weapon])
for weapon: String in weapon_kills:
var share: float = float(weapon_kills[weapon]) / maxi(weapon_total, 1)
analysis["weapon_share"][weapon] = share
if share > analysis["top_share"]:
analysis["top_share"] = share
analysis["top_weapon"] = weapon
for minute: int in STANDING_AT_MINUTES:
analysis["standing"][minute] = standing[minute] / maxi(results.size(), 1)
var problems: Array = analysis["problems"]
if results.size() < Tuning.BALANCE_MIN_MATCHES:
problems.append("only %d matches; the pass needs %d" % [results.size(), Tuning.BALANCE_MIN_MATCHES])
if total["finished"] != results.size() or total["with_winner"] != results.size():
problems.append("%d of %d matches finished with a winner" % [total["with_winner"], results.size()])
var median: float = analysis["minutes"]["median"]
if median < Tuning.BALANCE_MEDIAN_MINUTES_MIN or median > Tuning.BALANCE_MEDIAN_MINUTES_MAX:
problems.append("median match length %.1f min is outside %.0f to %.0f" % [median, Tuning.BALANCE_MEDIAN_MINUTES_MIN, Tuning.BALANCE_MEDIAN_MINUTES_MAX])
if analysis["top_share"] > Tuning.BALANCE_MAX_WEAPON_SHARE:
problems.append("%s took %.0f%% of weapon eliminations, over the %.0f%% limit" % [analysis["top_weapon"], analysis["top_share"] * 100.0, Tuning.BALANCE_MAX_WEAPON_SHARE * 100.0])
return analysis
## The report as plain text.
static func format(a: Dictionary) -> String:
var lines: PackedStringArray = []
var m: Dictionary = a["minutes"]
lines.append("Tidewall balance report: %d bot-only matches, %d players each" % [a["matches"], Tuning.SOLO_PLAYERS])
lines.append("")
lines.append("Match length (minutes from the barge leaving):")
lines.append(" min %.1f p10 %.1f p25 %.1f median %.1f p75 %.1f p90 %.1f max %.1f" % [m["min"], m["p10"], m["p25"], m["median"], m["p75"], m["p90"], m["max"]])
lines.append(" target median %.0f to %.0f; %d of %d ended by the tide's clock" % [Tuning.BALANCE_MEDIAN_MINUTES_MIN, Tuning.BALANCE_MEDIAN_MINUTES_MAX, a["timed_out"], a["matches"]])
var curve: PackedStringArray = []
for minute: int in STANDING_AT_MINUTES:
curve.append("%d min: %.1f" % [minute, a["standing"][minute]])
lines.append(" mean players standing: " + ", ".join(curve))
lines.append("")
lines.append("Causes of %d falls:" % a["deaths"])
var causes: Array = a["causes"].keys()
causes.sort()
for cause: String in causes:
lines.append(" %-8s %5d %5.1f%%" % [cause, a["causes"][cause], 100.0 * a["causes"][cause] / maxi(a["deaths"], 1)])
lines.append(" the sea (drown + tide): %.1f%%" % (a["tide_share"] * 100.0))
lines.append("")
lines.append("Eliminations by weapon (limit %.0f%% for any one):" % (Tuning.BALANCE_MAX_WEAPON_SHARE * 100.0))
var weapons: Array = a["weapon_kills"].keys()
weapons.sort_custom(func(x: String, y: String) -> bool: return a["weapon_kills"][x] > a["weapon_kills"][y])
for weapon: String in weapons:
lines.append(" %-16s %5d %5.1f%%" % [weapon, a["weapon_kills"][weapon], a["weapon_share"][weapon] * 100.0])
lines.append("")
lines.append("By difficulty:")
for level: String in ["easy", "normal", "hard"]:
lines.append(" %-6s wins %3d eliminations %5d mean place %.2f" % [level, a["wins"].get(level, 0), a["eliminations"].get(level, 0), a["mean_place"].get(level, 0.0)])
lines.append("")
if a["problems"].is_empty():
lines.append("balance: ok")
else:
for problem: String in a["problems"]:
lines.append("balance FAIL: %s" % problem)
return "\n".join(lines) + "\n"