view 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 source

balance
-------

all game numbers in one place. the values used by the game are in the config
file (see architecture.md); this document explains them and records where each
one comes from.

source markers:

- notes: from the original design notes or the original drawing sheet,
  decided
- decided: decided after the notes were written
- guess: a starting value for playtesting, expected to change
- derived: calculated from other values

notes and decided values are not fixed either. they come from the original
drawing sheet and the first design rounds, made without experience in game
design, and are all open to change in balancing.

units: distances are in map pixels, that is pixels of the map image as
scanned. times are in seconds, speeds in map pixels per second.


scale
-----

| item                         | value | source |
|------------------------------|-------|--------|
| map images                   | 1.0   | notes  |
| towers, monsters, projectiles | 0.25 | notes ("maps scaled approx 400%") |
| coins                        | 0.4   | guess, 0.25 makes them about 10 pixels |
| hp bars                      | 0.25  | guess  |

measured from the earlier masks, which covered the whole road (approximate,
from red area divided by path width):

| map  | size    | path width | path length, all branches |
|------|---------|------------|---------------------------|
| map0 | 705x697 | 56         | 1930 |
| map1 | 663x590 | 48         | 1350 |
| map2 | 618x537 | 42         | 2075 |
| map3 | 642x459 | 52         | 905  |

a single route on map1 or map2 is shorter than the total. exact route lengths
come from the build (see architecture.md).


monsters
--------

| monster | hp | coins | speed | source |
|---------|----|-------|-------|--------|
| m0      | 5  | 1     | 35    | hp, coins: notes; speed: guess |
| m1      | 10 | 2     | 40    | as above |
| m2      | 15 | 3     | 45    | as above |
| m3      | 20 | 4     | 40    | as above |
| m4      | 30 | 6     | 35    | 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 |

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.

animation (all guesses):

- one hop takes 0.35 s
- hop height 5
- squash on landing 6 % (wider and flatter), stretch in the air 4 %
- idle bob 2 %
- each monster starts at a random point in its hop cycle, so a group does not
  hop in step
- the death puff shows for 0.4 s

variation between monsters, so a group does not walk in single file (all
guesses):

- each monster's speed differs from its table speed by up to 5 % either way.
  faster ones overtake slower ones
- a monster walks beside the centre line of the road, at most 0.45 of the
  road half width away from it: 8.6, 7.7, 7.2 and 9.9 pixels by map
- half of that is a fixed lean to one side, chosen at spawn. the other half
  wanders, with a new random value every 40 pixels along the route and a
  smooth change between them
- the offset grows from 0 over the first 20 pixels of the route
- on the inside of tight bends the offset is reduced, so a monster never moves
  backwards. monsters may bunch up there


route preference
----------------

on maps with several routes, a monster picks one at spawn. faster monsters
prefer longer or straighter routes, slower ones prefer shortcuts (decided).

proposed rule (guess):

- for each route the build calculates its length and how much it turns (sum of
  direction changes along the route)
- each route gets a value between 0 and 1: the average of its length relative
  to the longest route and its straightness relative to the straightest route
- each monster gets a speed factor: its speed minus the reference speed,
  divided by the reference speed, limited to -1..1
- route weight = 1 + bias * speed factor * (2 * route value - 1), at least 0.1
- a monster at the reference speed sees all routes as equally likely
- a boss always takes the shortest route (decided). a route with a fixed
  weight of 0 is left out

| parameter       | value | source |
|-----------------|-------|--------|
| reference speed | 40    | guess  |
| bias            | 3     | guess  |

with the speeds above, m2 is the only regular monster faster than the
reference, and the effect on it is small. the speeds may need to spread out
more for the preference to be visible.


towers
------

towers have 5 levels (decided). the config sets damage, range, slow and cost
for level 1 and level 5 only. the build fills in the levels between in equal
steps, rounded to whole numbers where both ends are whole.

