Files
tidewall/test/bots/balance_report.gd
T
claudeandClaude Opus 5.5 aa797580a7 #72: The packet ship, the lifeline mortar and the gull-kite
Eric chose option B on #72. The drop is now the GDD's launch:

- A packet ship sails a seeded straight line past the island, offshore,
  as close in as it can while keeping 45 m of open water from any land
  (eight-way probes; up to 32 headings, then the four world sides).
- Jump fires the lifeline mortar along the look heading. How high the
  player aims sets the charge (-10 to 45 degrees: 16 to 110 m/s over
  the ground; every shot climbs at 75 m/s). The climb can't be steered
  and the kite can't open until the arc tops out. Riders still aboard at
  the end are fired towards the middle of the island.
- Drop.reach() mirrors the fall for both ways down (kite at the top, or
  a fall with the kite opening by itself); bots, the soak and autoplay
  clients and the tutorial pilot aim with Drop.aim_charge().
- Bots fire at their landing spot once abeam of it, when in easy reach
  at their own staggered moment, or just before the route ends, and open
  the kite early only when the spot is beyond the rest of a fall.
- Art: VesselModels.ship() (two-masted packet, tanned square sails, a
  salt-white boot-top, a bowsprit and the mortar on its bed, mirrored to
  face the island), the figure's gull-kite (figure.py), and a lifeline
  cord from the muzzle to each player still climbing.
- Renamed barge to ship and wing-sail to gull-kite throughout code,
  tests, captures, docs and the tutorial text. make match now defaults to
  seed 2, where the scripted player still harvests and builds.

Closes #72

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 12:49:21 -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 ship 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"