Sub topic 12
Principles for Designing for Emergence
This chapter closes the tutorial by turning the earlier chapters into working principles. It assumes you can read short Python programs and that you know the ideas from the earlier chapters: local rules acting on shared state, tags, feedback loops, exploits, tuning and playtesting. It adds no new mechanisms. Its job is to give you a set of decisions to make, in order, when you design a system and want interesting behavior you did not script.
The goal: behavior you can't point to in the rules
Emergent gameplay is behavior that no single rule describes but that appears when several rules act on shared state. In the Game of Life code, nothing mentions movement, yet a glider moves. In the fire example, nothing mentions water as a firebreak, yet water stops fire.
You cannot design emergence directly. You design the rules, the state they share and the parameters that scale them. Then you observe what happens. The principles below are about making that process productive instead of chaotic.
Principle 1: Prefer few, general rules
A rule is general when it talks about a category of things instead of one named thing. "Fire ignites flammable neighbors" is general. "Fire ignites the wooden bridge in level 3" is a script.
General rules give you more situations per rule, because each rule applies wherever its condition holds. They are also easier to reason about and to test.
Check each rule you write against three questions:
- Does its condition mention a category (a tag, a state, a number range) or a specific object?
- Would it still make sense if you added ten new kinds of content?
- Can you state it in one sentence without the word "except"?
If the answers are "specific object", "no" and "no", the rule is probably a special case. Special cases are legitimate sometimes, for example for a tutorial or a boss. But each one is a place where the system stops combining and starts being authored.
Principle 2: Keep rules orthogonal and put interactions in data
Two rules are orthogonal when each changes a different aspect of the state, so the order and combination of rules do not need to be hand-managed. Heat rules change temperature. Movement rules change position. A rule that changes both is harder to combine with others.
The number of possible pairs of things grows faster than the number of things. With n tags there are n(n+1)/2 unordered pairs, including a tag with itself. Ten tags give 55 pairs. If every pair needed its own code branch, you would be writing a script. If pairs are looked up in a table of tag interactions, adding one tag adds one row of data and the code does not change.
The next script audits a tag table. It reports how many pairs have a defined interaction, and which tags take part in none.
from itertools import combinations_with_replacement
TAGS = ["fire", "water", "wood", "metal", "oil"]
# Each rule is (source_tag, target_tag, effect).
RULES = [
("fire", "wood", "ignite"),
("fire", "oil", "ignite"),
("water", "fire", "extinguish"),
("water", "oil", "spread"),
]
def audit(tags, rules):
defined = {frozenset((a, b)) for a, b, _ in rules}
pairs = list(combinations_with_replacement(tags, 2))
used = {t for a, b, _ in rules for t in (a, b)}
isolated = [t for t in tags if t not in used]
return len(defined), len(pairs), isolated
defined, total, isolated = audit(TAGS, RULES)
print(f"{defined} of {total} tag pairs have an interaction")
print("tags that interact with nothing:", isolated)The output is 4 of 15 tag pairs have an interaction and tags that interact with nothing: ['metal'].
The audit does not tell you which pairs should be defined. Most pairs should stay empty, because a dense table is hard for players to learn. It does catch the clearest design failure: a tag such as metal that no rule touches contributes nothing to emergence, however good it looks on screen.
Principle 3: Make the shared state readable by every rule
Emergence needs rules to see each other's results. If the fire rule writes to a private structure that only fire code reads, water cannot respond to it. The tile grid in the fire example works because every rule reads and writes the same grid.
Three habits help:
- Put the facts rules care about (position, tags, temperature, ownership) in one state structure, not scattered across objects.
- Compute the next state from a copy of the current one, as
tickdoes withnew = [row[:] for row in grid]. Otherwise results depend on the order you loop over cells, and a fire could spread many tiles in one step. - Prefer rules that react to state over rules that trigger other rules directly. State-driven rules combine freely. Rule-calls-rule chains are scripts in disguise.
Principle 4: Audit feedback loops on purpose
Feedback loops decide whether a match drifts toward one winner or stays open. A positive loop amplifies differences. A negative loop reduces them. Every economy, combat or territory system contains some of each, whether or not you meant it.
A useful test is to find the quantity that is fed back and ask whether a lead in it grows or shrinks. In the income function from earlier in this tutorial, the gap between leader and trailer is multiplied each turn by a factor of 1 + interest - catch_up. When catch_up is larger than interest, leads shrink. When it is smaller, they grow.
This script checks that by simulation.
def income(gold, leader_gold, base=10, interest=0.05, catch_up=0.1):
return base + interest * gold + catch_up * (leader_gold - gold)
def gap_after(turns, interest, catch_up, leader=200, trailer=100):
for _ in range(turns):
leader_income = income(leader, leader, interest=interest, catch_up=catch_up)
trailer_income = income(trailer, leader, interest=interest, catch_up=catch_up)
leader += leader_income
trailer += trailer_income
return leader - trailer
print(round(gap_after(10, 0.05, 0.0), 1)) # 162.9, the lead grows
print(round(gap_after(10, 0.05, 0.1), 1)) # 59.9, the lead shrinksNeither result is automatically right. A strong catch-up term keeps matches close but can make the early game feel pointless, because leading earns nothing extra. A pure snowball makes early decisions matter a lot but ends many matches long before they finish. The principle is to choose the balance deliberately, ideally per phase of the match, instead of discovering it from complaints.
Principle 5: Assume players will find exploits, then choose a response
A system that combines rules freely will contain combinations you did not intend. Some are delightful. Some are exploits: sequences that win with little risk or skill. A degenerate strategy is one that is so dominant that it makes other choices pointless.
Sorting them takes three questions:
- Does the combination create interesting decisions, or remove them?
- Is it available to everyone, or only to players who know a trick?
- Does it break the goal of the game, or just surprise you?
You then have four responses.
| Response | When to use it | Cost |
|---|---|---|
| Keep it | It adds variety and is available to all | May need to be taught in the game |
| Add a counter | The strategy is strong but beatable with a rule that already exists | Adds a new interaction to learn |
| Change a parameter | One number makes the strategy too good | Can shift other strategies |
| Change or remove a rule | The combination removes decisions | Loses all the other combinations that rule enabled |
Prefer the options near the top of the table. Removing a rule is the most expensive response, because a general rule participates in many combinations besides the one that bothers you.
Principle 6: Tune numbers before structure, and tune with evidence
Many problems that look structural are really about magnitudes. A fire that spreads too fast, an income that snowballs, a tag that dominates: these are often a number changed by 10 or 20 percent, not a redesign.
Tune in this order:
- Change one parameter at a time, so you know which change caused which effect.
- Write down what you expect before running the change. If you are surprised, your model of the system is wrong, and that is useful to know.
- Test across the range, not at one point. Parameters often have thresholds, as the
interest - catch_upsign above shows. - Change structure (add or remove a rule) only when no value of the parameter gives the behavior you want.
Analysis only gets you so far. Systems with several interacting rules are often unpredictable by inspection, which is why the Game of Life needs to be run to see what a pattern does. Predict what you can, then watch real play.
Principle 7: Plan playtests to observe, not to confirm
Playtesting for emergence differs from testing for bugs. You want to see what players do that you did not expect, which means you must give them room to act.
- Give goals, not instructions. A tester told which tools to use can't discover a combination.
- Record what happened, not just what players said. Logs of state changes show combinations that players do not notice or mention.
- Watch for repetition. When several testers converge on the same strategy, check whether it is a good design discovery or a degenerate strategy.
- Re-run tests after each tuning change. A parameter fix for one problem can create another elsewhere.
A design loop
The principles fit together as a loop, not a one-time checklist.
Common errors
| Error | What it looks like | Fix |
|---|---|---|
| Rules that name specific objects | Each new item needs new code | Rewrite the rule against a tag or state |
| Hidden state | One rule cannot see another's result | Move the fact into shared state |
| In-place updates | Results change with loop order | Compute the next state from a copy |
| Unexamined feedback | The first lead decides every match | Find the fed-back quantity and check its sign |
| Fixing exploits by deleting rules | Variety drops along with the exploit | Try a counter or a parameter first |
| Tuning several numbers at once | Nobody knows what helped | Change one number per test |
| Testing only what you expect | No surprises found | Give goals, log state, review for repeated strategies |
Summary of the principles
- Write general rules that refer to categories, not named objects.
- Keep rules orthogonal, and store interactions in tag tables, not code branches.
- Put everything rules need to see in shared state, and update from a copy.
- Find each feedback loop and decide on purpose whether it amplifies or reduces leads.
- Expect exploits, classify them, and pick the cheapest response that works.
- Tune one parameter at a time before changing structure.
- Playtest to observe, with logs, and repeat after every change.
Exercise
A designer adds a new tag, "ice", to the tag table from this chapter. Water should freeze into ice when cold, and fire should melt ice into water. Which of Principles 1 and 2 does the designer follow if they implement this as two new rows in the rules table, and which do they break if they instead add if tile == "ice" branches to the fire code?
Show answer
Adding two rows follows both principles: the rules are general (they talk about tags) and the interactions live in data, so the code does not change. Adding if tile == "ice" branches in the fire code breaks Principle 2, because a new tag now needs code changes, and it weakens Principle 1, because the fire rule starts to name a specific thing instead of a category.
Exercise
Using the income model, you set interest to 0.08 and catch_up to 0.05. Without running code, predict whether a 100-gold lead grows or shrinks over time, and by what factor per turn. Then name one design response if testers report that matches are decided in the first five turns.
Show answer
The gap is multiplied each turn by 1 + interest - catchup = 1 + 0.08 - 0.05 = 1.03, so the lead grows by 3 percent per turn. Because the gap grows, early leads carry through to the end, which matches the tester reports. The cheapest response is to tune a parameter: raise catchup above 0.08 so the factor drops below 1, or lower interest. Raising catch_up to 0.1, for example, gives a factor of 0.98 and leads shrink. Check afterward that early decisions still matter.
Exercise
Playtest logs show that 8 of 10 testers win by building one cheap unit repeatedly and never using the other nine units. List the three questions from Principle 5 you would ask about this, and name the first response you would try.
Show answer
Ask whether the strategy creates interesting decisions or removes them (it removes them, since nine units go unused), whether it is available to everyone or only to players who know a trick (it appears available to everyone, since 8 of 10 found it), and whether it breaks the goal of the game or only surprises you (it makes most of the game's content pointless). Try a parameter change first, such as the cost or strength of the cheap unit, or add a counter using an existing rule, before removing any rule.