the drawing sheet gives five damage values for t0 and t1, and four for t2 and
t3. level 5 of t2 and t3 continues the trend (guess). the equal steps change
three values from the sheet: t1 level 2 from 7 to 8, t1 level 4 from 17 to 18,
and t3 level 2 from 5 to 4 (decided).

| tower | damage by level  | cost | range by level      | attack every | projectile speed | source |
|-------|------------------|------|---------------------|--------------|------------------|--------|
| t0    | 5,10,15,20,25    | 5    | 60,63,66,69,72      | 1.5 s        | none (melee)     | damage, cost: notes; range level 1: decided (was 45); rest: guess |
| t1    | 3,8,13,18,23     | 10   | 100,104,108,112,116 | 0.7 s        | 300              | damage levels 1 and 5, cost: notes; range: guess |
| t2    | 1,3,5,7,9        | 20   | 90,94,98,102,106    | 1.2 s        | 220              | damage level 1, cost: notes; rest: guess |
| t3    | 1,4,7,10,13      | 25   | 220,230,240,250,260 | 1.3 s        | 800              | damage level 1: notes; cost: decided (was 40), may go lower; rest: guess |

the cost column is the build cost, level 1.

rules:

- attack speed stays the same at every level (decided). t0 is slower than the
  others (decided), t1 faster than t2, t2 faster than t3 (notes)
- range grows about 4 % per level (decided "slightly", amount guessed)
- t0 damages every monster in range at once, each attack
- t2 slow: hit monsters move at 0.60, 0.55, 0.50, 0.45, 0.40 of their speed
  by level, for 2 s (guess). a new hit restarts the time. slows do not add up;
  the strongest one applies
- p1, p2, p3 home in on their target. if the target dies first, the
  projectile flies on to the last position and disappears (guess)
- towers aim at the monster furthest along its route (guess)

costs: the price of building, or of the upgrade to a level. they started as
level n costs base cost x n (decided); the config sets levels 1 and 5:

| tower | level 1 (build) | level 2 | level 3 | level 4 | level 5 | total |
|-------|-----------------|---------|---------|---------|---------|-------|
| t0    | 5               | 10      | 15      | 20      | 25      | 75    |
| t1    | 10              | 20      | 30      | 40      | 50      | 150   |
| t2    | 20              | 40      | 60      | 80      | 100     | 300   |
| t3    | 25              | 50      | 75      | 100     | 125     | 375   |

selling refunds half of everything paid for the tower, build and upgrades,
rounded down (decided). a tower is sold whole.

| tower | level 1 | level 2 | level 3 | level 4 | level 5 |
|-------|---------|---------|---------|---------|---------|
| t0    | 2       | 7       | 15      | 25      | 37      |
| t1    | 5       | 15      | 30      | 50      | 75      |
| t2    | 10      | 30      | 60      | 100     | 150     |
| t3    | 12      | 37      | 75      | 125     | 187     |

damage per second against a single target, at the guessed attack times
(derived):

| tower | level 1 | level 2 | level 3 | level 4 | level 5 |
|-------|---------|---------|---------|---------|---------|
| t0    | 3.3     | 6.7     | 10.0    | 13.3    | 16.7    |
| t1    | 4.3     | 11.4    | 18.6    | 25.7    | 32.9    |
| t2    | 0.8     | 2.5     | 4.2     | 5.8     | 7.5     |
| t3    | 0.8     | 3.1     | 5.4     | 7.7     | 10.0    |

t3 is meant to be weaker than the other towers; its range lets it reach more
targets (decided). to keep the gap moderate, its cost went from 40 to 25 and
its attack time from 2.0 s to 1.3 s, just slower than t2 as the notes require
(decided, amount guessed). at level 1 it deals about a fifth of t1's damage per
second at two and a half times the cost. its range covers more path, roughly
three times as much on a winding map (estimate).


placement
---------

