M5: Bot looting, combat and tide awareness

BotBrain plays a match with the commands a player sends: it picks a landing
marker near the barge's route, loots points of interest (following their own
walking routes into huts, lofts and piers), fights opponents it can see,
bandages itself, and gets to ground the coming tide will leave dry. BotWorld
is the map every bot shares: loot markers, routes, and each tide phase's safe
ground, which is the dry land joined to the island's highest walkable ground.

Three difficulties (Tuning.BOT_DIFFICULTIES) set reaction time, sight range
and aim error. The server mixes them unless --bot-difficulty says otherwise.

NavGrid labels connected regions when it is built, so a goal that is cut off
is turned down without a search of the whole island (about 70 ms each).

make bot-matches plays 20 bot-only matches and checks winners, drownings and
difficulty. Seeds 101 to 120: 20 of 20 with a winner, 7 of 460 deaths were
drownings (1.5%), easy bots placed worst (13.7 against 11.8 and 12.0) and
hard bots took the most eliminations (186 against 137 and 132).

Closes #28

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 02:42:10 -05:00
co-authored by Claude Opus 5.5
parent 793caf2b12
commit 4db605c33d
23 changed files with 1691 additions and 19 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ func _ready() -> void:
if not config.has_seed:
config.match_seed = _fresh_seed()
Engine.max_fps = 0 if config.unthrottled else REALTIME_MAX_FPS
loop = ServerLoop.new(config.match_seed, config.players, config.bots)
loop = ServerLoop.new(config.match_seed, config.players, config.bots, null, config.bot_difficulty)
var started: Dictionary = config.to_dictionary()
started["engine"] = Engine.get_version_info()["string"]
started["tick_rate_hz"] = Tuning.TICK_RATE_HZ
+13 -1
View File
@@ -1,7 +1,8 @@
## Command-line configuration for a headless server.
##
## tools/godot.sh -- --server [--seed=N] [--port=N] [--players=N] [--bots=N]
## [--ticks=N] [--unthrottled] [--log-every=N]
## [--bot-difficulty=mixed|easy|normal|hard] [--ticks=N]
## [--unthrottled] [--log-every=N]
##
## Unknown or malformed arguments are errors, so a typo can't silently run the wrong
## match. See `parse()`.
@@ -23,6 +24,8 @@ var port: int = DEFAULT_PORT
## Player slots for human clients. Until v0.5 they join as idle players.
var players: int = 0
var bots: int = 0
## Every bot's difficulty, as an index into Tuning.BOT_DIFFICULTIES, or -1 to mix them.
var bot_difficulty: int = -1
## Ticks to run before exiting. 0 runs until the process is stopped.
var ticks: int = 0
## Runs ticks back to back instead of at the real tick rate. For tests and smoke runs.
@@ -59,6 +62,7 @@ func to_dictionary() -> Dictionary:
"port": port,
"players": players,
"bots": bots,
"bot_difficulty": "mixed" if bot_difficulty < 0 else String(Tuning.BOT_DIFFICULTIES[bot_difficulty]["name"]),
"ticks": ticks,
"unthrottled": unthrottled,
}
@@ -94,6 +98,14 @@ func _parse_one(arg: String) -> void:
"--log-every":
if _check_int(key, value):
log_every = value.to_int()
"--bot-difficulty":
var found: bool = value == "mixed"
for index: int in Tuning.BOT_DIFFICULTIES.size():
if Tuning.BOT_DIFFICULTIES[index]["name"] == value:
bot_difficulty = index
found = true
if not found:
errors.append("--bot-difficulty must be mixed, easy, normal or hard, got '%s'" % value)
"--fault":
fault = value
_:
+15 -8
View File
@@ -14,9 +14,12 @@ 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[NavBot] = []
## The current or next match's navigation grid, built while the lobby waits.
var bots: Array[BotBrain] = []
## The current or next match's navigation grid and bot map, built while the lobby waits.
var nav: NavGrid = null
var world: BotWorld = null
## Every bot's difficulty, or -1 to mix them: easy, normal, hard, in turn.
var bot_difficulty: int = -1
## Wall-clock duration of every tick run, in microseconds.
var tick_usec: PackedInt64Array = PackedInt64Array()
## Server ticks run, across every match.
@@ -26,7 +29,8 @@ var ticks: int = 0
## `human_players` join as idle participants with handles 1 and up; `bot_count` bots
## fill the rest of every match. With `rules` null the match starts at once, and the
## server goes back to the lobby after each match's results and starts another.
func _init(match_seed: int, human_players: int, bot_count: int, rules: MatchRules = null) -> void:
func _init(match_seed: int, human_players: int, bot_count: int, rules: MatchRules = null, difficulty: int = -1) -> void:
bot_difficulty = difficulty
if rules == null:
rules = MatchRules.immediate()
rules.max_players = maxi(human_players + bot_count, 1)
@@ -35,6 +39,7 @@ func _init(match_seed: int, human_players: int, bot_count: int, rules: MatchRule
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)
world = BotWorld.build(match_flow.sim, nav)
for handle: int in range(1, human_players + 1):
match_flow.join(handle)
if rules.lobby_ticks == 0 and rules.countdown_ticks == 0:
@@ -47,8 +52,9 @@ func run_tick() -> void:
var started: int = Time.get_ticks_usec()
if match_flow.in_match():
nav.sync(sim)
for bot: NavBot in bots:
sim.submit_command(bot.player_id, bot.think(sim, nav))
world.observe(sim)
for bot: BotBrain in bots:
sim.submit_command(bot.player_id, bot.think(sim, nav, world))
_advance()
ticks += 1
tick_usec.append(Time.get_ticks_usec() - started)
@@ -64,6 +70,7 @@ func _advance() -> void:
bots.clear()
if event["from"] == "results":
nav = NavGrid.build(match_flow.sim)
world = BotWorld.build(match_flow.sim, nav)
func _track_players() -> void:
@@ -73,9 +80,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):
var bot: NavBot = NavBot.new(entity_id)
bot.roam = true
bots.append(bot)
var level: int = bot_difficulty if bot_difficulty >= 0 else bots.size() % Tuning.BOT_DIFFICULTIES.size()
bots.append(BotBrain.new(entity_id, level))
world.player_ids = player_ids.duplicate()
## Timing statistics over every tick run so far, in microseconds.