wobblyhead hg > minor_monsters
comparison doc/balancing.md @ 36:a464bd43b76c 1.0.0
clean documentation rewrite
| author | ark |
|---|---|
| date | 2026-10-21 22:34 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 35:0d40f346059c | 36:a464bd43b76c |
|---|---|
| 1 Balancing | |
| 2 --------- | |
| 3 | |
| 4 How the game's numbers are tuned, and the two tools that help with it. | |
| 5 The numbers themselves are in config/game.toml. This document does not | |
| 6 record results; run the tools for current figures. | |
| 7 | |
| 8 | |
| 9 Aim | |
| 10 --- | |
| 11 | |
| 12 The player should have to think about where to place towers and which | |
| 13 ones to build. A player who only buys plain firepower should need nearly | |
| 14 every coin a map pays to win it. Coins left over then come from better | |
| 15 choices. | |
| 16 | |
| 17 Two scripted players mark the range: | |
| 18 | |
| 19 - Naive: builds t1 only, at level 1, on placement cells of median | |
| 20 coverage, whenever it can afford one. Never starts a wave early. It | |
| 21 should win with about half its hearts left (HEARTS_TARGET in both | |
| 22 tools) and next to no coins at the start of the last wave | |
| 23 - Greedy: builds t1 on the best cells and upgrades when that adds more | |
| 24 damage per second per coin than a new tower. Starts every wave early for | |
| 25 the bonus. It should win with coins to spare | |
| 26 | |
| 27 A boss that gets through loses the map, so a player who wins has held the | |
| 28 boss. The hearts target dates from when a boss cost 5 hearts; see | |
| 29 roadmap.md. | |
| 30 | |
| 31 Coverage of a cell is the length of route within a tower's range from it, | |
| 32 the mean over the map's routes. | |
| 33 | |
| 34 The coins of the last wave, the boss's included, arrive when the map is as | |
| 35 good as won. Leftover coins are therefore measured at the start of the | |
| 36 last wave, and the last wave's coins are left out. | |
| 37 | |
| 38 | |
| 39 Rules for changing values | |
| 40 ------------------------- | |
| 41 | |
| 42 - Shop prices and starting coins stay multiples of 5. Round upgrade | |
| 43 prices are preferred | |
| 44 - Values the player does not see are free: hit points, damage, coin | |
| 45 drops, speeds, attack times | |
| 46 - Shop prices are set first. Hit points, damage and the wave mix are then | |
| 47 fitted to them | |
| 48 - The main control is coins per hit point, set by the mix of monsters. The | |
| 49 monster m0 pays more coins per hit point than the other regular | |
| 50 monsters, so a mix with fewer m0 pays less for the same hit points | |
| 51 - Monster hit points stay the same on every map. Wave size and the mix | |
| 52 make a map harder | |
| 53 - Each wave is at least as hard as the one before, and the last wave is | |
| 54 the largest. Early waves are mostly m0 and m1; later waves mix levels | |
| 55 | |
| 56 Workflow: change config/game.toml, build, run tools/simulate.js and read | |
| 57 temp/preview/simulate.txt. The script tools/balance.py gives a faster | |
| 58 estimate and drafts wave lists. | |
| 59 | |
| 60 | |
| 61 Drafting waves | |
| 62 -------------- | |
| 63 | |
| 64 `python3 tools/balance.py --draft [MAP]` prints wave lists as TOML, to | |
| 65 paste over a map's [[map.N.wave]] lists. They are made from the draft | |
| 66 numbers in the map's section, which the game does not read: | |
| 67 | |
| 68 - wave_count: the number of waves | |
| 69 - wave_size: regular monsters in the first and in the last wave. The waves | |
| 70 between grow in equal steps | |
| 71 - monster_share: the share of each regular monster, m0 to m4, by count | |
| 72 - first_wave: the wave in which each regular monster first appears | |
| 73 | |
| 74 Each monster gets a weight per wave that grows by one per wave from its | |
| 75 first wave. The weights are scaled, in turn per wave and per monster, | |
| 76 until the wave sizes and the shares are met, then rounded to whole | |
| 77 monsters. Later waves therefore hold more of the monsters that came in | |
| 78 late. Every monster keeps at least one, and the boss goes into the last | |
| 79 wave. Below each map the tool prints what the calculation makes of the | |
| 80 draft, and warns about a wave with fewer hit points than the one before. | |
| 81 Nothing is written in this mode. The lists may be edited by hand after | |
| 82 pasting. | |
| 83 | |
| 84 | |
| 85 tools/simulate.js | |
| 86 ----------------- | |
| 87 | |
| 88 Plays the real game logic with scripted players. Run by hand with Node | |
| 89 after a build: | |
| 90 | |
| 91 node tools/simulate.js | |
| 92 node tools/simulate.js --maps 2 --players naive,naive_t0 --seeds 10 | |
| 93 | |
| 94 It loads www/data/config.js, www/data/maps.js and the logic files util.js, | |
| 95 assets.js, map.js, monster.js, tower.js, projectile.js, wave.js and | |
| 96 game.js, as the browser would. The files render.js, ui.js, input.js, | |
| 97 debug.js and main.js are left out, so the debug switches have no effect. | |
| 98 Audio is a stub. | |
| 99 | |
| 100 - The game advances in steps of 1/60 s; game speed plays no part. Each | |
| 101 seed is passed to the game, so a run can be repeated | |
| 102 - Players buy through the game's own functions (shop choice, preview, | |
| 103 build, tower selection, upgrade, early start), so placement rules and | |
| 104 prices are the game's. They buy the moment they can afford the next | |
| 105 purchase, also during a wave | |
| 106 - Players: naive and greedy as above, naive_t0 (t0 only) and naive_mix (t1 | |
| 107 and t0 in turn). The list and their rules are at the top of the file | |
| 108 - The coins a wave needs are measured by playing that wave alone from an | |
| 109 empty map, with the first purchases of the player's list, and searching | |
| 110 for the fewest that lose no heart. By default only the last wave is | |
| 111 measured; `--need all` measures every wave | |
| 112 - `--waves FILE` takes wave lists from a JSON file in place of the | |
| 113 config's, for trying drafts without a build. `--config FILE` uses | |
| 114 another config.js. `--json` prints the results as JSON and writes | |
| 115 nothing | |
| 116 | |
| 117 It writes temp/preview/simulate.txt (per map and player: maps won, hearts | |
| 118 left, coins on hand and the surplus at the start of the last wave, hearts | |
| 119 lost per wave, and monsters hit per t0 attack) and | |
| 120 temp/preview/simulate.json, which tools/balance.py reads. | |
| 121 | |
| 122 | |
| 123 tools/balance.py | |
| 124 ---------------- | |
| 125 | |
| 126 Estimates, map by map and wave by wave, whether the coins a map pays buy | |
| 127 enough firepower. It only calculates, against t1, and is much faster than | |
| 128 the simulation. Run it by hand after a build, as it reads the routes and | |
| 129 placement grid from temp/build/maps.json: | |
| 130 | |
| 131 python3 tools/balance.py | |
| 132 | |
| 133 It needs NumPy and Matplotlib, which the build does not. It writes to | |
| 134 temp/preview/: | |
| 135 | |
| 136 - balance.txt: value per coin for every tower and level; per map the | |
| 137 coverage of each tower's range, and per wave the coins on hand, the | |
| 138 damage rate the wave demands, and the coins the naive and greedy players | |
| 139 need to hold it; t0's value per coin with area damage | |
| 140 - balance_value.png: value per coin by tower level | |
| 141 - balance_map0.png to balance_map3.png: coins per wave, and the surplus at | |
| 142 the last wave and the hearts left against a wave size factor. The factor | |
| 143 scales the number of regular monsters in every wave; their coins follow | |
| 144 | |
| 145 Method: | |
| 146 | |
| 147 - At the start of each wave the player has the starting coins, the coins | |
| 148 dropped in earlier waves and, for greedy, the early start bonus. It buys | |
| 149 what it can in its order. Coins dropped during a wave count from the | |
| 150 next wave | |
| 151 - The wave sets two demands. Throughput: the towers' damage has to keep up | |
| 152 with the hit points arriving. Single target: the toughest monster of the | |
| 153 wave, m4 or the boss, has to die within its time in range | |
| 154 - Damage is counted in whole shots: a tower that needs 2 shots for a | |
| 155 monster spends 2 attacks on it | |
| 156 - A tower attacks from the first monster of a wave reaching it until the | |
| 157 last has passed, and is idle when no monster is in range. With route | |
| 158 length c in range and spacing s between monsters, the share of time with | |
| 159 a monster in range is taken as 1 - e^(-c/s) | |
| 160 - For the single target demand the monster gets every tower's full | |
| 161 attention while in range | |
| 162 - Leaked monsters cost hearts and drop no coins, so a leaky wave leaves | |
| 163 less for the next one | |
| 164 - Naive uses the median coverage of all legal cells. Greedy picks cells | |
| 165 one after the other, each counting only route that no earlier pick | |
| 166 covers. Maps with several routes are measured per route and averaged | |
| 167 - Value per coin is damage per second divided by all coins paid for the | |
| 168 tower, with whole shots against each regular monster | |
| 169 - The tower t0 hits several monsters per attack. Its value per coin is | |
| 170 multiplied by the monsters hit per attack, as measured by the simulation | |
| 171 when simulate.json exists, otherwise estimated from coverage and spacing | |
| 172 | |
| 173 Simplifications and limits: | |
| 174 | |
| 175 - Only t1 is considered for the wave demands. The tower t2 works as a time | |
| 176 multiplier (a slow to a share k of the speed gives 1/k the time in range | |
| 177 for every tower covering the same stretch), which helps only against the | |
| 178 single target demand. It is not modelled | |
| 179 - Routes are equally likely; the route preference is left out. The boss | |
| 180 takes the shortest route | |
| 181 - Towers keep their level 1 range when upgraded | |
| 182 - Towers that only slow are left out of the value per coin table | |
| 183 | |
| 184 | |
| 185 Where the tools differ | |
| 186 ---------------------- | |
| 187 | |
| 188 The two tools agree on the coins on hand at each wave. They differ in the | |
| 189 coins a wave needs, for reasons the calculation leaves out: | |
| 190 | |
| 191 - The boss needs more in the simulation: faster monsters overtake it and | |
| 192 draw fire away from it | |
| 193 - On maps with several routes, towers on median cells cover the routes | |
| 194 unevenly, and monsters on a route with little cover get through. The | |
| 195 mean over routes hides this. It shows most on map2, with six routes | |
| 196 - Some shots are lost because the target died before the projectile | |
| 197 arrived | |
| 198 - The simulated players also build during a wave, with coins from the | |
| 199 monsters killed in it | |
| 200 | |
| 201 The waves in the config were fitted with the simulation. |