| parameter                                  | value | source |
|--------------------------------------------|-------|--------|
| tower footprint radius                     | 16    | guess  |
| road half width, centre line to road edge  | per map: 19, 17, 16, 22 | measured from the earlier masks |
| 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    | 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  |

towers may not be placed on the entrance or exit areas.

the spawn point is where the path leaves the blue entrance area. the space
between it and a tower footprint is one to one and a half times the average
tower size (decided). level 1 towers average about 36 pixels across at sprite
scale 0.25, so the space is 36 to 53 pixels.

the exit point is where the path enters the green exit area. towers keep a
somewhat smaller space from it (decided), so they do not cover the building
drawn at the exit.


economy
-------

| map  | starting coins | coins dropped in total | boss coins | regular monster coins | regular monster hp |
|------|----------------|------------------------|------------|-----------------------|--------------------|
| map0 | 10             | 100                    | 30         | 70                    | 350                |
| map1 | 20             | 200                    | 50         | 150                   | 750                |
| map2 | 40             | 400                    | 70         | 330                   | 1650               |
| map3 | 60             | 600                    | 100        | 500                   | 2500               |

starting coins and the 10 x starting coins total are from the notes; the rest
is derived. early wave bonuses come on top of this total.

the source sheet gives 50 starting coins for map3. the notes raise it to 60 to
make the step from map1 to map3 more even (10, 20, 40, 60 instead of 10, 20,
40, 50). likely to change after playtesting.

share of the regular monster coins by monster level (guess). all monster
levels appear on all maps (decided):

| map  | m0   | m1   | m2   | m3   | m4   |
|------|------|------|------|------|------|
| map0 | 40 % | 25 % | 15 % | 10 % | 10 % |
| map1 | 30 % | 25 % | 20 % | 15 % | 10 % |
| map2 | 20 % | 20 % | 20 % | 20 % | 20 % |
| map3 | 15 % | 15 % | 20 % | 25 % | 25 % |

resulting monster counts (derived, rounded):

| map  | m0 | m1 | m2 | m3 | m4 | monsters | coins |
|------|----|----|----|----|----|----------|-------|
| map0 | 28 | 9  | 4  | 2  | 1  | 44       | 72    |
| map1 | 45 | 19 | 10 | 6  | 2  | 82       | 149   |
| map2 | 66 | 33 | 22 | 16 | 11 | 148      | 328   |
| map3 | 75 | 38 | 33 | 31 | 21 | 198      | 500   |

the build prints these totals from the actual wave lists and warns when a map
is more than 5 % off its coin total.


waves
-----

| parameter                          | value               | source |
|------------------------------------|---------------------|--------|
| waves per map                      | 6, 8, 10, 12        | guess  |
| break before the first wave        | 40 s                | guess  |
| break between waves               | 25 s                | guess ("longer", decided) |
| time between spawns               | 1.0, 1.0, 0.8, 0.7 s by map | guess |
| early start bonus, coins per second left | 0.05, 0.1, 0.2, 0.3 by map | guess (starting coins / 200) |

the bonus is rounded down. if every break is skipped at once, the bonus adds
about 6, 17, 45 and 82 coins per map (derived).

suggested shape of a map's waves (guess): the coin value of wave n grows in
proportion to n, so the last wave is the largest. the boss comes in the last
wave and spawns first. later waves mix monster levels; early waves are mostly
m0 and m1.


hearts
------

| parameter               | value | source |
|-------------------------|-------|--------|
| hearts per map          | 10    | decided |
| heart cost of a monster | 1     | decided |
| heart cost of a boss    | 5     | decided |


coins in flight
---------------

| parameter                        | value | source |
|----------------------------------|-------|--------|
| flight time to the counter       | 0.7 s | guess  |
| most coin sprites for one death  | 8     | guess  |

coins are added to the counter at the moment the monster dies; the flying
coins only show it (guess). this keeps the counter correct for a player who
builds right after a kill.


controls
--------

| 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