## Plays bot-only matches on a run of seeds and checks issue M5's acceptance: every ## match ends with a winner, under a tenth of deaths are drownings, and difficulty ## shows: easy bots place worst and hard bots take the most eliminations. ## ## tools/godot.sh --script res://tools/bot_matches.gd -- [--seeds=20] [--first=1] ## ## Prints one JSON line per match and a summary. Exits 1 if a check fails. extends SceneTree func _init() -> void: var count: int = 20 var first: int = 1 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() var results: Array[Dictionary] = [] for seed_value: int in range(first, first + count): var result: Dictionary = BotBatch.run_match(seed_value) results.append(result) print(JSON.stringify(result)) var total: Dictionary = BotBatch.summarise(results) print(JSON.stringify({"summary": total})) var problems: Array[String] = [] if total["with_winner"] != count or total["finished"] != count: problems.append("%d of %d matches finished with a winner" % [total["with_winner"], count]) if total["drown_share"] >= 0.1: problems.append("%.1f%% of deaths were drownings" % (total["drown_share"] * 100.0)) # Placement is noisy between neighbouring levels over 20 matches, so the check is on # what holds up: easy bots place worst, and hard bots take the most eliminations. var mean: Dictionary = total["mean_place"] var kills: Dictionary = total["eliminations"] if not (mean.get("easy", 0.0) > mean.get("normal", 99.0) and mean.get("easy", 0.0) > mean.get("hard", 99.0)): problems.append("easy bots didn't place worst: %s" % mean) if not (kills.get("hard", 0) > kills.get("normal", 0) and kills.get("hard", 0) > kills.get("easy", 0)): problems.append("hard bots didn't take the most eliminations: %s" % kills) for problem: String in problems: print("bot-matches FAIL: %s" % problem) if problems.is_empty(): print("bot-matches: ok (%d matches, all with a winner, %.1f%% drowned, mean place %s, eliminations %s)" % [count, total["drown_share"] * 100.0, mean, kills]) quit(0 if problems.is_empty() else 1)