Measuring game balance with scripted bots
game-designbalancesimulationai-opponenttesting
Balance claims should be measured. Several justinahampton.com games were tuned by running batches of scripted players (a greedy bot, a random bot, a naive policy) and changing rules until the numbers said the game had decisions in it. Record the win rates when you ship, and re-measure before retuning.
Pattern
- Keep rules in a DOM-free module so a batch runner (Node, gjs, or a headless page with
?games=N) can play hundreds of games quickly. - Use at least two bots: a greedy one (shows whether a dominant strategy exists) and a random one (shows whether the game is winnable by accident). Add specialized bots for features (a trader, a quest bot that cheats the riddles) to measure what a feature is worth.
- Record results in the project notes as the regression baseline.
Findings worth reusing
- If whoever moves first can always capture, lookahead is useless. Encircle 2 (polygons capturing each other's corners): before the change, greedy first-mover won 7 of 8 in about 11 rounds. An "atari" rule (a corner is captured only if it is strictly inside the enemy at the start and end of your move, and is shown as threatened in between) made games run 26 to 33 rounds with a 6-4 / 7-3 split, and 2-ply search mattered.
- Cap growth per turn (absorb one captured corner a turn, the rest become loose seeds) so a win takes a minimum number of turns.
- Resource scarcity forces interaction: with 5 seeds the 8-corner win is unreachable without taking from the opponent; with 7 the machine won by round 7.
- Finite boards have sanctuaries. A corner on the board edge can never be strictly inside anything, and greedy play camped the edge for 20 rounds. A closing wall (inset +1 every 4 rounds from round 16) fixed it.
- Flat healing kills tension. In Recourse (a turn-based battle against customer support) a 200-game batch with a flat "breathe" heal had zero losses. Diminishing healing (
max(5, 14 - 2n)) restored them. At ship, 100 naive games: right line won 31 / hung up 69, wrong line won 20 / hung up 80. - Make costs real: Encircle's hunter gets
ceil(cells/2)steps per move you make, so long moves are the risky ones and reach becomes a genuine trade-off. - Set targets per preset. Voyages' settings presets were measured with the same bot: Gentle 98% wins, Default ~57%, Corsair 77%, Storm 27%, Debtor's Prison 13%, Merchant Prince 27% (45% with the trading bot). Random play wins about 0% (mostly starves).
- Idle animations can break rules. A guard whose look-around turned at 1.4 rad/s swung his vision cone off a target mid-meal; 0.5 rad/s fixed it (found by the harness, not by eye).
- For puzzles, measure fairness as well as difficulty: blind play-testers called long levels "trial and undo" when their only winnable line was the solution. See Generating puzzle levels with a solver (Leave a Pebble).
A machine opponent that is cheap and decent
Encircle 2's AI: score every legal move one ply deep (100 per corner difference + 0.25 x area +/- 45 per corner in atari +/- 35 per loose seed inside a shape - distance to seeds and opponent - 80 per corner about to be burned by the wall), then a 2-ply worst case over the player's replies for the top 24 moves. About 3 ms per turn; a switch drops it to 1 ply for measurement.
See also
- Test harnesses for browser canvas games and simulations
- Generating puzzle levels with a solver (Leave a Pebble)
- Arcade game design toolkit (loops, enemies, scoring, structure)