From 38812120dfbbc53b1272d4f2e373ffa83abbb5f1 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 06:28:15 -0500 Subject: [PATCH] H3: Balance pass from 200 bot matches (make balance) make balance (tools/balance.sh, tools/balance.gd, BalanceReport) plays 200 bot-only matches in four processes under nice and reports match length, players standing over time, causes of death, eliminations by weapon and by difficulty, judged against the new BALANCE_* targets in Tuning and the GDD's Balance section. Before: median match 5.0 min, 3.4 of 24 standing at 2 min, the boathook 41% of eliminations. After, over seeds 1001-1200: median 13.1 min (p10 9.2, p90 14.6), top weapon the rivet repeater at 31.7%. Passes. Changes, each traced from single-match runs (docs/BALANCE.md): - Fix: bots leapt from the barge on a timer and landed hundreds of metres short of their spot; they now leap when it's in gliding reach or the barge starts drawing away from it. - Bots spread their landings, only brawl whoever hit them, pick out new opponents within 30 m, roam locally and hold ground, run from a gun when unarmed, and (normal and hard) break off when badly hurt. - Aim error widened; rivet repeater damage 17 to 15. - Tide: lower early levels, longer holds; every match ends within 17.75 min. Tests: BalanceReport, the new bot behaviours, the tide length. Tests that leaned on old bot luck now pin or set up what they check. make match moves to seed 29, where the scripted player still builds. Closes #56 Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 4 +- Makefile | 6 +- docs/BALANCE.md | 129 ++++++++++++++++++++++++++ docs/GDD.md | 14 +++ src/bots/bot_brain.gd | 94 +++++++++++++++++-- src/bots/bot_world.gd | 18 ++++ src/bots/nav_bot.gd | 12 ++- src/bots/scripted_player.gd | 28 ++++-- src/sim/tuning.gd | 51 +++++++--- test/bots/balance_report.gd | 121 ++++++++++++++++++++++++ test/bots/balance_report.gd.uid | 1 + test/bots/bot_batch.gd | 16 +++- test/bots/test_balance_report.gd | 54 +++++++++++ test/bots/test_balance_report.gd.uid | 1 + test/bots/test_bot_brain.gd | 93 +++++++++++++++++++ test/bots/test_scripted_player.gd | 7 +- test/client/test_client_session.gd | 15 ++- test/server/test_server_loop.gd | 12 ++- test/server/test_world_replication.gd | 17 ++-- test/sim/test_tide.gd | 17 +++- tools/balance.gd | 75 +++++++++++++++ tools/balance.gd.uid | 1 + tools/balance.sh | 45 +++++++++ tools/match.sh | 4 +- 24 files changed, 774 insertions(+), 61 deletions(-) create mode 100644 docs/BALANCE.md create mode 100644 test/bots/balance_report.gd create mode 100644 test/bots/balance_report.gd.uid create mode 100644 test/bots/test_balance_report.gd create mode 100644 test/bots/test_balance_report.gd.uid create mode 100644 tools/balance.gd create mode 100644 tools/balance.gd.uid create mode 100755 tools/balance.sh diff --git a/CLAUDE.md b/CLAUDE.md index d536102..361bf11 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -14,6 +14,7 @@ continuity. - [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md): server-authoritative design and module map. - [src/sim/tuning.gd](src/sim/tuning.gd): the one table of gameplay numbers. - [docs/PLAY.md](docs/PLAY.md): graphics presets, renderers and the tested configurations. +- [docs/BALANCE.md](docs/BALANCE.md): how the pacing and weapons were tuned from bot matches. ## Commands @@ -29,7 +30,8 @@ continuity. | `tools/capture.sh ` | Renders the real client offscreen in a throwaway `tidewall-capture-*` Docker container (Xvfb, Mesa software rendering) and saves a PNG. Fails on a blank frame or a renderer fallback. | | `tools/godot.sh --script res://tools/island_map.gd -- --seed=N --out=res://captures/island.png` | Draws a top-down map of a seed's island, with a contour at each tide level. | | `make bot-matches` | Plays 20 bot-only matches (about ten minutes, under `nice`) and checks every one has a winner, under a tenth of deaths are drownings, and easy bots win less than an even share and take the fewest eliminations. `BOT_MATCH_SEEDS=5 BOT_MATCH_FIRST=40` changes the seeds; under 20 matches the difficulty checks are skipped. | -| `make match` | Plays one whole offline match, lobby to results: a scripted player and 23 bots on a local server (about 25 s). Saves the command log to `build/match/match.tclog`, replays it and checks the replay ends on the same state hash. `MATCH_SEED=N` changes the seed; the default, 2, is one where the scripted player also builds. | +| `make balance` | H3: plays 200 bot-only matches in four processes under `nice` (about 15 min) and writes `build/balance/report.txt`: match length, players standing over time, causes of death, eliminations by weapon and by difficulty. Fails if the median match is outside 12 to 18 minutes or a weapon takes over 35% of eliminations (`BALANCE_*` in tuning). `BALANCE_MATCHES`, `BALANCE_FIRST`, `BALANCE_JOBS` scale it. See docs/BALANCE.md. | +| `make match` | Plays one whole offline match, lobby to results: a scripted player and 23 bots on a local server (about 25 s). Saves the command log to `build/match/match.tclog`, replays it and checks the replay ends on the same state hash. `MATCH_SEED=N` changes the seed; the default, 29, is one where the scripted player also builds. | | `make match-captures` | Renders eight stages of that match from its command log (`captures/match_.png`), about 3 minutes. Needs Docker. Look at them. | | `make terrain-capture` | Renders the terrain crack check and a skirtless control in the capture container. The control must crack and the real terrain must not. Needs Docker. | | `tools/godot.sh -- --connect=HOST:PORT --autoplay --client-seconds=N` | Runs the client headless against a server for N seconds, played by its script, and prints one JSON line saying how far it got. `--offline` plays a server in the same process instead. On a real display, with no options, the game opens on its main menu (`AppShell`); see `src/app/client_config.gd`. | diff --git a/Makefile b/Makefile index dd1ba8a..10c5015 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Tidewall build entry points. Everything runs headless with the repo-local engine. GODOT := tools/godot.sh -.PHONY: app-icon deb deb-check bench dist dist-check build-captures poi-captures art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine bot-matches match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz soak soak-selfcheck server-package-check +.PHONY: app-icon deb deb-check bench dist dist-check build-captures poi-captures art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine balance bot-matches match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz soak soak-selfcheck server-package-check ## A8: regenerates every sound in assets/audio/ from tools/audio/ (about 6 s). audio: import @@ -99,6 +99,10 @@ smoke: import ## Plays 20 bot-only matches and checks each has a winner, few bots drown and easy ## bots do worst. Takes about ten minutes, so it isn't part of `check`. ## BOT_MATCH_SEEDS and BOT_MATCH_FIRST change how many seeds and where they start. +## H3: the balance pass over 200 bot-only matches; report in build/balance/report.txt. +balance: import + @tools/balance.sh + bot-matches: import @tools/bot_matches.sh diff --git a/docs/BALANCE.md b/docs/BALANCE.md new file mode 100644 index 0000000..d9ced6b --- /dev/null +++ b/docs/BALANCE.md @@ -0,0 +1,129 @@ +# Balance + +How Tidewall's pacing and weapons were tuned, from batches of bot-only matches. The +targets are in [GDD.md](GDD.md#balance) and in `src/sim/tuning.gd` (`BALANCE_*`). + +## How to measure + +`make balance` (`tools/balance.sh`) plays 200 bot-only matches of 24 players from seed +1001, in four processes under `nice`, and writes `build/balance/report.txt`: + +- match length from the barge leaving to the last player standing, as quantiles; +- how many players are still standing at each two minutes; +- causes of every fall, and the share the sea took; +- eliminations by weapon, the boathook included; +- wins, eliminations and mean place by bot difficulty. + +It fails if there are fewer than 200 matches, any match lacks a winner, the median +length is outside 12 to 18 minutes, or one weapon has more than 35% of weapon +eliminations. `BALANCE_MATCHES`, `BALANCE_FIRST`, `BALANCE_JOBS` and `BALANCE_DIR` +change the batch. A 30-match look takes about two minutes on four cores. + +Bot-only matches are what the server can play on its own. They are not people: they +show where the numbers are badly off, not how a match feels. Eric's playtest (R6) is +the check on that. + +## What the first batches showed (2026-11-14) + +The starting point, 30 matches on seeds 1001 to 1030: + +| | Before | +|---|---| +| Median match | 5.0 min (p10 3.3, p90 7.3) | +| Players standing at 2 min | 3.4 of 24 | +| Ended by the tide's clock | 0 of 30 | +| Top weapon | the boathook, 41% | + +Most of a lobby fell within two minutes of the drop. Tracing single matches showed why, +in order of how much each mattered: + +1. **Bots leapt from the barge on a timer, not when their landing spot was in reach.** + A bot that picked a spot further along the route leapt early and came down hundreds + of metres short, then walked across the island unarmed. This was a bug in + `NavBot._ride`. +2. **Unarmed bots started boathook brawls** with anyone within 6 m, so the landing was a + melee. The boathook took 41% of all eliminations. +3. **Bots went looking for fights.** A bot picked out any opponent within its sight + (45 to 90 m) and chased them, and with nothing to loot it walked to a random safe + point anywhere on the island, every 40 seconds, so the last few always met. +4. **Bots never broke off.** Fights ran until someone fell. An unarmed bot kept looting + while someone shot at it. +5. **The tide's endgame came at about 9 minutes.** Phase 3's rise to 30 m left the last + few players on ground small enough that they always met then. + +## Changes + +| Change | Where | Why | +|---|---|---| +| Bots leap once their landing spot is in gliding reach, or once the barge starts drawing away from it | `NavBot._ride` | Finding 1, a bug | +| Bots weigh `BOT_LANDING_CHOICES` (8) landing spots and take the one with the fewest other bots' landings within `BOT_LANDING_SPREAD_METRES` (60 m) | `BotBrain._drop`, `BotWorld.landings` | Spread the landing | +| An unarmed bot only swings its boathook at whoever hit it | `BotBrain.think` | Finding 2 | +| Bots pick out a new opponent only within `BOT_ENGAGE_METRES` (30 m); one who shoots them is fought as far as they can see | `BotBrain._sense` | Finding 3 | +| With nothing to loot, bots roam to safe ground within `BOT_ROAM_METRES` (60 m) and hold it for `BOT_HOLD_SECONDS` (45 s) | `BotBrain._hunt`, `BotWorld.random_safe_near` | Finding 3; the single biggest change to match length | +| An unarmed bot runs from a gun held in view; a hurt bot with something to heal with breaks off at its difficulty's `retreat` health (normal 35, hard 50, easy never) | `BotBrain._check_retreat` | Finding 4, and the judgement issue #76 asked of hard bots | +| Aim error: easy 7 to 9 degrees, normal 3.5 to 5.5, hard 1.5 to 3 | `BOT_DIFFICULTIES` | Bots hit nearly every shot at close range | +| Tide: lower early levels (6, 14, 24, 34, 46, 58, 75 m, was 8, 18, 30, 42, 54, 64, 75) and longer holds (150, 130, 120, 110, 90, 60, 45 s); rises unchanged. With sudden death every match ends within 17.75 minutes | `TIDE_PHASES` | Finding 5: move the squeeze later, and keep the longest match inside 18 minutes | +| Rivet repeater damage 17 to 15 | `WEAPONS` | It was the top weapon at 33%, close to the limit, as the commonest gun with the highest damage per second | + +Tried and dropped: doubling the weapons guaranteed at points of interest +(`LOOT_MIN_POI_WEAPONS` to 48). It made no clear difference to how many bots were armed +early; the leap bug was the real cause. It stays at one per player. + +Each step, on the same 30 seeds (median minutes, players standing at 2 min): + +| Step | Median | At 2 min | +|---|---|---| +| Start | 5.0 | 3.4 | +| Unarmed bots don't start brawls | 5.4 | 4.0 | +| Engage range, local roaming, aim error | 8.7 | 5.6 | +| Landing spread | 8.7 | 5.8 | +| Longer holds | 9.7 | 5.8 | +| Retreat | 9.4 | 5.7 | +| Leap fix, running from guns | 9.0 | 5.0 | +| Lower levels, longer schedule | 9.5 | 5.1 | +| Holding ground | 14.0 | 5.5 | + +## The 200-match result + +`make balance` on seeds 1001 to 1200, with every change above (2026-11-14). It passes. + +| | Before (30 matches) | After (200 matches) | +|---|---|---| +| Median match | 5.0 min | **13.1 min** (target 12 to 18) | +| p10 to p90 | 3.3 to 7.3 min | 9.2 to 14.6 min | +| Shortest, longest | 1.2, 8.8 min | 2.2, 16.4 min | +| Players standing at 2, 6, 10, 14 min | 3.4, 0.7, 0.0, 0.0 | 6.4, 3.6, 2.4, 0.7 | +| Ended by the tide's clock | 0 | 0 | +| Falls to the sea | 0.4% | 2.1% | +| Top weapon | boathook 41% | rivet repeater 31.7% (limit 35%) | + +Eliminations by weapon over the 200 matches: rivet repeater 31.7%, dock carbine 27.4%, +signal revolver 22.4%, fowling piece 11.5%, harpoon gun 4.5%, whaler's longgun 2.3%, +boathook 0.3%. The three commonest guns take most eliminations, as they should; the +rarer heavy weapons are under-used by bots, which don't yet lead long shots well or +fight at the ranges the longgun suits. + +By difficulty: hard won 148 matches, normal 42 and easy 10, with 2,053, 1,434 and 1,013 +eliminations and mean places of 11.93, 12.41 and 13.12. Hard bots are now clearly the +strongest, which issue #76 found they weren't: breaking off at 50 health and the wider +gap in aim both count. + +Every match ended with one player standing before the tide's clock ran out. Matches end +when the rising water brings the last few together: half of them end between 11 and 14 +minutes, from phase 4's rise to phase 6's hold. + +## Known and left open + +- **The landing is still bloody.** About three quarters of a bot lobby falls in the first + two minutes, mostly unarmed bots shot by the first to find a gun. People are likely + to spread out and hide more than bots do; R6 will show it. More could be done in + bot looting (they give up on a hut whose chest someone else just emptied and set off + across the island unarmed). Noted on #74 (H10, bot follow-ups). +- **The sea takes few players.** Bots read the forecast well and leave in time, so + drowning is rare. The tide still decides where the endgame is. +- **Hard bots win three quarters of matches.** Against people that is what a "hard" + setting should be, but if R6 finds them unfair, `retreat` and `aim_error` in + `BOT_DIFFICULTIES` are the levers. +- **The whaler's longgun and harpoon gun are rarely the weapon that finishes someone.** + They are rare (rarity 2 and 1) and bots use them poorly; no change was made from bot + data alone. diff --git a/docs/GDD.md b/docs/GDD.md index d66e0e2..3624ae0 100644 --- a/docs/GDD.md +++ b/docs/GDD.md @@ -296,6 +296,20 @@ A player has `PLAYER_MAX_HEALTH` health, up to `PLAYER_MAX_ARMOR` armor, which t damage first, and `INVENTORY_SLOTS` slots. The top `HEAD_HEIGHT` of the body takes each weapon's headshot multiplier. +## Balance + +The balance targets are checked by `make balance` over at least `BALANCE_MIN_MATCHES` +bot-only matches of `SOLO_PLAYERS` players (H3): + +- the median match, from the barge leaving to the last player standing, lasts between + `BALANCE_MEDIAN_MINUTES_MIN` and `BALANCE_MEDIAN_MINUTES_MAX` minutes; +- no one weapon takes more than `BALANCE_MAX_WEAPON_SHARE` of the eliminations made with + weapons, the boathook included. + +Every match ends within the tide's total time plus sudden death, which the tide table +keeps under `BALANCE_MEDIAN_MINUTES_MAX`. Findings and the changes they led to are in +[BALANCE.md](BALANCE.md). + ## Controls Rebindable. Defaults for keyboard and mouse: diff --git a/src/bots/bot_brain.gd b/src/bots/bot_brain.gd index 830ca2f..4dc56fd 100644 --- a/src/bots/bot_brain.gd +++ b/src/bots/bot_brain.gd @@ -65,7 +65,16 @@ var _skipped_pickups: Dictionary = {} var _skipped_chests: Dictionary = {} var _loot_checked: int = -100000 var _interact_last: bool = false +## Health and armor at or under which this bot breaks off a fight, and until when it's +## running from one (H3). +var _retreat_health: int = 0 +var _retreat_until: int = -100000 +var _retreat_goal: Vector3 = Vector3.ZERO +## Who last hit this bot, and when: an unarmed bot only swings back at them. +var _hit_by: int = 0 +var _hit_tick: int = -100000 var _hunt_goal: Vector3 = Vector3.ZERO +var _holding: bool = false var _hunt_until: int = 0 var _goal_set: bool = false ## Walking a point of interest's route: the stage, the route, the next point on it and @@ -93,6 +102,7 @@ func _init(id: int, level: int = NORMAL) -> void: _aim_error_degrees = float(stats["aim_error"]) _sight = float(stats["sight"]) _lead = float(stats["lead"]) + _retreat_health = int(stats["retreat"]) func difficulty_name() -> String: @@ -116,16 +126,20 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand: var armed: bool = _weapon_slot >= 0 var selection: int = _weapon_slot + 1 if armed else Simulation.BOATHOOK_SLOT var buttons: int = 0 - var fighting: bool = target != null and target_visible and armed and not me.swimming - # Inside a hut or loft too: someone beating on you there gets a swing back. + _check_retreat(sim, world, me, target, armed) + var retreating: bool = sim.tick < _retreat_until + var fighting: bool = target != null and target_visible and armed and not me.swimming and not retreating + # Inside a hut or loft too: someone beating on you there gets a swing back. An + # unarmed bot doesn't start a brawl; it keeps looking for a weapon (H3). + var provoked: bool = target != null and target.id == _hit_by and sim.tick - _hit_tick <= roundi(Tuning.BOT_MEMORY_SECONDS * TICKS) var brawling: bool = (target != null and target_visible and not armed and not me.swimming - and not _fleeing and distance <= Tuning.BOT_BRAWL_METRES) + and not _fleeing and not retreating and distance <= Tuning.BOT_BRAWL_METRES and provoked) var interact: bool = false var walk: bool = true # Where to go. _direct_on = false - var urgent: bool = _fleeing or (target != null and armed) + var urgent: bool = _fleeing or retreating or (target != null and armed) if _stage != OUTSIDE: # Inside a hut or up a loft: loot, or walk back out first if something's up. if urgent and _stage != LEAVING: @@ -135,6 +149,9 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand: elif _fleeing: state = "flee" _go(_flee_goal, 3.0) + elif retreating: + state = "retreat" + _go(_retreat_goal, 3.0) elif fighting: state = "fight" _stop() @@ -185,7 +202,7 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand: buttons &= ~PlayerCommand.BUTTON_SPRINT # Fighting: face the target and fire, whatever the feet are doing. - if target != null and target_visible and armed and not me.swimming: + if fighting or (target != null and target_visible and armed and not me.swimming and _fleeing): var def: ItemDef = ItemCatalog.get_def(me.slot_items[_weapon_slot]) var aim: Vector2 = _aim_at(me, target, def) yaw = aim.x @@ -258,7 +275,21 @@ func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand: var closest: Vector2 = Geometry2D.get_closest_point_to_segment(at, a, b) if at.distance_to(closest) <= 120.0 and world.markers[index].y > sim.sea_level + 1.0: near.append(index) - _landing = near[rng.randi_range(0, near.size() - 1)] if not near.is_empty() else rng.randi_range(0, world.markers.size() - 1) + if near.is_empty(): + _landing = rng.randi_range(0, world.markers.size() - 1) + else: + # Of a few spots, land at the one fewest others have picked nearby (H3). + var best_crowd: int = 1 << 30 + for _try: int in Tuning.BOT_LANDING_CHOICES: + var pick: int = near[rng.randi_range(0, near.size() - 1)] + var crowd: int = 0 + for other: Vector3 in world.landings: + if other.distance_to(world.markers[pick]) <= Tuning.BOT_LANDING_SPREAD_METRES: + crowd += 1 + if crowd < best_crowd: + best_crowd = crowd + _landing = pick + world.landings.append(world.markers[_landing]) _marker = _landing _marker_since = sim.tick _go(world.markers[_landing], 2.0) @@ -276,6 +307,9 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void: _forget_target() # Being hit tells a player roughly where it came from. var attacker_id: int = int(world.attackers.get(player_id, 0)) + if attacker_id != 0 and attacker_id != player_id: + _hit_by = attacker_id + _hit_tick = tick if attacker_id != 0 and attacker_id != player_id and not target_visible: var attacker: SimEntity = sim.entities.find(attacker_id) if attacker != null and not attacker.eliminated: @@ -308,8 +342,11 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void: var other: SimEntity = sim.entities.find(other_id) if other == null or other.eliminated or other.drop_state != Drop.NONE: continue + # A bot picks out a new opponent only this close; one who shoots it first is + # fought at any range it can see (H3). var gap: float = me.position.distance_squared_to(other.position) - if gap <= _sight * _sight: + var notice: float = minf(_sight, Tuning.BOT_ENGAGE_METRES) + if gap <= notice * notice: candidates.append(Vector2(gap, other_id)) candidates.sort() for index: int in mini(candidates.size(), 3): @@ -341,6 +378,35 @@ func _can_see(sim: Simulation, world: BotWorld, me: SimEntity, other: SimEntity, return world.clear_line(sim.ground, Harvest.eye(me), chest) +## Breaks off a fight: runs away from the opponent, over safe ground, for +## BOT_RETREAT_SECONDS, then heals if it can. Any bot without a gun runs from one held +## in view; a bot badly hurt with a way to heal breaks off too, except easy ones. +func _check_retreat(sim: Simulation, world: BotWorld, me: SimEntity, target: SimEntity, armed: bool) -> void: + if target == null or _fleeing or sim.tick < _retreat_until or me.swimming: + return + var outgunned: bool = not armed and target_visible and _holds_gun(target) + var hurt: bool = _retreat_health > 0 and me.health + me.armor <= _retreat_health and _heal_slot(me) >= 0 + if not outgunned and not hurt: + return + if sim.tick - _retreat_until < roundi(Tuning.BOT_RETREAT_SECONDS * TICKS): + return + var away: Vector3 = me.position - target.position + away.y = 0.0 + away = away.normalized() if away.length() > 0.1 else Vector3(1.0, 0.0, 0.0) + var phase: int = sim.tide.phase_at(sim.tick) if sim.tide != null else 0 + _retreat_goal = world.random_safe_near(nav.stream(sim), phase, me.position + away * Tuning.BOT_RETREAT_METRES, Tuning.BOT_RETREAT_METRES * 0.5) + _retreat_until = sim.tick + roundi(Tuning.BOT_RETREAT_SECONDS * TICKS) + _forget_target() + + +## True if `other` has a gun in hand. +static func _holds_gun(other: SimEntity) -> bool: + if other.selected == Simulation.BOATHOOK_SLOT or other.selected > other.slot_items.size(): + return false + var def: ItemDef = ItemCatalog.get_def(other.slot_items[other.selected - 1]) + return def != null and def.kind == ItemDef.WEAPON and def.damage > 0 + + func _forget_target() -> void: target_id = 0 target_visible = false @@ -773,13 +839,23 @@ func _next_marker(sim: Simulation, world: BotWorld, me: SimEntity) -> int: ## Nothing to loot: wander the ground the tide will leave, where the others will be. +## With nothing to loot: roams to safe ground nearby, and holds there for a while +## before moving on (H3). The tide check moves it sooner if the water is coming. func _hunt(sim: Simulation, world: BotWorld) -> void: state = "hunt" var arrived: bool = _goal_set and nav.status != NavBot.MOVING - if not _goal_set or arrived or sim.tick >= _hunt_until: + if arrived and not _holding: + _holding = true + _hunt_until = sim.tick + roundi(Tuning.BOT_HOLD_SECONDS * TICKS) + if (not _goal_set and not _holding) or sim.tick >= _hunt_until: var phase: int = sim.tide.phase_at(sim.tick) if sim.tide != null else 0 - _hunt_goal = world.random_safe(nav.stream(sim), phase) + var me: SimEntity = sim.entities.find(player_id) + _hunt_goal = world.random_safe_near(nav.stream(sim), phase, me.position, Tuning.BOT_ROAM_METRES) _hunt_until = sim.tick + 40 * TICKS + _holding = false _go(_hunt_goal, 4.0) + elif _holding: + state = "hold" + _stop() else: _go(_hunt_goal, 4.0) diff --git a/src/bots/bot_world.gd b/src/bots/bot_world.gd index 376e12b..93feb33 100644 --- a/src/bots/bot_world.gd +++ b/src/bots/bot_world.gd @@ -42,6 +42,8 @@ var phase_tops: Array[Vector3] = [] ## 1 for each grid cell a bot can walk to: open on the navigation grid and joined to the ## rest of the island. Safe ground a bot is sent to is always one of these. var walkable: PackedByteArray = PackedByteArray() +## Where bots have chosen to land this match, so later bots can spread out (H3). +var landings: Array[Vector3] = [] ## Victim entity ID -> attacker entity ID, for hits landed during the last tick. var attackers: Dictionary = {} @@ -183,6 +185,22 @@ func random_safe(rng: RandomNumberGenerator, phase: int) -> Vector3: return phase_tops[phase] +## A random point of phase `phase`'s safe ground within `radius` of `centre`, or one +## anywhere on it (random_safe) if a few tries find none that close. +func random_safe_near(rng: RandomNumberGenerator, phase: int, centre: Vector3, radius: float) -> Vector3: + phase = clampi(phase, 0, phase_count() - 1) + if phase_cells[phase] == 0: + return phase_tops[phase] + var marks: PackedByteArray = phase_marks[phase] + for _try: int in 24: + var angle: float = rng.randf() * TAU + var reach: float = sqrt(rng.randf()) * radius + var cell: int = _cell_of(centre + Vector3(cos(angle) * reach, 0.0, sin(angle) * reach)) + if marks[cell] != 0: + return _cell_position(cell) + return random_safe(rng, phase) + + ## True if nothing solid stands between two points: terrain, checked every couple of ## metres, and solids. Players don't block it. func clear_line(ground: SimGround, from: Vector3, to: Vector3) -> bool: diff --git a/src/bots/nav_bot.gd b/src/bots/nav_bot.gd index 46ff12b..a9c7d00 100644 --- a/src/bots/nav_bot.gd +++ b/src/bots/nav_bot.gd @@ -36,6 +36,8 @@ var _stuck_ticks: int = 0 var _stuck_tries: int = 0 var _jump_next: bool = false var _leap_tick: int = -1 +## How far the goal was from the barge last tick, while riding. +var _ride_gap: float = INF var _rng: RandomNumberGenerator = null var _rng_seed: int = 0 @@ -173,15 +175,19 @@ func _steer(sim: Simulation, player: SimEntity, target: Vector3, buttons: int) - return PlayerCommand.from_input(sim.tick, Vector2(0.0, 1.0), atan2(to.x, to.y), 0.0, buttons) -## Aboard the barge: leap once the goal is within gliding reach, or at a time set by -## the player ID, whichever comes first. The end of the route puts everyone off anyway. +## Aboard the barge: leap once the goal is within gliding reach, or once the barge +## starts drawing away from it; with no goal, at a time set by the player ID. The end of the route puts everyone off anyway. func _ride(sim: Simulation, player: SimEntity) -> PlayerCommand: if _leap_tick < 0 and sim.drop != null: _leap_tick = sim.drop.began_tick + Tuning.TICK_RATE_HZ * 2 + (player_id * 53) % (Tuning.TICK_RATE_HZ * 20) var leap: bool = sim.tick >= _leap_tick if status == MOVING: + # With somewhere to land, wait until it's in gliding reach, or until the barge + # has passed it and is drawing away (H3: bots used to leap on the timer and land + # hundreds of metres short). var gap: float = Vector2(goal.x - player.position.x, goal.z - player.position.z).length() - leap = leap or gap < 0.6 * (player.position.y - goal.y) + leap = gap < 0.6 * (player.position.y - goal.y) or gap > _ride_gap + 0.01 + _ride_gap = gap var buttons: int = PlayerCommand.BUTTON_JUMP if leap else 0 return PlayerCommand.from_input(sim.tick, Vector2.ZERO, 0.0, 0.0, buttons) diff --git a/src/bots/scripted_player.gd b/src/bots/scripted_player.gd index 27e8975..cec45c2 100644 --- a/src/bots/scripted_player.gd +++ b/src/bots/scripted_player.gd @@ -20,9 +20,11 @@ const STEP_NAMES: Array[String] = ["wait", "harvest", "build", "done"] const WANTED_DRIFTWOOD: int = 45 ## How far to look for something to cut, in metres. const SEARCH_RADIUS: float = 45.0 +const FAR_SEARCH_RADIUS: float = 250.0 ## Starts the script this long after landing even with no weapon found. const UNARMED_WAIT_SECONDS: float = 45.0 -## Gives up on one prop, and on the whole script, after this long. +## Gives up on one prop after this long (plus the walk to it), and on the whole script +## after SCRIPT_TIMEOUT_SECONDS. const PROP_TIMEOUT_SECONDS: float = 25.0 const SCRIPT_TIMEOUT_SECONDS: float = 150.0 ## Inside this distance the script walks straight at the prop instead of path-finding. @@ -38,6 +40,7 @@ var _script_since: int = 0 var _driving: bool = false var _prop: int = -1 var _prop_since: int = 0 +var _prop_deadline: int = 0 var _skipped_props: Dictionary = {} var _to_build: Array[int] = [StructureSet.BREAKWATER, StructureSet.WALL] var _build_yaw: float = 0.0 @@ -108,11 +111,14 @@ func _harvest(sim: Simulation, grid: NavGrid, me: SimEntity) -> PlayerCommand: _build_yaw = float(me.yaw) / PlayerCommand.YAW_STEPS * TAU return _hold(sim, me) var standing: bool = _prop >= 0 and sim.props.is_standing(_prop) - if not standing or sim.tick - _prop_since > roundi(PROP_TIMEOUT_SECONDS * TICKS): + if not standing or sim.tick > _prop_deadline: if standing: _skipped_props[_prop] = true _prop = _find_prop(sim, me) _prop_since = sim.tick + # A far prop gets time to walk there too, at about 4 m/s. + var far: float = PropSet._distance_to_box(sim.props.boxes[_prop], me.position) if _prop >= 0 else 0.0 + _prop_deadline = sim.tick + roundi((PROP_TIMEOUT_SECONDS + far / 4.0) * TICKS) if _prop < 0: step = DONE return _hold(sim, me) @@ -138,14 +144,18 @@ func _harvest(sim: Simulation, grid: NavGrid, me: SimEntity) -> PlayerCommand: return walk -## The nearest standing driftwood prop on dry ground that hasn't been given up on. +## The nearest standing driftwood prop on dry ground that hasn't been given up on: +## close by and about level if there is one, or else anywhere within FAR_SEARCH_RADIUS +## (since H3 bots land where they meant to, often inland, away from the beaches). func _find_prop(sim: Simulation, me: SimEntity) -> int: - for prop: int in sim.props.near(me.position, SEARCH_RADIUS): - if _skipped_props.has(prop) or sim.props.material_of(prop) != Materials.NAMES[Materials.DRIFTWOOD]: - continue - var box: AABB = sim.props.boxes[prop] - if box.position.y > sim.sea_level + 0.5 and absf(box.position.y - me.position.y) < 8.0: - return prop + for radius: float in [SEARCH_RADIUS, FAR_SEARCH_RADIUS]: + for prop: int in sim.props.near(me.position, radius): + if _skipped_props.has(prop) or sim.props.material_of(prop) != Materials.NAMES[Materials.DRIFTWOOD]: + continue + var box: AABB = sim.props.boxes[prop] + var level: bool = absf(box.position.y - me.position.y) < 8.0 or radius > SEARCH_RADIUS + if box.position.y > sim.sea_level + 0.5 and level: + return prop return -1 diff --git a/src/sim/tuning.gd b/src/sim/tuning.gd index 4e98c53..c1e28e9 100644 --- a/src/sim/tuning.gd +++ b/src/sim/tuning.gd @@ -217,13 +217,13 @@ const PROP_POI_CLEARANCE: float = 3.0 # must exceed ISLAND_MAX_HEIGHT, so that every match ends. const ISLAND_MAX_HEIGHT: float = 70.0 const TIDE_PHASES: Array[Dictionary] = [ - {"hold": 150.0, "rise": 60.0, "level": 8.0, "drown_dps": 2, "surge": 0}, - {"hold": 100.0, "rise": 50.0, "level": 18.0, "drown_dps": 4, "surge": 40}, - {"hold": 80.0, "rise": 45.0, "level": 30.0, "drown_dps": 6, "surge": 60}, - {"hold": 60.0, "rise": 40.0, "level": 42.0, "drown_dps": 8, "surge": 80}, - {"hold": 45.0, "rise": 35.0, "level": 54.0, "drown_dps": 12, "surge": 100}, - {"hold": 30.0, "rise": 30.0, "level": 64.0, "drown_dps": 16, "surge": 120}, - {"hold": 20.0, "rise": 40.0, "level": 75.0, "drown_dps": 25, "surge": 150}, + {"hold": 150.0, "rise": 60.0, "level": 6.0, "drown_dps": 2, "surge": 0}, + {"hold": 130.0, "rise": 50.0, "level": 14.0, "drown_dps": 4, "surge": 40}, + {"hold": 120.0, "rise": 45.0, "level": 24.0, "drown_dps": 6, "surge": 60}, + {"hold": 110.0, "rise": 40.0, "level": 34.0, "drown_dps": 8, "surge": 80}, + {"hold": 90.0, "rise": 35.0, "level": 46.0, "drown_dps": 12, "surge": 100}, + {"hold": 60.0, "rise": 30.0, "level": 58.0, "drown_dps": 16, "surge": 120}, + {"hold": 45.0, "rise": 40.0, "level": 75.0, "drown_dps": 25, "surge": 150}, ] ## Each island's levels are planned from its terrain (SafeGround): a phase's level is ## lowered, if need be, to this far under the top of the largest piece of land still @@ -270,11 +270,12 @@ const BOT_PATH_CHECK_TICKS: int = 15 ## Per difficulty: `reaction` is seconds between first seeing an opponent and firing, ## `aim_error` the most their aim wanders off the target in degrees, `sight` how far ## they can pick an opponent out in metres, and `lead` how much of a moving target's -## travel they allow for with slow shots (0 none, 1 all of it). +## travel they allow for with slow shots (0 none, 1 all of it), and `retreat` the health +## plus armor at or under which they break off a fight to heal (0 never). const BOT_DIFFICULTIES: Array[Dictionary] = [ - {"name": "easy", "reaction": 0.9, "aim_error": 7.0, "sight": 45.0, "lead": 0.0}, - {"name": "normal", "reaction": 0.5, "aim_error": 3.5, "sight": 65.0, "lead": 0.5}, - {"name": "hard", "reaction": 0.25, "aim_error": 1.5, "sight": 90.0, "lead": 1.0}, + {"name": "easy", "reaction": 0.9, "aim_error": 9.0, "sight": 45.0, "lead": 0.0, "retreat": 0}, + {"name": "normal", "reaction": 0.5, "aim_error": 5.5, "sight": 65.0, "lead": 0.5, "retreat": 35}, + {"name": "hard", "reaction": 0.25, "aim_error": 3.0, "sight": 90.0, "lead": 1.0, "retreat": 50}, ] ## Each bot looks around once in this many ticks. const BOT_SENSE_TICKS: int = 6 @@ -288,6 +289,22 @@ const BOT_MEMORY_SECONDS: float = 4.0 const BOT_AIM_WANDER_TICKS: int = 12 ## Bots ease off the trigger while bloom is above this, in degrees. const BOT_BLOOM_PAUSE_DEGREES: float = 3.0 +## Bots pick out a new opponent only this close (or their `sight`, if less). Anyone who +## shoots them is fought as far off as they can see. Without it bot lobbies emptied in +## the first two minutes; see docs/BALANCE.md. +const BOT_ENGAGE_METRES: float = 30.0 +## A bot breaking off a fight runs for this long towards safe ground about this far +## away from its opponent, and won't break off again until as long again has passed. +const BOT_RETREAT_SECONDS: float = 6.0 +const BOT_RETREAT_METRES: float = 30.0 +## A bot weighs this many landing spots near the barge's line and takes the one with +## the fewest other bots' landings within BOT_LANDING_SPREAD_METRES. +const BOT_LANDING_CHOICES: int = 8 +const BOT_LANDING_SPREAD_METRES: float = 60.0 +## With nothing to loot, a bot roams to safe ground at most this far from where it is. +const BOT_ROAM_METRES: float = 60.0 +## Having roamed there, it holds that ground this long before moving on. +const BOT_HOLD_SECONDS: float = 45.0 ## Bots notice items lying within this distance. const BOT_LOOT_SIGHT_METRES: float = 12.0 ## A bot with no gun goes for an opponent in view this close with its boathook, in @@ -412,7 +429,7 @@ const WEAPONS: Dictionary = { "spread": 0.8, "bloom": 0.6, "ammo": "cartridges", "headshot": 2.0, }, "rivet_repeater": { - "damage": 17, "fire_rate": 11.0, "magazine": 35, "reload": 2.0, + "damage": 15, "fire_rate": 11.0, "magazine": 35, "reload": 2.0, "range_full": 12.0, "range_max": 45.0, "falloff_min": 0.4, "rarity": 0, "spread": 2.4, "bloom": 0.25, "ammo": "cartridges", "headshot": 1.5, }, @@ -512,3 +529,13 @@ const LOOT_THROWN_COUNT: int = 2 const CHEST_RANGE: float = 2.5 ## Loot from one spot lands on a ring this far from it. const LOOT_SCATTER_METRES: float = 0.7 + +# Balance targets (H3), judged by `make balance` over bot-only matches; see docs/BALANCE.md. +## The pass needs at least this many matches. +const BALANCE_MIN_MATCHES: int = 200 +## The median match, from the barge leaving to the last player standing, lasts this +## many minutes. +const BALANCE_MEDIAN_MINUTES_MIN: float = 12.0 +const BALANCE_MEDIAN_MINUTES_MAX: float = 18.0 +## No one weapon takes more than this share of the eliminations made with weapons. +const BALANCE_MAX_WEAPON_SHARE: float = 0.35 diff --git a/test/bots/balance_report.gd b/test/bots/balance_report.gd new file mode 100644 index 0000000..184638f --- /dev/null +++ b/test/bots/balance_report.gd @@ -0,0 +1,121 @@ +## Adds up BotBatch.run_match() results for the balance pass (H3) and judges them +## against the targets in Tuning (BALANCE_*). Shared by tools/balance.gd and its test. +class_name BalanceReport +extends RefCounted + +## Minutes at which the report counts who is still standing. +const STANDING_AT_MINUTES: Array[int] = [2, 4, 6, 8, 10, 12, 14] + + +## The value at fraction `q` (0 to 1) of a sorted list, interpolating between neighbours. +static func quantile(sorted: Array[float], q: float) -> float: + if sorted.is_empty(): + return 0.0 + var position: float = q * (sorted.size() - 1) + var low: int = floori(position) + var high: int = mini(low + 1, sorted.size() - 1) + return lerpf(sorted[low], sorted[high], position - low) + + +## Returns {"matches", "minutes": {"p10", "p25", "median", "p75", "p90", "min", "max"}, +## "finished", "with_winner", "timed_out", "causes", "deaths", "tide_share", +## "weapon_kills", "weapon_share": {weapon: fraction of weapon eliminations}, +## "top_weapon", "top_share", "wins", "eliminations", "mean_place", +## "standing": {minute: mean players standing}, "problems": [String]}. +static func analyse(results: Array[Dictionary]) -> Dictionary: + var minutes: Array[float] = [] + var weapon_kills: Dictionary = {} + var standing: Dictionary = {} + for minute: int in STANDING_AT_MINUTES: + standing[minute] = 0.0 + for result: Dictionary in results: + minutes.append(float(result["ticks"]) / Tuning.TICK_RATE_HZ / 60.0) + for weapon: String in result.get("weapon_kills", {}): + weapon_kills[weapon] = int(weapon_kills.get(weapon, 0)) + int(result["weapon_kills"][weapon]) + var deaths: Array = result.get("death_seconds", []) + var players: int = Tuning.SOLO_PLAYERS + for minute: int in STANDING_AT_MINUTES: + var fallen: int = 0 + for at: Variant in deaths: + if float(at) <= minute * 60.0: + fallen += 1 + standing[minute] += float(players - fallen) + minutes.sort() + var typed: Array[Dictionary] = results + var total: Dictionary = BotBatch.summarise(typed) + var analysis: Dictionary = { + "matches": results.size(), + "minutes": { + "min": minutes[0] if not minutes.is_empty() else 0.0, + "p10": quantile(minutes, 0.1), "p25": quantile(minutes, 0.25), + "median": quantile(minutes, 0.5), "p75": quantile(minutes, 0.75), + "p90": quantile(minutes, 0.9), "max": minutes[-1] if not minutes.is_empty() else 0.0, + }, + "finished": total["finished"], "with_winner": total["with_winner"], "timed_out": total["timed_out"], + "causes": total["causes"], "deaths": total["deaths"], + "tide_share": float(int(total["causes"].get("drown", 0)) + int(total["causes"].get("tide", 0))) / maxi(total["deaths"], 1), + "weapon_kills": weapon_kills, "weapon_share": {}, "top_weapon": "", "top_share": 0.0, + "wins": total["wins"], "eliminations": total["eliminations"], "mean_place": total["mean_place"], + "standing": {}, "problems": [], + } + var weapon_total: int = 0 + for weapon: String in weapon_kills: + weapon_total += int(weapon_kills[weapon]) + for weapon: String in weapon_kills: + var share: float = float(weapon_kills[weapon]) / maxi(weapon_total, 1) + analysis["weapon_share"][weapon] = share + if share > analysis["top_share"]: + analysis["top_share"] = share + analysis["top_weapon"] = weapon + for minute: int in STANDING_AT_MINUTES: + analysis["standing"][minute] = standing[minute] / maxi(results.size(), 1) + var problems: Array = analysis["problems"] + if results.size() < Tuning.BALANCE_MIN_MATCHES: + problems.append("only %d matches; the pass needs %d" % [results.size(), Tuning.BALANCE_MIN_MATCHES]) + if total["finished"] != results.size() or total["with_winner"] != results.size(): + problems.append("%d of %d matches finished with a winner" % [total["with_winner"], results.size()]) + var median: float = analysis["minutes"]["median"] + if median < Tuning.BALANCE_MEDIAN_MINUTES_MIN or median > Tuning.BALANCE_MEDIAN_MINUTES_MAX: + problems.append("median match length %.1f min is outside %.0f to %.0f" % [median, Tuning.BALANCE_MEDIAN_MINUTES_MIN, Tuning.BALANCE_MEDIAN_MINUTES_MAX]) + if analysis["top_share"] > Tuning.BALANCE_MAX_WEAPON_SHARE: + problems.append("%s took %.0f%% of weapon eliminations, over the %.0f%% limit" % [analysis["top_weapon"], analysis["top_share"] * 100.0, Tuning.BALANCE_MAX_WEAPON_SHARE * 100.0]) + return analysis + + +## The report as plain text. +static func format(a: Dictionary) -> String: + var lines: PackedStringArray = [] + var m: Dictionary = a["minutes"] + lines.append("Tidewall balance report: %d bot-only matches, %d players each" % [a["matches"], Tuning.SOLO_PLAYERS]) + lines.append("") + lines.append("Match length (minutes from the barge leaving):") + lines.append(" min %.1f p10 %.1f p25 %.1f median %.1f p75 %.1f p90 %.1f max %.1f" % [m["min"], m["p10"], m["p25"], m["median"], m["p75"], m["p90"], m["max"]]) + lines.append(" target median %.0f to %.0f; %d of %d ended by the tide's clock" % [Tuning.BALANCE_MEDIAN_MINUTES_MIN, Tuning.BALANCE_MEDIAN_MINUTES_MAX, a["timed_out"], a["matches"]]) + var curve: PackedStringArray = [] + for minute: int in STANDING_AT_MINUTES: + curve.append("%d min: %.1f" % [minute, a["standing"][minute]]) + lines.append(" mean players standing: " + ", ".join(curve)) + lines.append("") + lines.append("Causes of %d falls:" % a["deaths"]) + var causes: Array = a["causes"].keys() + causes.sort() + for cause: String in causes: + lines.append(" %-8s %5d %5.1f%%" % [cause, a["causes"][cause], 100.0 * a["causes"][cause] / maxi(a["deaths"], 1)]) + lines.append(" the sea (drown + tide): %.1f%%" % (a["tide_share"] * 100.0)) + lines.append("") + lines.append("Eliminations by weapon (limit %.0f%% for any one):" % (Tuning.BALANCE_MAX_WEAPON_SHARE * 100.0)) + var weapons: Array = a["weapon_kills"].keys() + weapons.sort_custom(func(x: String, y: String) -> bool: return a["weapon_kills"][x] > a["weapon_kills"][y]) + for weapon: String in weapons: + lines.append(" %-16s %5d %5.1f%%" % [weapon, a["weapon_kills"][weapon], a["weapon_share"][weapon] * 100.0]) + lines.append("") + lines.append("By difficulty:") + for level: String in ["easy", "normal", "hard"]: + lines.append(" %-6s wins %3d eliminations %5d mean place %.2f" % [level, a["wins"].get(level, 0), a["eliminations"].get(level, 0), a["mean_place"].get(level, 0.0)]) + lines.append("") + if a["problems"].is_empty(): + lines.append("balance: ok") + else: + for problem: String in a["problems"]: + lines.append("balance FAIL: %s" % problem) + return "\n".join(lines) + "\n" diff --git a/test/bots/balance_report.gd.uid b/test/bots/balance_report.gd.uid new file mode 100644 index 0000000..0457ab2 --- /dev/null +++ b/test/bots/balance_report.gd.uid @@ -0,0 +1 @@ +uid://b7srh0xr2vucq diff --git a/test/bots/bot_batch.gd b/test/bots/bot_batch.gd index 2c79dda..3f6b5b4 100644 --- a/test/bots/bot_batch.gd +++ b/test/bots/bot_batch.gd @@ -12,8 +12,9 @@ static func tick_limit() -> int: ## 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"}. +## "eliminations": {difficulty name: count}, "weapon_kills": {item id: count}, +## "death_seconds": [seconds into the match of each fall], "shots", "slow_ticks", +## "timing", "state_hash"}. Seconds count from the barge leaving. 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 @@ -23,7 +24,7 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul var result: Dictionary = { "seed": seed_value, "finished": false, "winner": 0, "winner_difficulty": "", "timed_out": false, "causes": {}, "places": {}, "eliminations": {}, "shots": 0, - "slow_ticks": [], + "slow_ticks": [], "weapon_kills": {}, "death_seconds": [], } var limit: int = tick_limit() while loop.ticks < limit and flow.phase != Match.RESULTS: @@ -52,6 +53,15 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul 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 result["timing"] = loop.timing_stats() result["state_hash"] = loop.sim.state_hash() return result diff --git a/test/bots/test_balance_report.gd b/test/bots/test_balance_report.gd new file mode 100644 index 0000000..566d5ba --- /dev/null +++ b/test/bots/test_balance_report.gd @@ -0,0 +1,54 @@ +extends TestCase + +## The balance pass's report (H3): match length quantiles, weapon shares, survivors +## over time, and the verdict against the BALANCE_* targets. + + +func _match(seed_value: int, minutes: float, kills: Dictionary, winner: String = "normal") -> Dictionary: + var deaths: Array = [] + for index: int in Tuning.SOLO_PLAYERS - 1: + deaths.append(minutes * 60.0 * (index + 1) / Tuning.SOLO_PLAYERS) + return { + "seed": seed_value, "finished": true, "winner": -1, "winner_difficulty": winner, "timed_out": false, + "causes": {"weapon": Tuning.SOLO_PLAYERS - 1}, "places": {"normal": [1, 2]}, "eliminations": {"normal": 2}, + "weapon_kills": kills, "death_seconds": deaths, "shots": 10, "ticks": roundi(minutes * 60.0 * Tuning.TICK_RATE_HZ), + "timing": {"p99_us": 100, "over_budget": 0}, "state_hash": "x", + } + + +func test_quantiles_interpolate() -> void: + var values: Array[float] = [1.0, 2.0, 3.0, 4.0] + assert_eq(BalanceReport.quantile(values, 0.0), 1.0) + assert_eq(BalanceReport.quantile(values, 0.5), 2.5) + assert_eq(BalanceReport.quantile(values, 1.0), 4.0) + assert_eq(BalanceReport.quantile([] as Array[float], 0.5), 0.0) + + +func test_a_balanced_batch_passes() -> void: + var results: Array[Dictionary] = [] + for index: int in Tuning.BALANCE_MIN_MATCHES: + results.append(_match(index, 13.0 + (index % 5) * 0.5, {"dock_carbine": 8, "signal_revolver": 8, "rivet_repeater": 7})) + var a: Dictionary = BalanceReport.analyse(results) + assert_eq(a["problems"], [], "no problems: %s" % [a["problems"]]) + assert_eq(a["minutes"]["median"], 14.0) + assert_true(absf(a["weapon_share"]["dock_carbine"] - 8.0 / 23.0) < 0.001) + assert_true(a["standing"][12] > 1.0 and a["standing"][2] > a["standing"][12], "survivors fall over time: %s" % [a["standing"]]) + assert_true(BalanceReport.format(a).contains("balance: ok")) + + +func test_short_matches_a_dominant_weapon_and_a_small_batch_fail() -> void: + var results: Array[Dictionary] = [] + for index: int in 10: + results.append(_match(index, 6.0, {"rivet_repeater": 20, "dock_carbine": 3})) + var a: Dictionary = BalanceReport.analyse(results) + var text: String = BalanceReport.format(a) + assert_eq(a["problems"].size(), 3, "count, length and weapon: %s" % [a["problems"]]) + assert_true(text.contains("only 10 matches")) + assert_true(text.contains("median match length 6.0 min")) + assert_true(text.contains("rivet_repeater took 87%")) + + +func test_every_match_ends_inside_the_longest_target() -> void: + var seconds: float = float(Tide.new(0).time_limit_offset()) / Tuning.TICK_RATE_HZ + assert_true(seconds <= Tuning.BALANCE_MEDIAN_MINUTES_MAX * 60.0, "the tide and sudden death take %.0f s" % seconds) + assert_true(seconds >= Tuning.BALANCE_MEDIAN_MINUTES_MIN * 60.0, "and leave room for a %.0f-minute match" % Tuning.BALANCE_MEDIAN_MINUTES_MIN) diff --git a/test/bots/test_balance_report.gd.uid b/test/bots/test_balance_report.gd.uid new file mode 100644 index 0000000..a800ed4 --- /dev/null +++ b/test/bots/test_balance_report.gd.uid @@ -0,0 +1 @@ +uid://c1yqg4w0d1y1a diff --git a/test/bots/test_bot_brain.gd b/test/bots/test_bot_brain.gd index ce28bf9..e3fea61 100644 --- a/test/bots/test_bot_brain.gd +++ b/test/bots/test_bot_brain.gd @@ -39,6 +39,14 @@ func _bot(at: Vector3, level: int = BotBrain.NORMAL, yaw: int = 0) -> BotBrain: return brain +## Keeps an idle bot where it stands, facing as it was put, instead of roaming off and +## turning its back on whoever the test placed. +func _pin(brain: BotBrain) -> void: + brain._hunt_goal = sim.entities.find(brain.player_id).position + brain._holding = true + brain._hunt_until = 1 << 30 + + func _arm(player: SimEntity, weapon: String = "dock_carbine", ammo: String = "cartridges", rounds: int = 150) -> void: assert_eq(Inventory.give(player, ItemCatalog.code_of(weapon), 1), 0) Inventory.give(player, ItemCatalog.code_of(ammo), rounds) @@ -144,6 +152,7 @@ func test_an_armed_bot_eliminates_an_opponent_it_can_see() -> void: _arm(sim.entities.find(brain.player_id)) var victim: SimEntity = _player(HOME + Vector3(25.0, 0.0, 0.0)) _ready_world() + _pin(brain) _run(30 * TICKS, func() -> bool: return victim.eliminated) assert_true(victim.eliminated, "the opponent fell (health %d)" % victim.health) assert_eq(victim.last_attacker, brain.player_id) @@ -191,6 +200,7 @@ func test_bots_wait_out_their_reaction_time() -> void: _arm(sim.entities.find(brain.player_id)) _player(HOME + Vector3(20.0, 0.0, 0.0)) _ready_world() + _pin(brain) _run(4 * TICKS, func() -> bool: return not first_shot.is_empty()) assert_true(first_shot.has(brain.player_id), "%s fired" % brain.difficulty_name()) var reaction: int = roundi(float(Tuning.BOT_DIFFICULTIES[level]["reaction"]) * TICKS) @@ -330,6 +340,8 @@ func test_an_unarmed_bot_closes_in_and_swings_its_boathook() -> void: var victim: SimEntity = _player(HOME + Vector3(4.5, 0.0, 0.0)) var start: int = victim.health _ready_world() + # Unarmed bots only brawl someone who hit them (H3). + Weapons.damage_player(sim, sim.entities.find(brain.player_id), 5, victim.id) var swings: Array[int] = [0] for _tick: int in 6 * TICKS: _run(1) @@ -353,3 +365,84 @@ func test_an_unarmed_bot_leaves_a_distant_opponent_alone() -> void: _run(3 * TICKS) assert_ne(brain.state, "brawl") assert_eq(victim.health, Tuning.PLAYER_MAX_HEALTH) + + +func test_an_unarmed_bot_does_not_start_a_brawl() -> void: + _setup() + var brain: BotBrain = _bot(HOME, BotBrain.HARD, FACING_X) + var other: SimEntity = _player(HOME + Vector3(4.5, 0.0, 0.0)) + _ready_world() + _run(3 * TICKS) + assert_ne(brain.state, "brawl") + assert_eq(other.health, Tuning.PLAYER_MAX_HEALTH, "nobody was hit") + + +func test_a_bot_ignores_a_far_opponent_until_it_is_shot() -> void: + _setup() + var brain: BotBrain = _bot(HOME, BotBrain.HARD, FACING_X) + var me: SimEntity = sim.entities.find(brain.player_id) + _arm(me) + # In sight (hard bots see 90 m) but further than a bot picks out a new opponent. + var other: SimEntity = _player(HOME + Vector3(Tuning.BOT_ENGAGE_METRES + 15.0, 0.0, 0.0)) + _ready_world() + _pin(brain) + _run(2 * TICKS) + assert_eq(brain.target_id, 0, "it doesn't go looking for a fight that far off") + assert_true(shots_by.is_empty()) + Weapons.damage_player(sim, me, 10, other.id) + _run(3 * TICKS) + assert_eq(brain.target_id, other.id, "but answers one who shoots at it") + assert_true(int(shots_by.get(me.id, 0)) > 0, "and fires back") + + +func test_an_unarmed_bot_runs_from_a_gun() -> void: + _setup() + var brain: BotBrain = _bot(HOME, BotBrain.EASY, FACING_X) + var me: SimEntity = sim.entities.find(brain.player_id) + var gunner: SimEntity = _player(HOME + Vector3(12.0, 0.0, 0.0), FACING_X * 3) + _arm(gunner) + gunner.selected = 1 + _ready_world() + _pin(brain) + _run(2 * TICKS) + assert_eq(brain.state, "retreat", "an unarmed bot breaks away from a held gun") + _run(4 * TICKS) + assert_true(me.position.distance_to(gunner.position) > 16.0, "and gets further off (%.1f m)" % me.position.distance_to(gunner.position)) + + +func test_a_badly_hurt_bot_breaks_off_but_an_easy_one_does_not() -> void: + for level: int in [BotBrain.HARD, BotBrain.EASY]: + _setup() + var brain: BotBrain = _bot(HOME, level, FACING_X) + var me: SimEntity = sim.entities.find(brain.player_id) + _arm(me) + Inventory.give(me, ItemCatalog.code_of("sailcloth_bandage"), 2) + me.health = 30 + var other: SimEntity = _player(HOME + Vector3(20.0, 0.0, 0.0), FACING_X * 3) + _arm(other) + other.selected = 1 + _ready_world() + _pin(brain) + var states: Dictionary = {} + for _tick: int in 2 * TICKS: + _run(1) + states[brain.state] = true + if level == BotBrain.HARD: + assert_true(states.has("retreat"), "hard breaks off at 30 health with bandages: %s" % [states.keys()]) + else: + assert_false(states.has("retreat"), "easy fights on: %s" % [states.keys()]) + assert_true(states.has("fight"), "easy fights: %s" % [states.keys()]) + + +func test_a_bot_with_nothing_to_do_holds_its_ground() -> void: + _setup() + var brain: BotBrain = _bot(HOME) + var me: SimEntity = sim.entities.find(brain.player_id) + _arm(me) + _ready_world() + _run(60 * TICKS, func() -> bool: return brain.state == "hold") + assert_eq(brain.state, "hold", "it roams somewhere and settles") + var at: Vector3 = me.position + _run(roundi(Tuning.BOT_HOLD_SECONDS * 0.8) * TICKS) + assert_true(me.position.distance_to(at) < 3.0, "and stays put while holding (moved %.1f m)" % me.position.distance_to(at)) + assert_true(at.distance_to(HOME) <= Tuning.BOT_ROAM_METRES + 5.0, "it didn't roam far (%.1f m)" % at.distance_to(HOME)) diff --git a/test/bots/test_scripted_player.gd b/test/bots/test_scripted_player.gd index 0362929..5d4416b 100644 --- a/test/bots/test_scripted_player.gd +++ b/test/bots/test_scripted_player.gd @@ -16,9 +16,10 @@ func test_a_scripted_seat_sends_commands_like_anyone_else() -> void: func test_harvests_driftwood_and_builds_with_it() -> void: - # Seed 2 is the match `make match` plays: the player lands, finds a weapon, cuts - # driftwood and puts up a breakwater and a wall about a minute in. - var loop: ServerLoop = ServerLoop.new(2, 1, 23) + # Seed 29 is the match `make match` plays: the player lands, finds a weapon, cuts + # driftwood and puts up a breakwater and a wall within a minute. (It was seed 2 until + # H3 changed where bots land; there the scripted player now falls in a landing fight.) + var loop: ServerLoop = ServerLoop.new(29, 1, 23) loop.play_humans_by_script() var player: ScriptedPlayer = loop.scripted[0] var placed: int = 0 diff --git a/test/client/test_client_session.gd b/test/client/test_client_session.gd index 45e8c78..3a05416 100644 --- a/test/client/test_client_session.gd +++ b/test/client/test_client_session.gd @@ -80,13 +80,20 @@ func test_offline_play_goes_through_the_same_client_against_a_local_server() -> assert_eq(session.game.bad_packets, 0) assert_eq(session.local.game.bad_inputs, 0) assert_true(session.game.prediction.max_correction < 1.0, "largest correction %.2f m" % session.game.prediction.max_correction) - # On seed 2 a bot finds the scripted player soon after. From then on the client - # watches whoever it is given to watch. - for frame: int in 60 * 60: + # A bot brings the scripted player down. (It used to be left to the bots, but since + # H3 they hold their ground and how soon one turns up is luck.) From then on the + # client watches whoever it is given to watch. + for frame: int in 60 * 20: + session.pump(FRAME) + if mine.eliminated or came_down.distance_to(mine.position) > 3.0: + break + var walked_to: Vector3 = mine.position + Weapons.damage_player(server.sim, mine, Tuning.PLAYER_MAX_HEALTH + Tuning.PLAYER_MAX_ARMOR, server.bots[0].player_id) + for frame: int in 60 * 10: session.pump(FRAME) if mine.eliminated and session.mirror.watched_id != 0 and session.mirror.watched_id != mine.id: break - assert_true(came_down.distance_to(mine.position) > 3.0, "it walked: the server took its commands") + assert_true(came_down.distance_to(walked_to) > 3.0, "it walked: the server took its commands") assert_true(mine.eliminated, "the scripted player fell") assert_false(session.game.playing()) assert_eq(session.mirror.own_id, 0) diff --git a/test/server/test_server_loop.gd b/test/server/test_server_loop.gd index d372f7d..0b57da0 100644 --- a/test/server/test_server_loop.gd +++ b/test/server/test_server_loop.gd @@ -47,17 +47,23 @@ func test_percentile_uses_nearest_rank() -> void: func test_bots_leap_and_humans_without_commands_stay_aboard() -> void: # Every match starts on the drop carrier. A human who sends nothing rides it; the bot - # leaps at its own fixed moment and falls away. + # leaps once the spot it chose is in gliding reach, before the route ends, and falls + # away. var loop: ServerLoop = ServerLoop.new(99, 1, 1) var human: SimEntity = loop.sim.entities.find(1) var bot: SimEntity = loop.sim.entities.find(2) assert_eq(human.drop_state, Drop.ABOARD) assert_eq(bot.drop_state, Drop.ABOARD) - for _index: int in Tuning.TICK_RATE_HZ * 24: + var leapt_tick: int = -1 + while not loop.sim.drop.is_over(loop.sim.tick): loop.run_tick() + if leapt_tick < 0 and bot.drop_state != Drop.ABOARD: + leapt_tick = loop.sim.tick + if leapt_tick >= 0 and loop.sim.tick >= leapt_tick + Tuning.TICK_RATE_HZ * 5: + break assert_eq(human.drop_state, Drop.ABOARD) assert_true(human.position.distance_to(loop.sim.drop.barge_position(loop.sim.tick)) < 0.001) - assert_ne(bot.drop_state, Drop.ABOARD, "the bot should have leapt") + assert_true(leapt_tick >= 0, "the bot should have leapt before the route ended") assert_true(bot.position.y < Tuning.BARGE_ALTITUDE - 20.0, "the bot should be falling, at %s" % bot.position) diff --git a/test/server/test_world_replication.gd b/test/server/test_world_replication.gd index 0f39fa1..898fad4 100644 --- a/test/server/test_world_replication.gd +++ b/test/server/test_world_replication.gd @@ -105,17 +105,16 @@ func test_a_clients_world_agrees_with_the_servers_through_a_scripted_match() -> var most_pending: int = 0 var most_pieces: int = 0 var scripted: SimEntity = sim.entities.find(loop.scripted[0].player_id) - var shielded: bool = false while flow.phase != Match.RESULTS and loop.ticks < LIMIT_TICKS and differed == 0: _round() most_pending = maxi(most_pending, client.replica.pending_count()) most_pieces = maxi(most_pieces, sim.structures.count()) - if not shielded and scripted.drop_state == Drop.NONE and scripted.on_ground: - # Since H9 unarmed bots brawl, and on this seed one meets the scripted player - # early. Full armor keeps it alive to harvest and build, which this test needs - # to replicate; the fight itself isn't what's under test. - shielded = true + if scripted.drop_state == Drop.NONE and scripted.on_ground and not scripted.eliminated and loop.scripted[0].step != ScriptedPlayer.DONE: + # On this seed bots meet the scripted player soon after landing. Topping up its + # health and armor until its script is done keeps it alive to harvest and + # build, which this test needs to replicate; the fights aren't under test. scripted.armor = Tuning.PLAYER_MAX_ARMOR + scripted.health = Tuning.PLAYER_MAX_HEALTH if not landed and mine.drop_state == Drop.NONE and mine.on_ground and not mine.eliminated: # On the ground: hand it driftwood for two walls and a floor, and let it # try the walls. @@ -129,6 +128,12 @@ func test_a_clients_world_agrees_with_the_servers_through_a_scripted_match() -> # server finds the driftwood gone before it runs that tick. refused = true mine.materials[Materials.DRIFTWOOD] = 0 + if loop.ticks == 4 * 60 * Tuning.TICK_RATE_HZ + 10 and sim.props.destroyed.is_empty(): + # Bots no longer shoot up the scenery much (H3), so break a prop near the + # scripted player for the props' replication to be tested. + var near: PackedInt32Array = sim.props.near(scripted.position, 200.0) + if not near.is_empty(): + sim.damage_prop(near[0], 1 << 20) if loop.ticks % 150 == 0: if not _agrees("during the match"): differed += 1 diff --git a/test/sim/test_tide.gd b/test/sim/test_tide.gd index 3b4fc33..a3e957a 100644 --- a/test/sim/test_tide.gd +++ b/test/sim/test_tide.gd @@ -108,17 +108,24 @@ func test_the_schedule_follows_the_table_and_forecasts_each_level() -> void: func test_planned_levels_keep_safe_ground_on_the_main_land() -> void: - # A 30 m plateau: the table's 30 m phase would drown it all, so it's lowered. + # A 30 m plateau: the first table phase above 28 m would drown it all, so it's + # lowered; the phases before it keep their table levels. var safe: SafeGround = SafeGround.new(_ground(30.0)) var levels: PackedFloat32Array = safe.plan_levels() assert_eq(levels.size(), Tuning.TIDE_PHASES.size()) - assert_eq(levels[0], float(Tuning.TIDE_PHASES[0]["level"])) - assert_eq(levels[1], float(Tuning.TIDE_PHASES[1]["level"])) - assert_eq(levels[2], 30.0 - Tuning.TIDE_SAFE_MARGIN_METRES, "lowered to just under the land's top") + var lowered: int = -1 + for index: int in Tuning.TIDE_PHASES.size(): + if float(Tuning.TIDE_PHASES[index]["level"]) > 30.0 - Tuning.TIDE_SAFE_MARGIN_METRES: + lowered = index + break + assert_true(lowered > 0 and lowered < levels.size() - 1, "the table has a phase to lower (%d)" % lowered) + for index: int in lowered: + assert_eq(levels[index], float(Tuning.TIDE_PHASES[index]["level"])) + assert_eq(levels[lowered], 30.0 - Tuning.TIDE_SAFE_MARGIN_METRES, "lowered to just under the land's top") for index: int in range(1, levels.size()): assert_true(levels[index] >= levels[index - 1] + Tuning.TIDE_MIN_RISE_METRES - 0.001, "phase %d still rises" % index) assert_eq(levels[levels.size() - 1], float(Tuning.TIDE_PHASES[-1]["level"]), "the last phase covers everything") - assert_true(safe.is_safe(500.0, 500.0, levels[2])) + assert_true(safe.is_safe(500.0, 500.0, levels[lowered])) assert_false(safe.is_safe(100.0, 100.0, 0.0), "open sea is never safe") diff --git a/tools/balance.gd b/tools/balance.gd new file mode 100644 index 0000000..861035d --- /dev/null +++ b/tools/balance.gd @@ -0,0 +1,75 @@ +## The balance pass (issue H3). Two modes: +## +## tools/godot.sh --script res://tools/balance.gd -- --run --first=1 --seeds=50 --out=PATH +## plays bot-only matches and appends one JSON line per match to PATH; +## tools/godot.sh --script res://tools/balance.gd -- --report=DIR +## reads every DIR/*.jsonl, writes DIR/report.txt and judges it against the GDD's +## balance targets (BALANCE_* in Tuning). Exits 1 if a target is missed. +## +## tools/balance.sh runs several --run processes side by side, then the report. +extends SceneTree + + +func _init() -> void: + var run: bool = false + var first: int = 1 + var count: int = 10 + var out: String = "" + var report_dir: String = "" + for arg: String in OS.get_cmdline_user_args(): + if arg == "--run": + run = true + elif arg.begins_with("--first="): + first = arg.trim_prefix("--first=").to_int() + elif arg.begins_with("--seeds="): + count = arg.trim_prefix("--seeds=").to_int() + elif arg.begins_with("--out="): + out = arg.trim_prefix("--out=") + elif arg.begins_with("--report="): + report_dir = arg.trim_prefix("--report=") + if run and out != "": + quit(_run(first, count, out)) + elif report_dir != "": + quit(_report(report_dir)) + else: + printerr("balance: give --run --first=N --seeds=N --out=PATH, or --report=DIR") + quit(2) + + +func _run(first: int, count: int, out: String) -> int: + for seed_value: int in range(first, first + count): + var result: Dictionary = BotBatch.run_match(seed_value) + result.erase("slow_ticks") + var file: FileAccess = FileAccess.open(out, FileAccess.READ_WRITE if FileAccess.file_exists(out) else FileAccess.WRITE) + if file == null: + printerr("balance: can't write %s" % out) + return 1 + file.seek_end() + file.store_line(JSON.stringify(result)) + file.close() + print("balance: seed %d done, %.1f min" % [seed_value, float(result["ticks"]) / Tuning.TICK_RATE_HZ / 60.0]) + return 0 + + +func _report(dir_path: String) -> int: + var results: Array[Dictionary] = [] + var dir: DirAccess = DirAccess.open(dir_path) + if dir == null: + printerr("balance: no directory %s" % dir_path) + return 2 + var names: PackedStringArray = dir.get_files() + names.sort() + for file_name: String in names: + if not file_name.ends_with(".jsonl"): + continue + for line: String in FileAccess.get_file_as_string(dir_path.path_join(file_name)).split("\n", false): + var parsed: Variant = JSON.parse_string(line) + if parsed is Dictionary: + results.append(parsed) + var analysis: Dictionary = BalanceReport.analyse(results) + var text: String = BalanceReport.format(analysis) + var file: FileAccess = FileAccess.open(dir_path.path_join("report.txt"), FileAccess.WRITE) + file.store_string(text) + file.close() + print(text) + return 0 if analysis["problems"].is_empty() else 1 diff --git a/tools/balance.gd.uid b/tools/balance.gd.uid new file mode 100644 index 0000000..6edb9f7 --- /dev/null +++ b/tools/balance.gd.uid @@ -0,0 +1 @@ +uid://cy2gcehjr7d2p diff --git a/tools/balance.sh b/tools/balance.sh new file mode 100755 index 0000000..5afe81d --- /dev/null +++ b/tools/balance.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# H3: the balance pass. Plays BALANCE_MATCHES bot-only matches (default 200) from seed +# BALANCE_FIRST (default 1001) in BALANCE_JOBS processes side by side (default 4), under +# nice, then writes build/balance/report.txt and judges it against the targets in +# docs/GDD.md ("Balance"). Each match is about half a minute of one core. +# +# tools/balance.sh +# BALANCE_MATCHES=30 BALANCE_JOBS=2 tools/balance.sh a quick look; fails the count +# BALANCE_REPORT_ONLY=1 tools/balance.sh report on what's in build/balance +set -uo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +matches="${BALANCE_MATCHES:-200}" +first="${BALANCE_FIRST:-1001}" +jobs="${BALANCE_JOBS:-4}" +out="${BALANCE_DIR:-build/balance}" + +if [[ "${BALANCE_REPORT_ONLY:-0}" != "1" ]]; then + mkdir -p "$out" + rm -f "$out"/*.jsonl "$out"/report.txt "$out"/job-*.log + per=$(( (matches + jobs - 1) / jobs )) + pids=() + for (( j = 0; j < jobs; j++ )); do + start=$(( first + j * per )) + count=$(( matches - j * per )) + (( count > per )) && count=$per + (( count <= 0 )) && break + nice -n 15 tools/godot.sh --script res://tools/balance.gd -- --run --first="$start" --seeds="$count" \ + --out="$PWD/$out/job-$j.jsonl" > "$out/job-$j.log" 2>&1 & + pids+=("$!") + done + failed=0 + for pid in "${pids[@]}"; do + wait "$pid" || failed=1 + done + if grep -lE 'SCRIPT ERROR|^ERROR' "$out"/job-*.log >/dev/null 2>&1; then + echo "balance FAIL: engine or script errors in $(grep -lE 'SCRIPT ERROR|^ERROR' "$out"/job-*.log | tr '\n' ' ')" + failed=1 + fi + if (( failed )); then + echo "balance FAIL: a batch process failed; see $out/job-*.log" + exit 1 + fi +fi +tools/godot.sh --script res://tools/balance.gd -- --report="$PWD/$out" diff --git a/tools/match.sh b/tools/match.sh index c9c5666..0fe8a93 100755 --- a/tools/match.sh +++ b/tools/match.sh @@ -4,12 +4,12 @@ # checks the replay ends in the same state. Prints one JSON line per event and the # verdict. See tools/match.gd. # -# tools/match.sh seed 2, where the scripted player also builds +# tools/match.sh seed 29, where the scripted player also builds # MATCH_SEED=7 tools/match.sh set -uo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." -seed="${MATCH_SEED:-2}" +seed="${MATCH_SEED:-29}" [[ "$seed" =~ ^[0-9]+$ ]] || { echo "match FAIL: bad MATCH_SEED '$seed'"; exit 2; } raw="$(timeout --signal=KILL 900 nice -n 15 tools/godot.sh --script res://tools/match.gd -- --seed="$seed" 2>&1)" code=$?