Sub topic 8
Predictability, surprise and the limits of analysis
This chapter assumes you have read the earlier chapters on local interaction and Conway's Game of Life. You should be comfortable with Python sets, loops and functions, and with the idea of a game advancing in discrete ticks.
Deterministic does not mean predictable
Conway's Game of Life contains no randomness. Given the same starting cells, it produces the same result every time. Even so, nobody can look at a starting pattern and say what it will look like after a thousand generations without running it.
This is the central tension in designing for emergence. Your rules are fully known to you, because you wrote them. Your game's behavior is still not fully known to you. Both statements are true at once, and the gap between them is where emergent gameplay comes from. It is also where surprising bugs come from.
Three words are easy to confuse here:
- Deterministic means the same input always gives the same output.
- Predictable means a person can know the output without doing all the work of computing it.
- Random means the output depends on a source of chance outside the rules.
A system can be deterministic and unpredictable, as Life is. A system can also be random and still very predictable in aggregate. A coin flipped ten thousand times gives about 5,000 heads.
Three sources of unpredictability
Designers often say "it's unpredictable" without saying why. The reason matters, because each one calls for a different response.
| Source | What it means | Example | Typical response |
|---|---|---|---|
| Random input | The rules use dice, shuffled decks or procedural seeds | Loot drops, card draws | Reason about distributions and averages |
| Sensitivity | A tiny change in the starting state produces a large change later | One extra cell in Life, one unit moved a tile earlier | Test many starting states and don't trust one run |
| Irreducibility | No formula or shortcut is known that beats running the simulation step by step | Long-term behavior of a Life pattern | Simulate, and accept that you can't skip ahead |
Sensitivity and irreducibility often appear together, but they are different. Sensitivity says that small causes can have big effects. Irreducibility says that even with perfect knowledge of the start, the only way to learn the future is to run it.
What Life tells us about the limits
Life is Turing complete. A Turing-complete system can, given enough space and time, carry out any computation a general-purpose computer can. People have built logic gates, memory and even a working Life simulator inside Life, using gliders as signals.
This has a sharp consequence. The halting problem is the question "will this program ever stop?". It is proven impossible to answer for all programs. Because Life can embed arbitrary programs, questions such as "will this pattern ever die out?" or "will it grow forever?" cannot be answered by any single algorithm that works for every starting pattern. For specific patterns you can often answer by running them. There is no general shortcut.
You don't need to build computers in your game for this to matter. The practical lesson is that once a rule set has enough expressive power, there is no complete analysis, and you should plan your process around that.
The history of the R-pentomino shows this. It is a five-cell pattern. John Conway and others found that it evolves in a messy way for 1,103 generations before settling into stable blocks, oscillators and gliders that fly away. Nobody predicted that from the five cells. It was found by running it.
Experiment: measuring sensitivity
You can measure sensitivity directly. Run two copies of a world that differ by one cell, and track how many cells differ between them over time.
from collections import Counter
def life_step(live):
"""Advance Conway's Game of Life one generation.
live is a set of (x, y) cells that are alive."""
counts = Counter(
(x + dx, y + dy)
for (x, y) in live
for dx in (-1, 0, 1)
for dy in (-1, 0, 1)
if (dx, dy) != (0, 0)
)
return {
cell
for cell, n in counts.items()
if n == 3 or (n == 2 and cell in live)
}
def divergence(a, b, generations, report_at):
"""Print how many cells differ between two worlds as they evolve."""
for g in range(generations + 1):
if g in report_at:
print(f"generation {g:4d}: {len(a ^ b):4d} cells differ")
a, b = life_step(a), life_step(b)
r_pentomino = {(1, 0), (2, 0), (0, 1), (1, 1), (1, 2)}
tweaked = r_pentomino ^ {(2, 2)} # add one extra live cell
divergence(r_pentomino, tweaked, 200, {0, 10, 50, 100, 200})The ^ operator on sets is the symmetric difference: cells alive in exactly one of the two worlds. At generation 0 the count is 1. What you should watch for is how the count behaves afterward. For many starting patterns, the two worlds drift apart and the difference becomes large. For a few, such as a lone block, a one-cell change gets absorbed or stays small. Try several tweaked cells and different base patterns, and compare.
The result is a number you could not have worked out on paper. That is the point. Measurement replaces prediction.
Choosing an analysis method
When you face a question about your game's behavior, pick the method by the kind of question. The diagram shows a rough decision path.
What you can still analyze
Limits on prediction do not mean you can say nothing. Three kinds of claims remain available.
Invariants. An invariant is something that is true after every step no matter what. In the fire example from earlier, a tile that is water never becomes fire, because water is not in FLAMMABLE. You can state and test this without simulating anything. Invariants are your strongest tool, because they hold for every possible play. Examples are "the player always has at least one legal move", "total gold never goes negative", and "every unit has a way to leave a stuck position".
Bounds. You often cannot say what a value will be, but you can say it stays within limits. If income is base + interest * gold, you can reason about its growth rate even if you can't predict one match.
Distributions. You can run the system many times and describe what usually happens. This is the most useful approach for tuning, which a later chapter covers.
Here is a sampling example. It asks how likely fire is to cross a field of randomly placed grass, where a tile is grass with probability p.
import random
def burns_through(width, height, p, rng):
"""Ignite the left column of a random grass field.
Return True if fire reaches the right column."""
grass = [[rng.random() < p for _ in range(width)] for _ in range(height)]
frontier = [(0, y) for y in range(height) if grass[y][0]]
burned = set(frontier)
while frontier:
x, y = frontier.pop()
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nx, ny = x + dx, y + dy
if (0 <= nx < width and 0 <= ny < height
and grass[ny][nx] and (nx, ny) not in burned):
burned.add((nx, ny))
frontier.append((nx, ny))
return any(x == width - 1 for x, _ in burned)
rng = random.Random(42)
trials = 200
for p in (0.45, 0.55, 0.60, 0.65, 0.75):
hits = sum(burns_through(40, 40, p, rng) for _ in range(trials))
print(f"grass density {p:.2f}: fire crosses in {hits / trials:.0%} of runs")A single run tells you almost nothing, since it could go either way. The table of results tells you a lot. Fire rarely crosses at low density and nearly always crosses at high density. The change between the two is sharp, in the neighborhood of 0.59 for large grids. This is a known result from percolation theory, and it matches what a designer would want to know. A small change in how much grass you place can change the character of a level from "fire is a nuisance" to "fire is an inevitable disaster". You found that by sampling, not by reasoning from the rules.
Surprise as a design goal
Surprise is the thing you are trying to produce. A player who sets a grass field on fire and watches it cross a river by way of a wooden bridge has been surprised in a pleasing way. The surprise worked because the player can look back and explain it: grass burns, wood burns, the bridge was wood.
That points to a useful distinction:
- Explainable surprise. The outcome was not expected, but once it happens the player can trace it to rules they already knew. This builds mastery and feels fair.
- Inexplicable surprise. The outcome cannot be traced to anything visible. It feels like a bug or like arbitrary luck, even if it is perfectly deterministic.
Your analysis limits make it hard to prevent all inexplicable surprise by thinking alone. Two practices help. Keep rules few and consistent, so any outcome has a short explanation. Make rule effects visible, with burning animations, status icons and logs, so the player can see the chain of cause.
Common errors
- Trusting a mental simulation. Designers often convince themselves a rule combination "can't" lead to something. When the rules interact through shared state, your intuition covers only a few steps. Run it.
- Testing one run. In a sensitive system, one run is an anecdote. Test many starting states.
- Confusing randomness with emergence. Adding dice makes outcomes uncertain, but it does not create new kinds of situations. Emergence comes from rule interaction, so a game can be fully deterministic and richly emergent.
- Treating "unpredictable" as "unfixable". Unpredictable dynamics can still be constrained with invariants and bounds. You can't predict every match, but you can guarantee no match ends in a state you consider broken.
- Using a seed as a safety net. A fixed seed makes a bug reproducible, and that is all it does. It doesn't show that the bug is rare.
Looking ahead
If full prediction is impossible, the design process has to include measurement. The next chapters on exploits, tuning and playtesting follow from this. They all deal with ways to learn what your rules do after you have written them.
Exercise
A designer says, "Our fire system has no randomness, so I can work out in advance exactly what every level will do." Name the flaw in this reasoning and describe one analysis method that still works.
Show answer
Deterministic does not mean predictable. When fire, terrain and other rules interact through shared state, the outcome of a long run can depend sensitively on the starting layout, and there may be no shortcut except running the simulation. The designer can still check invariants (for example, water never ignites), or sample many randomly generated levels and read the distribution of outcomes, as in the grass-density experiment.
Exercise
In the divergence experiment, you add one cell to the R-pentomino and, after 200 generations, the two worlds differ in many cells. Is that evidence that Life is random? What does it show instead?
Show answer
No. Life is fully deterministic, so the same two starting states always give the same two results. The large difference shows sensitivity to initial conditions: a tiny change in the starting state can lead to very different outcomes later. That is a reason to measure behavior over many starting states, not to treat the rules as chance.
Exercise
A player is surprised when a lit torch ignites a wooden bridge and cuts off their retreat. Is this surprise explainable or inexplicable? Give one thing the designer can do to keep it explainable.
Show answer
It is explainable if the player knew that torches carry fire and that wood is flammable, because the outcome follows from known rules. The designer can keep it explainable by making those properties visible, for example by showing a flame effect on the torch and a visible wood texture or flammability marker on the bridge.