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:
@@ -0,0 +1,96 @@
|
||||
## Runs whole bot-only matches and gathers what happened: who won, how everyone fell,
|
||||
## how each difficulty placed and how long the ticks took. Shared by the tests and
|
||||
## `make bot-matches`.
|
||||
class_name BotBatch
|
||||
extends RefCounted
|
||||
|
||||
## Longest a match can run: the tide's whole schedule, sudden death and a little slack.
|
||||
static func tick_limit() -> int:
|
||||
return Tide.new(0).time_limit_offset() + 30 * Tuning.TICK_RATE_HZ
|
||||
|
||||
|
||||
## Plays one match of `bots` bots on `seed_value`. `difficulty` -1 mixes the levels.
|
||||
## Returns {"seed", "finished", "ticks", "winner", "winner_difficulty", "timed_out",
|
||||
## "causes": {cause: count}, "places": {difficulty name: [place, ...]},
|
||||
## "eliminations": {difficulty name: count}, "shots", "slow_ticks", "timing",
|
||||
## "state_hash"}.
|
||||
static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficulty: int = -1) -> Dictionary:
|
||||
var loop: ServerLoop = ServerLoop.new(seed_value, 0, bots, null, difficulty)
|
||||
var flow: Match = loop.match_flow
|
||||
var level_of: Dictionary = {}
|
||||
for bot: BotBrain in loop.bots:
|
||||
level_of[flow.handle_of[bot.player_id]] = bot.difficulty_name()
|
||||
var result: Dictionary = {
|
||||
"seed": seed_value, "finished": false, "winner": 0, "winner_difficulty": "",
|
||||
"timed_out": false, "causes": {}, "places": {}, "eliminations": {}, "shots": 0,
|
||||
"slow_ticks": [],
|
||||
}
|
||||
var limit: int = tick_limit()
|
||||
while loop.ticks < limit and flow.phase != Match.RESULTS:
|
||||
var before: int = Time.get_ticks_usec()
|
||||
loop.run_tick()
|
||||
if Time.get_ticks_usec() - before > ServerLoop.TICK_BUDGET_USEC:
|
||||
result["slow_ticks"].append(loop.sim.tick)
|
||||
for event: Dictionary in loop.sim.events:
|
||||
if event["type"] == "shot":
|
||||
result["shots"] += 1
|
||||
for event: Dictionary in flow.events:
|
||||
if event["type"] == "match_ended":
|
||||
result["timed_out"] = event["timed_out"]
|
||||
result["ticks"] = loop.sim.tick
|
||||
result["finished"] = flow.phase == Match.RESULTS
|
||||
if flow.winners.size() > 0:
|
||||
result["winner"] = flow.winners[0]
|
||||
result["winner_difficulty"] = level_of.get(flow.winners[0], "")
|
||||
for row: Dictionary in flow.summary():
|
||||
var level: String = level_of.get(row["handle"], "")
|
||||
if not result["places"].has(level):
|
||||
result["places"][level] = []
|
||||
result["eliminations"][level] = 0
|
||||
result["places"][level].append(row["place"])
|
||||
result["eliminations"][level] += row["eliminations"]
|
||||
if row["place"] != 1:
|
||||
var cause: String = row["cause"]
|
||||
result["causes"][cause] = int(result["causes"].get(cause, 0)) + 1
|
||||
result["timing"] = loop.timing_stats()
|
||||
result["state_hash"] = loop.sim.state_hash()
|
||||
return result
|
||||
|
||||
|
||||
## Adds up a list of run_match() results: {"matches", "finished", "with_winner",
|
||||
## "timed_out", "deaths", "causes", "drown_share", "mean_place": {difficulty: mean},
|
||||
## "wins": {difficulty: count}, "eliminations": {difficulty: count}, "mean_ticks",
|
||||
## "worst_p99_us", "over_budget"}.
|
||||
static func summarise(results: Array[Dictionary]) -> Dictionary:
|
||||
var total: Dictionary = {
|
||||
"matches": results.size(), "finished": 0, "with_winner": 0, "timed_out": 0, "deaths": 0,
|
||||
"causes": {}, "mean_place": {}, "wins": {}, "eliminations": {}, "worst_p99_us": 0, "over_budget": 0,
|
||||
}
|
||||
var places: Dictionary = {}
|
||||
var ticks: int = 0
|
||||
for result: Dictionary in results:
|
||||
total["finished"] += 1 if result["finished"] else 0
|
||||
total["with_winner"] += 1 if result["winner"] != 0 else 0
|
||||
total["timed_out"] += 1 if result["timed_out"] else 0
|
||||
ticks += result["ticks"]
|
||||
for cause: String in result["causes"]:
|
||||
total["causes"][cause] = int(total["causes"].get(cause, 0)) + int(result["causes"][cause])
|
||||
total["deaths"] += int(result["causes"][cause])
|
||||
for level: String in result["places"]:
|
||||
if not places.has(level):
|
||||
places[level] = []
|
||||
places[level].append_array(result["places"][level])
|
||||
total["eliminations"][level] = int(total["eliminations"].get(level, 0)) + int(result["eliminations"][level])
|
||||
var winner: String = result["winner_difficulty"]
|
||||
if winner != "":
|
||||
total["wins"][winner] = int(total["wins"].get(winner, 0)) + 1
|
||||
total["worst_p99_us"] = maxi(total["worst_p99_us"], int(result["timing"]["p99_us"]))
|
||||
total["over_budget"] += int(result["timing"]["over_budget"])
|
||||
for level: String in places:
|
||||
var sum: int = 0
|
||||
for place: int in places[level]:
|
||||
sum += place
|
||||
total["mean_place"][level] = float(sum) / places[level].size()
|
||||
total["drown_share"] = float(total["causes"].get("drown", 0)) / maxi(total["deaths"], 1)
|
||||
total["mean_ticks"] = ticks / maxi(results.size(), 1)
|
||||
return total
|
||||
Reference in New Issue
Block a user