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
+86
View File
@@ -0,0 +1,86 @@
## M6: measures whether bots that build do better. Plays bot-only matches in which
## every other bot gathers and builds and the rest don't (BotBatch's split_builders),
## and compares the two groups.
##
## tools/godot.sh --script res://tools/bot_builds.gd -- [--seeds=20] [--first=501] [--out=FILE]
##
## Prints one JSON line per match and a summary, and checks: of the fights builders
## begin with the materials for a wall, they place a piece in at least STOCKED_SHARE;
## they lose a smaller share of the fights they built in than of the rest; their mean
## place is no worse than the control group's; and every match's p99 tick is within
## the budget. Exits 1 if a check fails.
##
## How the two groups' fight losses and wins compare overall is printed but not judged:
## over 40 matches (2026-11-15) they came out level, so building helps a bot in the
## fights it builds in without, yet, making builders win more. See docs/BALANCE.md.
extends SceneTree
## Fewer matches than this are reported but not judged.
const MIN_MATCHES: int = 20
## Builders must place a piece in at least this share of the fights they begin with
## enough for a wall. (Most fights are in the landing, before anyone has gathered, so
## the share of all fights is reported but not judged.)
const STOCKED_SHARE: float = 0.35
func _init() -> void:
var count: int = 40
var first: int = 501
var out_path: String = ""
for arg: String in OS.get_cmdline_user_args():
if arg.begins_with("--seeds="):
count = arg.trim_prefix("--seeds=").to_int()
elif arg.begins_with("--first="):
first = arg.trim_prefix("--first=").to_int()
elif arg.begins_with("--out="):
out_path = arg.trim_prefix("--out=")
var out: FileAccess = FileAccess.open(out_path, FileAccess.WRITE) if out_path != "" else null
var results: Array[Dictionary] = []
var worst_p99: int = 0
var over_budget: int = 0
var unfinished: int = 0
for seed_value: int in range(first, first + count):
var result: Dictionary = BotBatch.run_match(seed_value, Tuning.SOLO_PLAYERS, -1, true)
results.append(result)
worst_p99 = maxi(worst_p99, int(result["timing"]["p99_us"]))
over_budget += int(result["timing"]["over_budget"])
unfinished += 0 if result["finished"] and result["winner"] != 0 else 1
var line: String = JSON.stringify({
"seed": seed_value, "ticks": result["ticks"], "winner": result["winner"],
"p99_us": result["timing"]["p99_us"], "building": result["building"],
})
print(line)
if out != null:
out.store_line(line)
out.flush()
var total: Dictionary = BotBatch.summarise_building(results)
print(JSON.stringify({"summary": total, "worst_p99_us": worst_p99, "over_budget": over_budget}))
var build: Dictionary = total["build"]
var control: Dictionary = total["control"]
print("bot-builds: builders placed %d pieces (%d walls, %d ramps, %d breakwaters) and gathered %d" % [build["pieces"], build["walls"], build["ramps"], build["breakwaters"], build["harvested"]])
print("bot-builds: builders began %.1f%% of their fights with the materials for a wall, and built in %.1f%% of those" % [build["stocked_share"] * 100.0, build["stocked_share_built"] * 100.0])
print("bot-builds: builders built in %.1f%% of %d fights and lost %.1f%% of them (%.1f%% when they built, %.1f%% when not); control lost %.1f%% of %d" % [
build["fight_share_built"] * 100.0, build["fights"], build["fight_loss"] * 100.0,
build["loss_when_built"] * 100.0, build["loss_when_not"] * 100.0,
control["fight_loss"] * 100.0, control["fights"]])
print("bot-builds: mean place builders %.2f, control %.2f; wins builders %d, control %d; worst p99 tick %d us" % [
build["mean_place"], control["mean_place"], build["wins"], control["wins"], worst_p99])
var problems: Array[String] = []
if unfinished > 0:
problems.append("%d of %d matches didn't finish with a winner" % [unfinished, count])
if worst_p99 > ServerLoop.TICK_BUDGET_USEC:
problems.append("a match's p99 tick was %d us, over the %d us budget" % [worst_p99, ServerLoop.TICK_BUDGET_USEC])
if count < MIN_MATCHES:
print("bot-builds: %d matches are too few to judge (needs %d); only completion and timing were checked" % [count, MIN_MATCHES])
else:
if build["stocked_share_built"] < STOCKED_SHARE:
problems.append("builders built in only %.1f%% of the fights they could afford to (needs %.0f%%)" % [build["stocked_share_built"] * 100.0, STOCKED_SHARE * 100.0])
if build["loss_when_built"] >= build["loss_when_not"]:
problems.append("builders lost %.1f%% of the fights they built in, no fewer than the %.1f%% they didn't" % [build["loss_when_built"] * 100.0, build["loss_when_not"] * 100.0])
if build["mean_place"] > control["mean_place"]:
problems.append("builders' mean place %.2f is worse than control's %.2f" % [build["mean_place"], control["mean_place"]])
for problem: String in problems:
print("bot-builds FAIL: %s" % problem)
if problems.is_empty():
print("bot-builds: ok (%d matches)" % count)
quit(0 if problems.is_empty() else 1)
+1
View File
@@ -0,0 +1 @@
uid://js4sgnk27y5n
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# M6: plays bot-only matches in which every other bot builds, under nice, and compares
# builders with the rest. One JSON line per match goes to build/bot_builds/matches.jsonl.
# See tools/bot_builds.gd for what is checked.
#
# tools/bot_builds.sh seeds 501 to 540
# BOT_BUILDS_SEEDS=5 BOT_BUILDS_FIRST=40 tools/bot_builds.sh
set -uo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
count="${BOT_BUILDS_SEEDS:-40}"
first="${BOT_BUILDS_FIRST:-501}"
out="build/bot_builds"
mkdir -p "$out"
raw="$(nice -n 15 tools/godot.sh --script res://tools/bot_builds.gd -- --seeds="$count" --first="$first" --out="$PWD/$out/matches.jsonl" 2>&1)"
code=$?
grep -E '^bot-builds' <<<"$raw"
if grep -qE 'SCRIPT ERROR|^ERROR' <<<"$raw"; then
echo "bot-builds FAIL: engine or script errors"
grep -E -A3 'SCRIPT ERROR|^ERROR' <<<"$raw" | head -n 20
code=1
fi
if [[ "$code" -ne 0 ]] && ! grep -q '^bot-builds' <<<"$raw"; then
echo "bot-builds FAIL: the run exited $code"
tail -n 15 <<<"$raw"
fi
exit "$code"