M6: Bots that build

Bots now gather materials with the boathook and build with the same build
command and Building.check a player's client goes through:

- Gathering: an armed bot with nothing more pressing gathers from props
  nearby (12 m while looting, 24 m once there's nothing left to loot) up to
  60 of a material, or 120 in the last three tide phases. Not within 10 s of
  seeing an opponent or being hit, and not when hurt.
- Cover: a wall toward a shooter who catches it reloading, from ambush or
  worn down to 60, then waits behind it to reload or heal.
- Wall and heal: a badly hurt bot that would break off walls itself off and
  heals where it stands instead, if it can afford a wall.
- Ramps: a staircase of ramps, each from the top of the last, up to an
  opponent on a cliff or a steep rise (at most 5 a fight).
- Breakwaters: late in the match, a bot the tide would catch before it
  reached dry ground, or one at the last stand, rings its cell with four
  breakwaters and stays inside while they hold.

Measured with the new `make bot-builds` (tools/bot_builds.gd): every other
bot builds and the rest are a control group. Over 40 matches, seeds 501 to
540: builders built in 53% of the fights they began with materials for a
wall (12% of all fights; most fights are in the landing, before anyone has
gathered), lost 58% of the fights they built in against 67% of the rest,
and placed 12.1 on average against the control's 12.8. Overall fight losses
(65.8% / 65.7%) and wins (20 / 20) came out level; docs/BALANCE.md has the
numbers and the earlier batches that led to the careful gathering. Worst
p99 tick 3.4 ms of the 12 ms budget.

Closes #29

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 01:13:25 -05:00
co-authored by Claude Opus 5.5
parent 4177bfff76
commit eb239c5424
15 changed files with 1135 additions and 16 deletions
+66 -2
View File
@@ -14,8 +14,14 @@ static func tick_limit() -> int:
## "causes": {cause: count}, "places": {difficulty name: [place, ...]},
## "eliminations": {difficulty name: count}, "weapon_kills": {item id: count},
## "death_seconds": [seconds into the match of each fall], "shots", "slow_ticks",
## "timing", "state_hash"}. Seconds count from the barge leaving.
static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficulty: int = -1) -> Dictionary:
## "timing", "state_hash", "building": {"build": group, "control": group}}. Seconds
## count from the barge leaving. Each group (M6) adds up its bots' BotBrain.stats and
## holds their "bots", "places" and "wins".
##
## With `split_builders`, only every other bot gathers and builds; the rest are the
## control group. Bot difficulty also goes by turns of three, so both groups have each
## level equally (within one bot).
static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficulty: int = -1, split_builders: bool = false) -> Dictionary:
var loop: ServerLoop = ServerLoop.new(seed_value, 0, bots, null, difficulty)
var flow: Match = loop.match_flow
var level_of: Dictionary = {}
@@ -27,7 +33,13 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul
"slow_ticks": [], "weapon_kills": {}, "death_seconds": [],
}
var limit: int = tick_limit()
var split: bool = false
while loop.ticks < limit and flow.phase != Match.RESULTS:
if split_builders and not split and not loop.bots.is_empty():
# The bots join when the match starts, before any of them thinks.
split = true
for index: int in loop.bots.size():
loop.bots[index].builds = index % 2 == 0
var before: int = Time.get_ticks_usec()
loop.run_tick()
if Time.get_ticks_usec() - before > ServerLoop.TICK_BUDGET_USEC:
@@ -62,6 +74,19 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul
# The boathook isn't in the catalog: its code is ItemCatalog.NONE.
var weapon: String = def.id if def != null else (ItemCatalog.BOATHOOK if int(record["item"]) == ItemCatalog.NONE else "unknown")
result["weapon_kills"][weapon] = int(result["weapon_kills"].get(weapon, 0)) + 1
var place_of: Dictionary = {}
for row: Dictionary in flow.summary():
place_of[row["handle"]] = row["place"]
var groups: Dictionary = {"build": _empty_group(), "control": _empty_group()}
for bot: BotBrain in loop.bots:
var group: Dictionary = groups["build" if bot.builds else "control"]
group["bots"] += 1
for key: String in bot.stats:
group[key] += int(bot.stats[key])
var place: int = int(place_of.get(flow.handle_of[bot.player_id], 0))
group["places"].append(place)
group["wins"] += 1 if place == 1 else 0
result["building"] = groups
result["timing"] = loop.timing_stats()
result["state_hash"] = loop.sim.state_hash()
return result
@@ -104,3 +129,42 @@ static func summarise(results: Array[Dictionary]) -> Dictionary:
total["drown_share"] = float(total["causes"].get("drown", 0)) / maxi(total["deaths"], 1)
total["mean_ticks"] = ticks / maxi(results.size(), 1)
return total
static func _empty_group() -> Dictionary:
var group: Dictionary = {"bots": 0, "places": [], "wins": 0}
for key: String in BotBrain.new(0).stats:
group[key] = 0
return group
## Adds up the "building" groups of run_match() results: per group the totals, plus
## "mean_place", "fight_share_built" (fights with a piece placed in them, of all
## fights), "stocked_share" (fights begun with the materials for a wall, of all fights),
## "stocked_share_built" (of those, the ones built in) and "fight_loss" (fights lost,
## of all fights), and for the build group
## "loss_when_built" and "loss_when_not".
static func summarise_building(results: Array[Dictionary]) -> Dictionary:
var total: Dictionary = {"build": _empty_group(), "control": _empty_group()}
for result: Dictionary in results:
for name: String in total:
var group: Dictionary = result["building"][name]
for key: String in group:
if key == "places":
total[name]["places"].append_array(group["places"])
else:
total[name][key] += int(group[key])
for name: String in total:
var group: Dictionary = total[name]
var sum: int = 0
for place: int in group["places"]:
sum += place
group["mean_place"] = float(sum) / maxi(group["places"].size(), 1)
group["fight_share_built"] = float(group["fights_built"]) / maxi(group["fights"], 1)
group["stocked_share"] = float(group["fights_stocked"]) / maxi(group["fights"], 1)
group["stocked_share_built"] = float(group["fights_stocked_built"]) / maxi(group["fights_stocked"], 1)
group["fight_loss"] = float(group["fights_lost"]) / maxi(group["fights"], 1)
group["loss_when_built"] = float(group["fights_built_lost"]) / maxi(group["fights_built"], 1)
group["loss_when_not"] = float(group["fights_lost"] - group["fights_built_lost"]) / maxi(group["fights"] - group["fights_built"], 1)
group.erase("places")
return total