towerdef/docs/BALANCE.md
Claude b4ae6cb57d Difficulty picker (Easy/Normal/Hard) and a balance pass
Difficulty:
- TD.DIFFICULTIES (starting credits, lives, enemy hp/shield, kill reward), validated
  create-room / newgame option, state carries it; solo menu picker and co-op lobby
  picker (44px segmented control, reachable on every layout), HUD/room/end-screen
  labels, best-wave record per map AND difficulty (Normal keeps the legacy key),
  Play again keeps the running game's difficulty for host and guest

Balance (12 bot runs, deterministic, 48/48 games replay identically in QA):
- Normal ~71% bot wins at wave 30 (was 94%), Easy 100%, Hard 25% on open
- credits tamed: reward growth 3% -> 2% per wave, clear bonus 10+2n -> 10+n, hp scaling
  eased, Rootkit pays 60 (was 100) but is tougher, flyers slower; unspent credits at
  wave 30: 1309 -> 335
- IDS Sniper is now a slow heavy hitter (essential, no longer sufficient: IDS-only
  dies by wave 7); Mortar, Arc and Filter buffed
- Orbital Uplink price step per owned unit 30% (buy and upgrade)
- remaining imbalances documented in docs/BALANCE.md

Tests: difficulty (19) and balance (8) unit suites, 14-difficulty e2e, layout matrix
reachability of the picker. 156 unit tests, 17 e2e scenarios.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
2026-10-10 23:41:21 +00:00

177 lines
14 KiB
Markdown

