diff doc/balance.md @ 22:ad1b478fc4dc

balancing work, docs and scripts
author ark
date 2026-10-20 03:08 +0200
parents c1c7e4f54bf6
children 2f555a54c332
line wrap: on
line diff
--- a/doc/balance.md	Tue Oct 20 00:44:02 2026 +0200
+++ b/doc/balance.md	Tue Oct 20 03:08:56 2026 +0200
@@ -55,12 +55,13 @@
 | m2      | 15 | 3     | 45    | as above |
 | m3      | 20 | 4     | 40    | as above |
 | m4      | 30 | 6     | 35    | as above |
-| b0      | 30 | 30    | 25    | as above |
-| b1      | 50 | 50    | 25    | as above |
-| b2      | 70 | 70    | 25    | as above |
-| b3      | 100 | 100  | 25    | as above |
+| b0      | 150 | 30   | 25    | hp: decided, 5 x the notes; coins: notes; speed: guess |
+| b1      | 250 | 50   | 25    | as above |
+| b2      | 350 | 70   | 25    | as above |
+| b3      | 500 | 100  | 25    | as above |
 
-regular monsters drop 0.2 coins per hp; bosses drop 1 coin per hp (derived).
+monsters and bosses drop 0.2 coins per hp (derived). the notes gave bosses
+hp equal to their coins; balancing raised it to 5 times that (decided).
 
 time to walk the whole path at 35-45 speed (derived): map0 about 50 s, map3
 about 23 s.
@@ -201,7 +202,7 @@
 | largest gap between footprint and road edge | 14   | guess  |
 | space between footprint and spawn point    | per map: 50 | decided |
 | space between footprint and exit point     | per map: 40 | decided |
-| smallest distance between tower centres    | 32    | derived (two footprints) |
+| smallest distance between tower centres    | 40    | decided (was 32, two footprints; towers stood too close together) |
 | distance from the map edge                 | 16    | guess  |
 | snap radius, how far a tap may be from a legal position | 48 | guess |
 | placement grid cell                        | 4     | guess  |
@@ -307,3 +308,112 @@
 | parameter  | value  | source |
 |------------|--------|--------|
 | game speeds | 1x, 2x, 4x | decided |
+
+
+balancing
+---------
+
+the values above were set without a way to estimate their effect, and the
+game is far too easy. two t1 towers win every map, t2 is never needed, and
+many coins are left over when a map is won. the aim is a game where the
+player has to think about where to place towers and which ones to build. a
+player who only buys plain firepower should need nearly every coin a map
+pays in order to win it. coins left over then come from better choices.
+
+two scripted players mark the range (decided):
+
+- naive: builds t1 only, on placement cells of median coverage, whenever it
+  can afford one. it should win with about 5 of its 10 hearts left and with
+  next to no coins at the start of the last wave
+- greedy: builds on the best cells, and upgrades when no good cell is left.
+  it should win with coins to spare
+
+rules for changing values:
+
+- shop prices and starting coins stay multiples of 5. round upgrade prices
+  are preferred
+- values the player does not see are free: hp, damage, coin drops, speeds,
+  attack times
+- shop prices are set first. hp, damage and the wave mix are then fitted to
+  them
+- the main control is coins per hp. regular monsters drop 0.2 coins per hp,
+  so a map's difficulty and its income grow together. a map gets harder when
+  its hp go up while its coins stay the same
+
+the coins of the last wave, the boss's included, arrive when the map is as
+good as won. leftover coins are therefore measured at the start of the last
+wave. the last wave's coins are left out of the calculation. the boss keeps
+its drop as a visible reward (decided).
+
+the calculation goes wave by wave, not per map. at the start of each wave
+the player has the starting coins, the coins dropped in earlier waves and
+any early start bonus. these coins buy a certain amount of firepower. the
+wave sets two demands on it:
+
+- throughput: the towers' damage per second has to keep up with the hp
+  arriving per second. the time a monster spends in range gives some buffer
+- single target: the toughest monster of the wave, m4 or the boss, has to
+  die within its time in range
+
+damage is counted in whole shots. t1 at level 1 needs 2 shots for the 5 hp
+of an m0, not five thirds of one.
+
+simplifications in tools/balance.py:
+
+- a tower attacks from the first monster of a wave reaching it until the
+  last has passed. it is idle when no monster is in range. with route
+  length c in range and spacing s between monsters, the share of time with
+  a monster in range is taken as 1 - e^(-c/s)
+- for the single target demand the monster gets every tower's full
+  attention while in range. in the game, faster monsters overtake the
+  boss and draw fire away from it
+- the naive player builds at the start of a wave with the coins on hand
+  and never starts a wave early. the greedy player always starts early and
+  takes the bonus. coins dropped during a wave count from the next wave
+- monsters that leak cost one heart each and drop no coins, so a leaky
+  wave leaves less for the next one
+- routes are equally likely; the route preference is left out. the boss
+  takes the shortest route
+- towers keep their level 1 range when upgraded
+
+the time a monster spends in range comes from coverage: the length of route
+within a tower's range, measured for every legal placement cell from the
+build's route and placement data. the median cell stands for the naive
+player and the best cells for the greedy one. for more than one tower,
+cells are picked one after the other, each counting only route that no
+earlier tower covers. maps with several routes are measured per route.
+
+t1 coverage at range 100 and footprint radius 16, in map pixels of route
+within range, the mean over routes on maps with several. top 10 % is the
+coverage the best tenth of the cells reach:
+
+| map  | routes | legal cells | best | top 10 % | median |
+|------|--------|-------------|------|----------|--------|
+| map0 | 1      | 2893        | 415  | 360      | 228    |
+| map1 | 3      | 2132        | 325  | 232      | 129    |
+| map2 | 6      | 1857        | 276  | 195      | 111    |
+| map3 | 1      | 1369        | 422  | 311      | 174    |
+
+route lengths: map0 2068, map1 737 to 1048, map2 722 to 1363, map3 1035.
+
+value per coin is damage per second divided by all coins paid for the
+tower. for t1 it falls with level: 0.43, 0.38, 0.31, 0.26 and 0.22. this
+is the intended trade between upgrading and building another tower. t0 at
+level 1 reaches 0.67 against a single target, kills an m0 in one hit and
+damages every monster in range. it may be the better buy for a naive
+player than t1, so the calculation lists value per coin for every tower and
+level, area damage included.
+
+t2 works as a time multiplier. a slow to 0.6 of the speed gives 1.67 times
+the time in range for every tower covering the same stretch. this only
+helps against the single target demand, so t2 needs faster monsters or
+tough monsters spaced apart to pay off. it is tuned after the t1 baseline.
+
+order of work (decided):
+
+1. the calculation, tools/balance.py (architecture.md): value per coin for
+   every tower, the wave demands against t1 only
+2. shop prices fixed, then hp, damage and waves fitted to them
+3. t2 after the t1 baseline
+4. a headless simulation of the real game code with the two scripted
+   players confirms the result