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:
2026-11-14 06:28:15 -05:00
co-authored by Claude Opus 5.5
parent ffb68a1e89
commit 38812120df
24 changed files with 774 additions and 61 deletions
+85 -9
View File
@@ -65,7 +65,16 @@ var _skipped_pickups: Dictionary = {}
var _skipped_chests: Dictionary = {}
var _loot_checked: int = -100000
var _interact_last: bool = false
## Health and armor at or under which this bot breaks off a fight, and until when it's
## running from one (H3).
var _retreat_health: int = 0
var _retreat_until: int = -100000
var _retreat_goal: Vector3 = Vector3.ZERO
## Who last hit this bot, and when: an unarmed bot only swings back at them.
var _hit_by: int = 0
var _hit_tick: int = -100000
var _hunt_goal: Vector3 = Vector3.ZERO
var _holding: bool = false
var _hunt_until: int = 0
var _goal_set: bool = false
## Walking a point of interest's route: the stage, the route, the next point on it and
@@ -93,6 +102,7 @@ func _init(id: int, level: int = NORMAL) -> void:
_aim_error_degrees = float(stats["aim_error"])
_sight = float(stats["sight"])
_lead = float(stats["lead"])
_retreat_health = int(stats["retreat"])
func difficulty_name() -> String:
@@ -116,16 +126,20 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
var armed: bool = _weapon_slot >= 0
var selection: int = _weapon_slot + 1 if armed else Simulation.BOATHOOK_SLOT
var buttons: int = 0
var fighting: bool = target != null and target_visible and armed and not me.swimming
# Inside a hut or loft too: someone beating on you there gets a swing back.
_check_retreat(sim, world, me, target, armed)
var retreating: bool = sim.tick < _retreat_until
var fighting: bool = target != null and target_visible and armed and not me.swimming and not retreating
# Inside a hut or loft too: someone beating on you there gets a swing back. An
# unarmed bot doesn't start a brawl; it keeps looking for a weapon (H3).
var provoked: bool = target != null and target.id == _hit_by and sim.tick - _hit_tick <= roundi(Tuning.BOT_MEMORY_SECONDS * TICKS)
var brawling: bool = (target != null and target_visible and not armed and not me.swimming
and not _fleeing and distance <= Tuning.BOT_BRAWL_METRES)
and not _fleeing and not retreating and distance <= Tuning.BOT_BRAWL_METRES and provoked)
var interact: bool = false
var walk: bool = true
# Where to go.
_direct_on = false
var urgent: bool = _fleeing or (target != null and armed)
var urgent: bool = _fleeing or retreating or (target != null and armed)
if _stage != OUTSIDE:
# Inside a hut or up a loft: loot, or walk back out first if something's up.
if urgent and _stage != LEAVING:
@@ -135,6 +149,9 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
elif _fleeing:
state = "flee"
_go(_flee_goal, 3.0)
elif retreating:
state = "retreat"
_go(_retreat_goal, 3.0)
elif fighting:
state = "fight"
_stop()
@@ -185,7 +202,7 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
buttons &= ~PlayerCommand.BUTTON_SPRINT
# Fighting: face the target and fire, whatever the feet are doing.
if target != null and target_visible and armed and not me.swimming:
if fighting or (target != null and target_visible and armed and not me.swimming and _fleeing):
var def: ItemDef = ItemCatalog.get_def(me.slot_items[_weapon_slot])
var aim: Vector2 = _aim_at(me, target, def)
yaw = aim.x
@@ -258,7 +275,21 @@ func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
var closest: Vector2 = Geometry2D.get_closest_point_to_segment(at, a, b)
if at.distance_to(closest) <= 120.0 and world.markers[index].y > sim.sea_level + 1.0:
near.append(index)
_landing = near[rng.randi_range(0, near.size() - 1)] if not near.is_empty() else rng.randi_range(0, world.markers.size() - 1)
if near.is_empty():
_landing = rng.randi_range(0, world.markers.size() - 1)
else:
# Of a few spots, land at the one fewest others have picked nearby (H3).
var best_crowd: int = 1 << 30
for _try: int in Tuning.BOT_LANDING_CHOICES:
var pick: int = near[rng.randi_range(0, near.size() - 1)]
var crowd: int = 0
for other: Vector3 in world.landings:
if other.distance_to(world.markers[pick]) <= Tuning.BOT_LANDING_SPREAD_METRES:
crowd += 1
if crowd < best_crowd:
best_crowd = crowd
_landing = pick
world.landings.append(world.markers[_landing])
_marker = _landing
_marker_since = sim.tick
_go(world.markers[_landing], 2.0)
@@ -276,6 +307,9 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
_forget_target()
# Being hit tells a player roughly where it came from.
var attacker_id: int = int(world.attackers.get(player_id, 0))
if attacker_id != 0 and attacker_id != player_id:
_hit_by = attacker_id
_hit_tick = tick
if attacker_id != 0 and attacker_id != player_id and not target_visible:
var attacker: SimEntity = sim.entities.find(attacker_id)
if attacker != null and not attacker.eliminated:
@@ -308,8 +342,11 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
var other: SimEntity = sim.entities.find(other_id)
if other == null or other.eliminated or other.drop_state != Drop.NONE:
continue
# A bot picks out a new opponent only this close; one who shoots it first is
# fought at any range it can see (H3).
var gap: float = me.position.distance_squared_to(other.position)
if gap <= _sight * _sight:
var notice: float = minf(_sight, Tuning.BOT_ENGAGE_METRES)
if gap <= notice * notice:
candidates.append(Vector2(gap, other_id))
candidates.sort()
for index: int in mini(candidates.size(), 3):
@@ -341,6 +378,35 @@ func _can_see(sim: Simulation, world: BotWorld, me: SimEntity, other: SimEntity,
return world.clear_line(sim.ground, Harvest.eye(me), chest)
## Breaks off a fight: runs away from the opponent, over safe ground, for
## BOT_RETREAT_SECONDS, then heals if it can. Any bot without a gun runs from one held
## in view; a bot badly hurt with a way to heal breaks off too, except easy ones.
func _check_retreat(sim: Simulation, world: BotWorld, me: SimEntity, target: SimEntity, armed: bool) -> void:
if target == null or _fleeing or sim.tick < _retreat_until or me.swimming:
return
var outgunned: bool = not armed and target_visible and _holds_gun(target)
var hurt: bool = _retreat_health > 0 and me.health + me.armor <= _retreat_health and _heal_slot(me) >= 0
if not outgunned and not hurt:
return
if sim.tick - _retreat_until < roundi(Tuning.BOT_RETREAT_SECONDS * TICKS):
return
var away: Vector3 = me.position - target.position
away.y = 0.0
away = away.normalized() if away.length() > 0.1 else Vector3(1.0, 0.0, 0.0)
var phase: int = sim.tide.phase_at(sim.tick) if sim.tide != null else 0
_retreat_goal = world.random_safe_near(nav.stream(sim), phase, me.position + away * Tuning.BOT_RETREAT_METRES, Tuning.BOT_RETREAT_METRES * 0.5)
_retreat_until = sim.tick + roundi(Tuning.BOT_RETREAT_SECONDS * TICKS)
_forget_target()
## True if `other` has a gun in hand.
static func _holds_gun(other: SimEntity) -> bool:
if other.selected == Simulation.BOATHOOK_SLOT or other.selected > other.slot_items.size():
return false
var def: ItemDef = ItemCatalog.get_def(other.slot_items[other.selected - 1])
return def != null and def.kind == ItemDef.WEAPON and def.damage > 0
func _forget_target() -> void:
target_id = 0
target_visible = false
@@ -773,13 +839,23 @@ func _next_marker(sim: Simulation, world: BotWorld, me: SimEntity) -> int:
## Nothing to loot: wander the ground the tide will leave, where the others will be.
## With nothing to loot: roams to safe ground nearby, and holds there for a while
## before moving on (H3). The tide check moves it sooner if the water is coming.
func _hunt(sim: Simulation, world: BotWorld) -> void:
state = "hunt"
var arrived: bool = _goal_set and nav.status != NavBot.MOVING
if not _goal_set or arrived or sim.tick >= _hunt_until:
if arrived and not _holding:
_holding = true
_hunt_until = sim.tick + roundi(Tuning.BOT_HOLD_SECONDS * TICKS)
if (not _goal_set and not _holding) or sim.tick >= _hunt_until:
var phase: int = sim.tide.phase_at(sim.tick) if sim.tide != null else 0
_hunt_goal = world.random_safe(nav.stream(sim), phase)
var me: SimEntity = sim.entities.find(player_id)
_hunt_goal = world.random_safe_near(nav.stream(sim), phase, me.position, Tuning.BOT_ROAM_METRES)
_hunt_until = sim.tick + 40 * TICKS
_holding = false
_go(_hunt_goal, 4.0)
elif _holding:
state = "hold"
_stop()
else:
_go(_hunt_goal, 4.0)