# Balance notes (tuned 2026-10-10, wave 4 pass; the untuned baseline was measured the same day)
`public/js/sim.js` holds the tuned tables. The numbers were measured with `tools/bot.js`, a headless player that drives the sim
through `sim.cmd()` / `sim.preview()`. No test pins a tuned number: `test/sim.test.js` and `test/difficulty.test.js` derive values
from the tables, and `test/balance.test.js` pins the *design rules* the pass relied on (credit budget, boss pay, upgrade
efficiency, IDS role, Uplink price share, difficulty ladder), each derived from the tables too.
The pass was time-boxed (12 runs of the bot, counting two short smoke tests of the tool itself; 8 seeds per cell in the final ones). With 8 seeds one win more or less is 12 points:
read the tables as bands, not as exact rates.
## What a player should notice
* Kill money is smaller and flatter: a defence earns about 22% fewer credits over 30 waves (7676 -> 5980), a boss is worth
about half as much, and the clear bonus grows by 1 a wave instead of 2. Packet hit points are 14 to 21% lower than before
(they scale slower), which pays the credit cut back: Normal stays winnable, but no longer by a wide margin.
* The IDS Sniper is now a slow heavy sniper (fewer, harder shots): the same damage per second as before against a tank, worse
against a swarm of weak packets, so a defence made of IDS alone dies in the first swarm waves. It is still the backbone of
every strong build against bosses and armour.
* Mortar, Arc and Filter are better value; upgrades are cheaper for them (and dearer for the IDS), so credits go into
upgrading and into a mix.
* Flyers are slower (longer in range), Trojans and Rootkits are more armoured, the opening waves are unchanged.
## Constants changed, and why (all in `public/js/sim.js`)
| constant | before | after | reason |
|---|---|---|---|
| `rewardScale(n)` | 1 + 0.03 (n-1) | 1 + 0.02 (n-1) | late kills paid too much; credits snowballed |
| Rootkit `reward` | 100 | 60 | a boss wave paid the price of ~2 IDS; now about one (wave 10: 127 -> 71 credits, wave 30 with 3 bosses: 561 -> 285) |
| Rootkit `buyCost` | 300 | 180 | keeps the "about 3x the kill reward" rule of the future versus mode (`docs/VERSUS.md` number updated) |
| clear bonus | 10 + 2 n | 10 + n (`CLEAR_BONUS`, `CLEAR_BONUS_PER_WAVE`, `clearBonus(n)` exported) | the bonus alone was 16% of all credits; only constants were extracted, the formula is the same |
| `hpScale(n)` | 1 + 0.16 (n-1) + 0.022 (n-1)^2 | 1 + 0.145 (n-1) + 0.0165 (n-1)^2 | pays back the credit cut: 14% lower at wave 10, 19% at 20, 21% at 30 than the untuned game |
| Trojan `armor` | 3 | 4 | armour should matter a little more against Filters |
| Rootkit `armor` | 5 | 7 | same, and the boss is the IDS / Mortar / Uplink job |
| Spoof (ghost) `speed` | 1.6 | 1.3 | flyers ignore the maze, so they get little time in range; they were a cliff at waves 7, 13, 15, 23 |
| Botnet `speed` | 2.6 | 2.2 | same |
| IDS cost (L1/L2/L3) | 60 / 70 / 110 | 70 / 80 / 130 | the best tower per credit by far; 58 of them were built per game |
| IDS dmg | 50 / 85 / 150 | 83 / 143 / 250 | same dps against a tank as before... |
| IDS rate | 0.70 / 0.75 / 0.80 | 0.42 / 0.445 / 0.48 | ...but fewer shots, so swarms of weak packets are not its job (IDS-only now dies by wave 7) |
| IDS range | 6.5 / 7.2 / 8.0 | 6.2 / 6.8 / 7.5 | slightly less coverage per credit |
| IDS description | "...bosses." | "...bosses, poor against swarms." | the player is told |
| Filter range | 3.2 / 3.5 / 3.9 | 3.5 / 3.8 / 4.2 | the cheap swarm / anti-air tower had too little coverage |
| Filter upgrade cost (L2/L3) | 30 / 55 | 25 / 45 | an upgrade gave 58% of the dps per credit of a new tower |
| Mortar cost / dmg / range | 55 60 100 / 28 45 75 / 4.8 5.2 5.6 | 55 60 95 / 31 50 82 / 4.9 5.3 5.7 | far too weak; now the answer to ground swarms |
| Arc cost / dmg | 75 70 120 / 16 24 36 | 70 60 105 / 17 26 38 | far too weak alone; the first buff (dmg 20 30 44, 65 / 50 / 90) let Arc-only win 6 of 8 on `open`, so this is the middle |
| Arc range | 3.6 / 3.8 / 4.2 | 3.8 / 4.0 / 4.4 | |
| `DIFFICULTIES.hard` | gold 0.8, lives 0.7, hp 1.3, reward 0.9 | gold 0.9, lives 0.85, hp 1.08, reward 0.97 | the first row was a wall (0 wins in 35 games). The whole row (+8% hp, -3% rewards, -10% credits, -15% lives) takes `open` from 75% to 25% |
| `DIFFICULTIES.easy` | 1.5 / 1.5 / 0.8 / 1.1 | unchanged | already 56 of 56 |
Not changed: `START_GOLD` 140, `START_LIVES` 20, `WAVE_INTERVAL` 28, `SELL_RATIO` 0.7, every `waveGroups` count and gap, Throttle,
Sandbox, Load Balancer, and the Orbital Uplink (1500 / 1200 / 2000 / 3200, each owned Uplink makes the next one and its
upgrades 30% dearer: the user's request, kept). Wall price and wall count are untouched on purpose (user decision: the maze stays strong).
## Results (Normal unless stated; "win" = the wave 30 clear)
Before = the untuned numbers, 5 seeds. After = the shipped numbers, 8 seeds (Easy and Hard rows: `maze@easy`, `maze@hard`).
| mixed maze bot | before | after | target |
|---|---|---|---|
| open | 4/5 | 6/8 | 70-80% |
| twin | 5/5 | 5/8 | 50-70% |
| hub | 5/5 | 6/8 | 40-50% |
| canyon | 5/5 | 8/8 | 50-70% |
| archipelago | 5/5 | 5/8 | 50-70% |
| fortress | 4/5 | 5/8 | 50-70% |
| pinwheel | 5/5 | 5/8 | 40-50% |
| all maps | 33/35 (94%), 12-20 lives left | 40/56 (71%), 12 lives left (open 10) | about 58% |
| Easy, all maps | 35/35 | 56/56 (27-30 lives left of 30) | 90%+ |
| Hard, open / twin / hub | 0/35 on all maps (dies wave 7-29) | 2/8 / 1/8 / 0/8 (mean wave 25.6 / 21.5 / 20.9) | 20-35% on open |
| single-tower and ablation builds (8 seeds) | before | after |
|---|---|---|
| spam-ids (open+twin) | 35/35 (all maps) | 0/16, dies in wave 3-7 (swarm waves) |
| spam-filter (open+twin) | 0/35 (all maps), wave 12-23 | 0/16, wave 12-22 |
| spam-mortar (open, twin, hub) | 0/24, wave 6-8 (old doc) | 0/16 (open, twin), wave 6-8 (flyers: no anti-air) |
| spam-arc (open, twin, hub) | 0/24, wave 14-22 (old doc) | 0/16 (open, twin), wave 15-26 |
| mixed without IDS (open) | 0/5, dies wave 16-29 | 1/8 (mixed: 6/8) |
| mixed without Mortar (open) | not measured | 1/8 |
| mixed without Throttle (open) | not measured | 2/8 |
| mixed without Arc (open) | not measured | 6/8 |
| mixed without Filter (open) | not measured | 8/8 |
| economy (mixed bot) | before | after |
|---|---|---|
| credits paid by wave 10 / 15 / 20 / 25 / 30 (gold + invested, games that got that far, all maps) | 874 / 1551 / 2370 / 3560 / 6577 | 773 / 1320 / 2040 / 2860 / 5190 |
| credits in hand at wave 10 / 15 / 20 / 25 | 33 / 39 / 33 / 38 | 32 / 33 / 33 / 30 (always spent) |
| credits in hand at wave 30 (the bot stops buying when no wave is left to prepare for) | 1309 | 335 |
| full-clear income to wave 30 (table arithmetic, `income()` in `test/balance.test.js`) | 7676 | 5980 |
| IDS towers at wave 30 (open / twin / hub) | 58 / 49 / 44 (80-97% of all damage) | 25 / 30 / 25 (49% / 76% / 69%) |
| lives lost in waves 1-5 (sum over games) | 5 in 35 games | 3 in 56 games |
Where the lives go (mixed bot, all maps): Rootkit leaks (5 lives each) 66% before and 53% after; then Trojans 15%, Spoofs 10%,
Proxies 9%, Botnets 6%, Worms 5% (after).
## Targets scorecard
| target | state |
|---|---|
| maze beats no-maze, no-maze survives the first 8-10 waves, lazy dies early, no leaks in waves 1-5 | holds (8 seeds): mixed maze 6/8, 5/8, 6/8 on open / twin / hub against no-maze 1/8, 0/8, 0/8 (they die at wave 21-30, on hub all 8 in the wave 30 boss wave); lazy dies in wave 9 / 4 / 7; waves 1-5 lose 3 lives in 56 games |
| Normal open 70-80% | 75% (6/8) |
| twin, new maps 50-70% | twin 63, archipelago 63, fortress 63; **canyon 100%** |
| hub, pinwheel 40-50% | 75% and 63%: a little easy (not fixable with global tables, see below) |
| every spam strategy loses | **yes**, all four 0/16 |
| each tower type matters in the best mix | IDS (1/8 without), Mortar (1/8), Throttle (2/8): yes. **Filter and Arc: no** (the mix wins as often, or more, without them) |
| credits neither pile up nor starve | spent to the credit at every wave up to 25 (30-33 in hand), 335 at wave 30 (1309 before) |
| Easy 90%+, Hard 20-35% on open | 100%, 25% |
## Remaining known imbalances
1. **Filter and Arc do not pull their weight in the bot's best build.** Without Filters the mixed build wins 8/8 (with: 6/8)
on `open`; the bot over-buys them (23 on `open` at wave 30, 18% of damage) because its surrogate overrates cheap towers. The
bot buys almost no Arc (0 to 1.5 a game), though an Arc-only build now reaches wave 15-26. Either the towers still need a
role (Arc: chain on dense late swarms, Filter: early game and flyers) or the bot's model undervalues them; a human playtest
should decide. Throttle matters (2/8 without it).
2. **IDS is still the backbone**: 49 to 76% of the damage of the mixed builds and a build without it wins 1/8, but it is no
longer sufficient (IDS-only dies in wave 3-7). A mixed build with ~25 IDS and a handful of Mortars is what the bot finds best.
3. **Map spread is not tunable with global tables.** `canyon` (rating 1) is a 100% map, `hub` and `pinwheel` are easier than
asked, `archipelago` and `fortress` are about right. Hard is tuned to `open` (25%): on `twin` and `hub` it is 0 to 12%.
4. **Boss leaks decide games**: a Rootkit that gets through costs 5 of 20 lives and is the main cause of death. They are
dangerous on purpose (the user wanted bosses to hurt); if playtests find it too swingy, lower the Rootkit `leak` to 4 before
touching hp. Rootkits walk about 200 s through a long maze, so they overlap 6 to 7 later waves when waves are called on the
28 s timer: the bot's per-wave life-loss log attributes such a leak to the wave that was current when it happened.
5. **Sandbox, Load Balancer and Orbital Uplink are not valued well by the bot.** It never builds a Sandbox and rarely a Load
Balancer, so nothing can be said about them from the numbers. The Uplink was tested with a "save for it" rule: a bot that
saves from wave 12 to 16 starves its defence and dies (1/8, mean wave 18.6) before it can pay 1500. Judged on paper: the
first Uplink is 1500 = 25% of the 5980 credits a full run pays (the second 1950, the third 2540), and 1500 credits of IDS L1
is ~21 towers; the Uplink is an endless-mode purchase, not a way to win wave 30. Nothing was changed.
6. The waves were not touched. Flyer waves (`(n-1) % 8` = 4 and 6; from wave 14 with the Botnet swarm) and wave 28 are
still where defences break first; the Daemon, Proxy and Botnet themselves are not a leading cause of lost lives
(1 to 15% of leaks each).
7. The balance of Normal, Easy and Hard is steep: the whole Hard row (8% more packet hit points, 3% less pay, 10% fewer opening
credits, 15% fewer lives) moves `open` from 75% to 25%. Re-measure after *any* number change, with at least 8 seeds.
## Re-running the measurement
```bash
node tools/bot.js --maps open,twin,hub,canyon,archipelago,fortress,pinwheel \
--strategies "maze;maze@easy#open;maze@hard#open;maze-no-ids#open;maze-no-filter#open;maze-no-mortar#open;maze-no-arc#open;maze-no-throttle#open;spam-ids#open+twin;spam-arc#open+twin;spam-filter#open+twin;spam-mortar#open+twin" \
--seeds 8 --max 30 --verbose --json out.json
# the Easy (all maps) and Hard (open, twin, hub) rows of the results table
node tools/bot.js --maps open,twin,hub,canyon,archipelago,fortress,pinwheel \
--strategies "maze@easy;maze@hard#open+twin+hub" --seeds 8 --max 30 --verbose --json out-diff.json
```
(about 3 to 10 minutes on 6 cores; it uses all of them. `--sim other/sim.js` measures another copy; `--json out.json --detail`
for raw games; `--gold N` overrides the opening credits.) Strategy names: `maze` (the mixed build), `nomaze`, `spam-<type>`,
`maze-no-<type>`, `lazy`, `full` (mixed + Sandbox + Load Balancer + Uplink) and `maze+<type>` (mixed + one extra type), with
optional `:key=value` overrides (see `DEFAULTS` in the bot; use `;` between strategies that carry them). A strategy can carry a
game difficulty after `@` and the only maps it runs on after `#` (`maze@hard#open+twin`). The tables now print `gold@25` and a
"credits seen" block (gold + everything invested, games that reached the wave only). Tips: results depend on the bot's own
heuristics as much as on the numbers; `full` and `maze+uplink` save for the Uplink from wave 16 (12 with the override), which starves the
defence, so do not read their rows as balance data; the bot waits for each wave to clear but calls the next one after at most 28 s; for a
Uplink experiment `maze+uplink:uplinkFrom=12` makes it save for one from that wave.
The bot is deterministic: the same sim and the same seeds replay the same games, so every number above can be reproduced exactly
(an independent QA re-run of `maze`, `maze@easy` and `maze@hard` on open / hub / canyon, seeds 1-6, matched all 48 recorded games
move for move, outcome and lives left). `maze@hard` on `canyon` was not measured in the pass: 4 of 6 won in the QA re-run.
The bot's model of the support towers is crude: a Sandbox counts as a slow of `stun / pulse`, a Load Balancer as a fire-rate boost
on the turrets in its range, the Uplink as armour-ignoring damage with a pierce factor. Treat their rows as "not measured".
## The untuned baseline (for the record; 8 seeds, waves up to 45, 2026-10-09)
| strategy | open | twin | hub |
|---|---|---|---|
| maze (mixed) | 8/8 win | 6/8 | 8/8 |
| nomaze | 7/8 (dies ~wave 29-43) | 0/8 (wave 29-30) | 0/8 (wave 29) |
| spam-ids | **8/8 win** | **8/8 win** | **8/8 win** |
| spam-filter | 0/8 (wave 14-28) | 0/8 | 0/8 |
| spam-mortar | 0/8 (wave 8) | 0/8 (wave 6-8) | 0/8 (wave 6-7) |
| spam-arc | 0/8 (wave 14-22) | 0/8 | 0/8 |
| maze without IDS | 0/8 (wave 14-29) | 0/8 | 0/8 |
| lazy | dies wave 8-9 | wave 3-4 | wave 6 |
Its findings: IDS mandatory and sufficient; the maze a near-guaranteed win; no-maze too viable on `open`; the economy snowballed
(about 280 credits unspent at wave 30 and ~60 IDS per game) while the early game was tight. This pass answered them with the
credit cut, the sniper role for the IDS and better Mortar / Arc / Filter value; the wall rule was ruled out by the user.