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)
+18
View File
@@ -42,6 +42,8 @@ var phase_tops: Array[Vector3] = []
## 1 for each grid cell a bot can walk to: open on the navigation grid and joined to the
## rest of the island. Safe ground a bot is sent to is always one of these.
var walkable: PackedByteArray = PackedByteArray()
## Where bots have chosen to land this match, so later bots can spread out (H3).
var landings: Array[Vector3] = []
## Victim entity ID -> attacker entity ID, for hits landed during the last tick.
var attackers: Dictionary = {}
@@ -183,6 +185,22 @@ func random_safe(rng: RandomNumberGenerator, phase: int) -> Vector3:
return phase_tops[phase]
## A random point of phase `phase`'s safe ground within `radius` of `centre`, or one
## anywhere on it (random_safe) if a few tries find none that close.
func random_safe_near(rng: RandomNumberGenerator, phase: int, centre: Vector3, radius: float) -> Vector3:
phase = clampi(phase, 0, phase_count() - 1)
if phase_cells[phase] == 0:
return phase_tops[phase]
var marks: PackedByteArray = phase_marks[phase]
for _try: int in 24:
var angle: float = rng.randf() * TAU
var reach: float = sqrt(rng.randf()) * radius
var cell: int = _cell_of(centre + Vector3(cos(angle) * reach, 0.0, sin(angle) * reach))
if marks[cell] != 0:
return _cell_position(cell)
return random_safe(rng, phase)
## True if nothing solid stands between two points: terrain, checked every couple of
## metres, and solids. Players don't block it.
func clear_line(ground: SimGround, from: Vector3, to: Vector3) -> bool:
+9 -3
View File
@@ -36,6 +36,8 @@ var _stuck_ticks: int = 0
var _stuck_tries: int = 0
var _jump_next: bool = false
var _leap_tick: int = -1
## How far the goal was from the barge last tick, while riding.
var _ride_gap: float = INF
var _rng: RandomNumberGenerator = null
var _rng_seed: int = 0
@@ -173,15 +175,19 @@ func _steer(sim: Simulation, player: SimEntity, target: Vector3, buttons: int) -
return PlayerCommand.from_input(sim.tick, Vector2(0.0, 1.0), atan2(to.x, to.y), 0.0, buttons)
## Aboard the barge: leap once the goal is within gliding reach, or at a time set by
## the player ID, whichever comes first. The end of the route puts everyone off anyway.
## Aboard the barge: leap once the goal is within gliding reach, or once the barge
## starts drawing away from it; with no goal, at a time set by the player ID. The end of the route puts everyone off anyway.
func _ride(sim: Simulation, player: SimEntity) -> PlayerCommand:
if _leap_tick < 0 and sim.drop != null:
_leap_tick = sim.drop.began_tick + Tuning.TICK_RATE_HZ * 2 + (player_id * 53) % (Tuning.TICK_RATE_HZ * 20)
var leap: bool = sim.tick >= _leap_tick
if status == MOVING:
# With somewhere to land, wait until it's in gliding reach, or until the barge
# has passed it and is drawing away (H3: bots used to leap on the timer and land
# hundreds of metres short).
var gap: float = Vector2(goal.x - player.position.x, goal.z - player.position.z).length()
leap = leap or gap < 0.6 * (player.position.y - goal.y)
leap = gap < 0.6 * (player.position.y - goal.y) or gap > _ride_gap + 0.01
_ride_gap = gap
var buttons: int = PlayerCommand.BUTTON_JUMP if leap else 0
return PlayerCommand.from_input(sim.tick, Vector2.ZERO, 0.0, 0.0, buttons)
+19 -9
View File
@@ -20,9 +20,11 @@ const STEP_NAMES: Array[String] = ["wait", "harvest", "build", "done"]
const WANTED_DRIFTWOOD: int = 45
## How far to look for something to cut, in metres.
const SEARCH_RADIUS: float = 45.0
const FAR_SEARCH_RADIUS: float = 250.0
## Starts the script this long after landing even with no weapon found.
const UNARMED_WAIT_SECONDS: float = 45.0
## Gives up on one prop, and on the whole script, after this long.
## Gives up on one prop after this long (plus the walk to it), and on the whole script
## after SCRIPT_TIMEOUT_SECONDS.
const PROP_TIMEOUT_SECONDS: float = 25.0
const SCRIPT_TIMEOUT_SECONDS: float = 150.0
## Inside this distance the script walks straight at the prop instead of path-finding.
@@ -38,6 +40,7 @@ var _script_since: int = 0
var _driving: bool = false
var _prop: int = -1
var _prop_since: int = 0
var _prop_deadline: int = 0
var _skipped_props: Dictionary = {}
var _to_build: Array[int] = [StructureSet.BREAKWATER, StructureSet.WALL]
var _build_yaw: float = 0.0
@@ -108,11 +111,14 @@ func _harvest(sim: Simulation, grid: NavGrid, me: SimEntity) -> PlayerCommand:
_build_yaw = float(me.yaw) / PlayerCommand.YAW_STEPS * TAU
return _hold(sim, me)
var standing: bool = _prop >= 0 and sim.props.is_standing(_prop)
if not standing or sim.tick - _prop_since > roundi(PROP_TIMEOUT_SECONDS * TICKS):
if not standing or sim.tick > _prop_deadline:
if standing:
_skipped_props[_prop] = true
_prop = _find_prop(sim, me)
_prop_since = sim.tick
# A far prop gets time to walk there too, at about 4 m/s.
var far: float = PropSet._distance_to_box(sim.props.boxes[_prop], me.position) if _prop >= 0 else 0.0
_prop_deadline = sim.tick + roundi((PROP_TIMEOUT_SECONDS + far / 4.0) * TICKS)
if _prop < 0:
step = DONE
return _hold(sim, me)
@@ -138,14 +144,18 @@ func _harvest(sim: Simulation, grid: NavGrid, me: SimEntity) -> PlayerCommand:
return walk
## The nearest standing driftwood prop on dry ground that hasn't been given up on.
## The nearest standing driftwood prop on dry ground that hasn't been given up on:
## close by and about level if there is one, or else anywhere within FAR_SEARCH_RADIUS
## (since H3 bots land where they meant to, often inland, away from the beaches).
func _find_prop(sim: Simulation, me: SimEntity) -> int:
for prop: int in sim.props.near(me.position, SEARCH_RADIUS):
if _skipped_props.has(prop) or sim.props.material_of(prop) != Materials.NAMES[Materials.DRIFTWOOD]:
continue
var box: AABB = sim.props.boxes[prop]
if box.position.y > sim.sea_level + 0.5 and absf(box.position.y - me.position.y) < 8.0:
return prop
for radius: float in [SEARCH_RADIUS, FAR_SEARCH_RADIUS]:
for prop: int in sim.props.near(me.position, radius):
if _skipped_props.has(prop) or sim.props.material_of(prop) != Materials.NAMES[Materials.DRIFTWOOD]:
continue
var box: AABB = sim.props.boxes[prop]
var level: bool = absf(box.position.y - me.position.y) < 8.0 or radius > SEARCH_RADIUS
if box.position.y > sim.sea_level + 0.5 and level:
return prop
return -1
+39 -12
View File
@@ -217,13 +217,13 @@ const PROP_POI_CLEARANCE: float = 3.0
# must exceed ISLAND_MAX_HEIGHT, so that every match ends.
const ISLAND_MAX_HEIGHT: float = 70.0
const TIDE_PHASES: Array[Dictionary] = [
{"hold": 150.0, "rise": 60.0, "level": 8.0, "drown_dps": 2, "surge": 0},
{"hold": 100.0, "rise": 50.0, "level": 18.0, "drown_dps": 4, "surge": 40},
{"hold": 80.0, "rise": 45.0, "level": 30.0, "drown_dps": 6, "surge": 60},
{"hold": 60.0, "rise": 40.0, "level": 42.0, "drown_dps": 8, "surge": 80},
{"hold": 45.0, "rise": 35.0, "level": 54.0, "drown_dps": 12, "surge": 100},
{"hold": 30.0, "rise": 30.0, "level": 64.0, "drown_dps": 16, "surge": 120},
{"hold": 20.0, "rise": 40.0, "level": 75.0, "drown_dps": 25, "surge": 150},
{"hold": 150.0, "rise": 60.0, "level": 6.0, "drown_dps": 2, "surge": 0},
{"hold": 130.0, "rise": 50.0, "level": 14.0, "drown_dps": 4, "surge": 40},
{"hold": 120.0, "rise": 45.0, "level": 24.0, "drown_dps": 6, "surge": 60},
{"hold": 110.0, "rise": 40.0, "level": 34.0, "drown_dps": 8, "surge": 80},
{"hold": 90.0, "rise": 35.0, "level": 46.0, "drown_dps": 12, "surge": 100},
{"hold": 60.0, "rise": 30.0, "level": 58.0, "drown_dps": 16, "surge": 120},
{"hold": 45.0, "rise": 40.0, "level": 75.0, "drown_dps": 25, "surge": 150},
]
## Each island's levels are planned from its terrain (SafeGround): a phase's level is
## lowered, if need be, to this far under the top of the largest piece of land still
@@ -270,11 +270,12 @@ const BOT_PATH_CHECK_TICKS: int = 15
## Per difficulty: `reaction` is seconds between first seeing an opponent and firing,
## `aim_error` the most their aim wanders off the target in degrees, `sight` how far
## they can pick an opponent out in metres, and `lead` how much of a moving target's
## travel they allow for with slow shots (0 none, 1 all of it).
## travel they allow for with slow shots (0 none, 1 all of it), and `retreat` the health
## plus armor at or under which they break off a fight to heal (0 never).
const BOT_DIFFICULTIES: Array[Dictionary] = [
{"name": "easy", "reaction": 0.9, "aim_error": 7.0, "sight": 45.0, "lead": 0.0},
{"name": "normal", "reaction": 0.5, "aim_error": 3.5, "sight": 65.0, "lead": 0.5},
{"name": "hard", "reaction": 0.25, "aim_error": 1.5, "sight": 90.0, "lead": 1.0},
{"name": "easy", "reaction": 0.9, "aim_error": 9.0, "sight": 45.0, "lead": 0.0, "retreat": 0},
{"name": "normal", "reaction": 0.5, "aim_error": 5.5, "sight": 65.0, "lead": 0.5, "retreat": 35},
{"name": "hard", "reaction": 0.25, "aim_error": 3.0, "sight": 90.0, "lead": 1.0, "retreat": 50},
]
## Each bot looks around once in this many ticks.
const BOT_SENSE_TICKS: int = 6
@@ -288,6 +289,22 @@ const BOT_MEMORY_SECONDS: float = 4.0
const BOT_AIM_WANDER_TICKS: int = 12
## Bots ease off the trigger while bloom is above this, in degrees.
const BOT_BLOOM_PAUSE_DEGREES: float = 3.0
## Bots pick out a new opponent only this close (or their `sight`, if less). Anyone who
## shoots them is fought as far off as they can see. Without it bot lobbies emptied in
## the first two minutes; see docs/BALANCE.md.
const BOT_ENGAGE_METRES: float = 30.0
## A bot breaking off a fight runs for this long towards safe ground about this far
## away from its opponent, and won't break off again until as long again has passed.
const BOT_RETREAT_SECONDS: float = 6.0
const BOT_RETREAT_METRES: float = 30.0
## A bot weighs this many landing spots near the barge's line and takes the one with
## the fewest other bots' landings within BOT_LANDING_SPREAD_METRES.
const BOT_LANDING_CHOICES: int = 8
const BOT_LANDING_SPREAD_METRES: float = 60.0
## With nothing to loot, a bot roams to safe ground at most this far from where it is.
const BOT_ROAM_METRES: float = 60.0
## Having roamed there, it holds that ground this long before moving on.
const BOT_HOLD_SECONDS: float = 45.0
## Bots notice items lying within this distance.
const BOT_LOOT_SIGHT_METRES: float = 12.0
## A bot with no gun goes for an opponent in view this close with its boathook, in
@@ -412,7 +429,7 @@ const WEAPONS: Dictionary = {
"spread": 0.8, "bloom": 0.6, "ammo": "cartridges", "headshot": 2.0,
},
"rivet_repeater": {
"damage": 17, "fire_rate": 11.0, "magazine": 35, "reload": 2.0,
"damage": 15, "fire_rate": 11.0, "magazine": 35, "reload": 2.0,
"range_full": 12.0, "range_max": 45.0, "falloff_min": 0.4, "rarity": 0,
"spread": 2.4, "bloom": 0.25, "ammo": "cartridges", "headshot": 1.5,
},
@@ -512,3 +529,13 @@ const LOOT_THROWN_COUNT: int = 2
const CHEST_RANGE: float = 2.5
## Loot from one spot lands on a ring this far from it.
const LOOT_SCATTER_METRES: float = 0.7
# Balance targets (H3), judged by `make balance` over bot-only matches; see docs/BALANCE.md.
## The pass needs at least this many matches.
const BALANCE_MIN_MATCHES: int = 200
## The median match, from the barge leaving to the last player standing, lasts this
## many minutes.
const BALANCE_MEDIAN_MINUTES_MIN: float = 12.0
const BALANCE_MEDIAN_MINUTES_MAX: float = 18.0
## No one weapon takes more than this share of the eliminations made with weapons.
const BALANCE_MAX_WEAPON_SHARE: float = 0.35