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>
123 lines
4.8 KiB
GDScript
123 lines
4.8 KiB
GDScript
extends TestCase
|
|
|
|
|
|
func _run(match_seed: int, players: int, bots: int, ticks: int) -> ServerLoop:
|
|
var loop: ServerLoop = ServerLoop.new(match_seed, players, bots)
|
|
for _index: int in ticks:
|
|
loop.run_tick()
|
|
return loop
|
|
|
|
|
|
func test_creates_players_then_bots() -> void:
|
|
var loop: ServerLoop = ServerLoop.new(1, 2, 3)
|
|
var players: int = 0
|
|
for entity: SimEntity in loop.sim.entities.entities():
|
|
if entity.archetype == SimEntity.ARCHETYPE_PLAYER:
|
|
players += 1
|
|
assert_eq(players, 5)
|
|
assert_true(loop.sim.pickups.size() > 0, "the match's floor loot was placed")
|
|
assert_eq(loop.player_ids, [1, 2, 3, 4, 5] as Array[int])
|
|
assert_eq(loop.bots.size(), 3)
|
|
assert_eq(loop.bots[0].player_id, 3)
|
|
|
|
|
|
func test_records_one_timing_sample_per_tick() -> void:
|
|
var loop: ServerLoop = _run(7, 0, 4, 120)
|
|
assert_eq(loop.sim.tick, 120)
|
|
var stats: Dictionary = loop.timing_stats()
|
|
assert_eq(stats["ticks"], 120)
|
|
assert_true(stats["min_us"] <= stats["p50_us"])
|
|
assert_true(stats["p50_us"] <= stats["p95_us"])
|
|
assert_true(stats["p95_us"] <= stats["p99_us"])
|
|
assert_true(stats["p99_us"] <= stats["max_us"])
|
|
assert_eq(stats["budget_us"], ServerLoop.TICK_BUDGET_USEC)
|
|
|
|
|
|
func test_empty_stats() -> void:
|
|
assert_eq(ServerLoop.new(1, 0, 0).timing_stats(), {"ticks": 0})
|
|
|
|
|
|
func test_percentile_uses_nearest_rank() -> void:
|
|
var values: PackedInt64Array = PackedInt64Array(range(1, 101))
|
|
assert_eq(ServerLoop._percentile(values, 0.5), 50)
|
|
assert_eq(ServerLoop._percentile(values, 0.95), 95)
|
|
assert_eq(ServerLoop._percentile(values, 1.0), 100)
|
|
assert_eq(ServerLoop._percentile(PackedInt64Array([9]), 0.99), 9)
|
|
|
|
|
|
func test_bots_leap_and_humans_without_commands_stay_aboard() -> void:
|
|
# Every match starts on the drop carrier. A human who sends nothing rides it; the bot
|
|
# leaps once the spot it chose is in gliding reach, before the route ends, and falls
|
|
# away.
|
|
var loop: ServerLoop = ServerLoop.new(99, 1, 1)
|
|
var human: SimEntity = loop.sim.entities.find(1)
|
|
var bot: SimEntity = loop.sim.entities.find(2)
|
|
assert_eq(human.drop_state, Drop.ABOARD)
|
|
assert_eq(bot.drop_state, Drop.ABOARD)
|
|
var leapt_tick: int = -1
|
|
while not loop.sim.drop.is_over(loop.sim.tick):
|
|
loop.run_tick()
|
|
if leapt_tick < 0 and bot.drop_state != Drop.ABOARD:
|
|
leapt_tick = loop.sim.tick
|
|
if leapt_tick >= 0 and loop.sim.tick >= leapt_tick + Tuning.TICK_RATE_HZ * 5:
|
|
break
|
|
assert_eq(human.drop_state, Drop.ABOARD)
|
|
assert_true(human.position.distance_to(loop.sim.drop.barge_position(loop.sim.tick)) < 0.001)
|
|
assert_true(leapt_tick >= 0, "the bot should have leapt before the route ended")
|
|
assert_true(bot.position.y < Tuning.BARGE_ALTITUDE - 20.0, "the bot should be falling, at %s" % bot.position)
|
|
|
|
|
|
func test_same_seed_gives_the_same_match() -> void:
|
|
var first: String = _run(2026, 2, 22, 300).sim.state_hash()
|
|
var second: String = _run(2026, 2, 22, 300).sim.state_hash()
|
|
assert_eq(first, second)
|
|
assert_ne(first, _run(2027, 2, 22, 300).sim.state_hash())
|
|
|
|
|
|
func test_server_returns_to_the_lobby_and_starts_the_next_match() -> void:
|
|
var rules: MatchRules = MatchRules.immediate()
|
|
rules.max_players = 3
|
|
rules.min_players = 0
|
|
rules.results_ticks = 3
|
|
var loop: ServerLoop = ServerLoop.new(5, 0, 3, rules)
|
|
assert_eq(loop.match_flow.phase, Match.DROP)
|
|
assert_eq(loop.bots.size(), 3)
|
|
var first_seed: int = loop.match_flow.current_seed()
|
|
for bot: BotBrain in loop.bots.slice(1):
|
|
loop.sim.entities.find(bot.player_id).health = 0
|
|
loop.run_tick()
|
|
assert_eq(loop.match_flow.phase, Match.RESULTS)
|
|
for _index: int in 4:
|
|
loop.run_tick()
|
|
assert_eq(loop.match_flow.phase, Match.DROP, "lobby and countdown pass at once")
|
|
assert_eq(loop.match_flow.matches_started, 2)
|
|
assert_ne(loop.match_flow.current_seed(), first_seed)
|
|
assert_eq(loop.bots.size(), 3, "bots are rebuilt for the new match")
|
|
assert_eq(loop.player_ids, [1, 2, 3] as Array[int])
|
|
assert_eq(loop.ticks, 5)
|
|
|
|
|
|
## H12: the next island's bot navigation is made on the worker with the island, and
|
|
## is the same as navigation made on the main thread.
|
|
func test_the_next_islands_navigation_is_made_in_the_background() -> void:
|
|
var rules: MatchRules = MatchRules.new()
|
|
rules.max_players = 2
|
|
rules.min_players = 0
|
|
rules.lobby_ticks = 2
|
|
rules.countdown_ticks = 2
|
|
rules.results_ticks = 2
|
|
rules.fill_with_bots = false
|
|
var loop: ServerLoop = ServerLoop.new(77, 0, 0, rules)
|
|
var first: NavGrid = loop.nav
|
|
while loop.match_flow.phase != Match.RESULTS:
|
|
loop.run_tick()
|
|
while loop.match_flow.phase != Match.LOBBY:
|
|
loop.run_tick()
|
|
assert_true(loop.nav != first, "new navigation for the new island")
|
|
assert_true(loop.match_flow.prepared.has("nav"), "made by the worker")
|
|
var fresh: NavGrid = NavGrid.build(loop.match_flow.sim)
|
|
assert_true(loop.nav.heights == fresh.heights, "the same heights")
|
|
assert_true(loop.nav.blocked == fresh.blocked, "the same blocked cells")
|
|
assert_eq(loop.nav.main_region, fresh.main_region)
|
|
assert_true(loop.world.walkable == BotWorld.build(loop.match_flow.sim, fresh).walkable)
|