M4: Bot navigation

NavGrid is the map bots plan on: a point per 2 m terrain sample, solid on cliffs and
where solids stand between step and head height, and costlier where the water is
deeper than wading. Path search uses Godot's AStarGrid2D. The grid syncs every tick:
new solids (walls, pieces) block points at once, removed ones are found by a rolling
scan, and points turn wet as the tide and flood reach them. Each change is stamped
with its tick.

NavBot follows a path with ordinary PlayerCommands: it steers at waypoints, sprints
on long dry stretches, jumps when stalled, and marks a point blocked after repeated
stalls. Every half second it checks its remaining path against the change stamps and
plans again if water or a wall now crosses it. One path is planned per server tick
across all bots.

The server builds the grid while the lobby waits and its bots now roam between
random reachable places, replacing the placeholder wander bot.

Tests: 150 of 150 random reachable targets reached on 50 islands in the sweep; the
test runs 2 per island and needs 95%. New walls and rising water both cause a new
path around them; a broken wall opens the grid again; with no dry way round, the bot
swims. 23 roaming bots on an island: p99 tick 1.6 ms against the 12 ms budget.

Closes #27

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 23:38:36 -05:00
co-authored by Claude Opus 5.5
parent 6e1c87fe32
commit cc652de46e
14 changed files with 863 additions and 39 deletions
+12 -4
View File
@@ -14,7 +14,9 @@ var sim: Simulation:
return match_flow.sim
## Entity IDs of everyone in the current match, humans first.
var player_ids: Array[int] = []
var bots: Array[WanderBot] = []
var bots: Array[NavBot] = []
## The current or next match's navigation grid, built while the lobby waits.
var nav: NavGrid = null
## Wall-clock duration of every tick run, in microseconds.
var tick_usec: PackedInt64Array = PackedInt64Array()
## Server ticks run, across every match.
@@ -32,6 +34,7 @@ func _init(match_seed: int, human_players: int, bot_count: int, rules: MatchRule
# With only bots there's nobody to wait for, so the lobby starts with no one in it.
rules.min_players = 0 if human_players == 0 and bot_count > 0 else 1
match_flow = Match.new(match_seed, rules)
nav = NavGrid.build(match_flow.sim)
for handle: int in range(1, human_players + 1):
match_flow.join(handle)
if rules.lobby_ticks == 0 and rules.countdown_ticks == 0:
@@ -43,8 +46,9 @@ func _init(match_seed: int, human_players: int, bot_count: int, rules: MatchRule
func run_tick() -> void:
var started: int = Time.get_ticks_usec()
if match_flow.in_match():
for bot: WanderBot in bots:
sim.submit_command(bot.player_id, bot.think(sim))
nav.sync(sim)
for bot: NavBot in bots:
sim.submit_command(bot.player_id, bot.think(sim, nav))
_advance()
ticks += 1
tick_usec.append(Time.get_ticks_usec() - started)
@@ -58,6 +62,8 @@ func _advance() -> void:
elif event["type"] == "phase" and event["to"] == "lobby":
player_ids.clear()
bots.clear()
if event["from"] == "results":
nav = NavGrid.build(match_flow.sim)
func _track_players() -> void:
@@ -67,7 +73,9 @@ func _track_players() -> void:
var entity_id: int = match_flow.entity_of[handle]
player_ids.append(entity_id)
if match_flow.bot_handles.has(handle):
bots.append(WanderBot.new(entity_id))
var bot: NavBot = NavBot.new(entity_id)
bot.roam = true
bots.append(bot)
## Timing statistics over every tick run so far, in microseconds.