Eric chose option B on #72. The drop is now the GDD's launch: - A packet ship sails a seeded straight line past the island, offshore, as close in as it can while keeping 45 m of open water from any land (eight-way probes; up to 32 headings, then the four world sides). - Jump fires the lifeline mortar along the look heading. How high the player aims sets the charge (-10 to 45 degrees: 16 to 110 m/s over the ground; every shot climbs at 75 m/s). The climb can't be steered and the kite can't open until the arc tops out. Riders still aboard at the end are fired towards the middle of the island. - Drop.reach() mirrors the fall for both ways down (kite at the top, or a fall with the kite opening by itself); bots, the soak and autoplay clients and the tutorial pilot aim with Drop.aim_charge(). - Bots fire at their landing spot once abeam of it, when in easy reach at their own staggered moment, or just before the route ends, and open the kite early only when the spot is beyond the rest of a fall. - Art: VesselModels.ship() (two-masted packet, tanned square sails, a salt-white boot-top, a bowsprit and the mortar on its bed, mirrored to face the island), the figure's gull-kite (figure.py), and a lifeline cord from the muzzle to each player still climbing. - Renamed barge to ship and wing-sail to gull-kite throughout code, tests, captures, docs and the tutorial text. make match now defaults to seed 2, where the scripted player still harvests and builds. Closes #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
192 lines
9.0 KiB
GDScript
192 lines
9.0 KiB
GDScript
## 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}, "weapon_kills": {item id: count},
|
|
## "death_seconds": [seconds into the match of each fall], "shots", "slow_ticks",
|
|
## "timing", "state_hash", "building": {"build": group, "control": group}}. Seconds
|
|
## count from the ship leaving. Each group (M6) adds up its bots' BotBrain.stats and
|
|
## holds their "bots", "places" and "wins".
|
|
##
|
|
## With `team_size` 2 the match is duos (M7), and the result also has "downs",
|
|
## "revives", "team_hits" (hits that did damage between teammates, which must be 0) and
|
|
## "winner_teams" (how many teams the winners came from, which must be 1).
|
|
##
|
|
## 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, team_size: int = 1) -> Dictionary:
|
|
var rules: MatchRules = null
|
|
if team_size > 1:
|
|
rules = ServerLoop.immediate_rules(0, bots)
|
|
rules.team_size = team_size
|
|
var loop: ServerLoop = ServerLoop.new(seed_value, 0, bots, rules, 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": [], "weapon_kills": {}, "death_seconds": [],
|
|
"downs": 0, "revives": 0, "team_hits": 0, "winner_teams": 0,
|
|
}
|
|
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:
|
|
result["slow_ticks"].append(loop.sim.tick)
|
|
for event: Dictionary in loop.sim.events:
|
|
match String(event["type"]):
|
|
"shot":
|
|
result["shots"] += 1
|
|
"downed":
|
|
result["downs"] += 1
|
|
"revived":
|
|
result["revives"] += 1
|
|
"player_hit":
|
|
if int(event["armor"]) + int(event["health"]) > 0 and loop.sim.are_teammates(loop.sim.entities.find(int(event["victim"])), loop.sim.entities.find(int(event["player"]))):
|
|
result["team_hits"] += 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
|
|
var winner_teams: Dictionary = {}
|
|
for handle: int in flow.winners:
|
|
winner_teams[flow.team_of[handle]] = true
|
|
result["winner_teams"] = winner_teams.size()
|
|
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
|
|
for record: Dictionary in flow.placements:
|
|
if record["left"]:
|
|
continue
|
|
result["death_seconds"].append(snappedf(float(record["tick"]) / Tuning.TICK_RATE_HZ, 0.1))
|
|
if record["cause"] == "weapon" and int(record["by"]) != 0:
|
|
var def: ItemDef = ItemCatalog.get_def(int(record["item"]))
|
|
# 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
|
|
|
|
|
|
## 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
|
|
|
|
|
|
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
|