Sub topic 3
Mechanics: the rules and algorithms of a game
This chapter assumes you have read the overview of MDA and know what game rules and game state are. You should be able to read short Python functions. No other background is needed.
What counts as a mechanic
In MDA, mechanics are the base layer of a game. They are the components you can write down and hand to someone else: the rules, the algorithms that apply those rules, and the data those algorithms read and change. If you could put it in a rulebook, a spreadsheet, or a source file, it is a mechanic.
Mechanics have three parts.
- Rules state what players may do and what happens when they do it. "A trailing racer gets a speed bonus" is a rule.
- Algorithms are the exact procedures that carry out a rule. They say how much the bonus is and when it applies.
- Data is the state and the numbers the algorithms use. It includes the positions of the racers, the base speed, and the cap on the bonus.
A mechanic is specific and fixed. Run it twice with the same inputs and you get the same result, unless the rule itself includes chance. This is what separates mechanics from the layers above them. Dynamics and aesthetics are what you observe and feel. Mechanics are what you actually control.
A mechanic as a small algorithm
The following function is one mechanic from a racing game. It is a catch-up rule: a racer who is behind the leader gets a speed bonus that grows with the gap.
def racer_speed(base_speed, gap_behind_leader, boost_per_unit=0.05, max_boost=0.3):
"""Mechanic: a trailing racer gets a speed bonus proportional to the gap, capped at max_boost."""
gap = max(gap_behind_leader, 0.0)
boost = min(gap * boost_per_unit, max_boost)
return base_speed * (1 + boost)Read it as a designer would. The function has three kinds of content.
- A rule in code. The bonus is proportional to the gap, and the leader, whose gap is zero, gets none.
- Parameters.
boost_per_unitandmax_boostare numbers a designer can change without changing the rule's shape. - Guards.
max(gap_behind_leader, 0.0)stops a leading racer from receiving a negative gap.min(..., max_boost)stops the bonus from growing without limit.
You can check the behavior by calling the function with a few values.
print(racer_speed(10.0, 0.0)) # 10.0: the leader gets no boost
print(racer_speed(10.0, 4.0)) # 12.0: gap 4 gives a 20% boost
print(racer_speed(10.0, 100.0)) # 13.0: the boost is capped at 30%Nothing in this function says the race will be close or exciting. It only says how fast a racer moves given a gap. Whether races become close is a question about dynamics, and whether that feels tense is a question about aesthetics. Mechanics alone cannot answer either.
Rules, parameters, and structure
Designers change mechanics in two different ways, and it helps to keep them apart.
- Changing a parameter keeps the rule and alters a number. Raising
max_boostfrom 0.3 to 0.5 is a parameter change. - Changing the structure alters the rule itself. Replacing the proportional boost with a flat boost for anyone behind by more than ten units is a structural change.
Parameter changes are cheap and easy to test. Structural changes can produce a different game. Early in design you usually need structural changes to find a workable rule. Later you mostly adjust parameters.
| Kind of change | Example | Typical effect | When to use |
|---|---|---|---|
| Parameter | `boost_per_unit` from 0.05 to 0.08 | Same behavior, stronger or weaker | Tuning a rule that mostly works |
| Structure | Boost only after the gap exceeds 10 | New behavior, new edge cases | The rule cannot reach the goal by tuning |
| Addition | Add item drops weighted toward trailing racers | A second rule interacts with the first | One rule alone is not enough |
| Removal | Delete the speed boost | Often changes the game more than expected | A rule works against another rule |
Kinds of mechanics
Games contain several families of mechanics. Naming them helps you notice what you have and what is missing.
- Resolution mechanics decide outcomes: dice rolls, comparing stats, hit detection.
- Movement and position mechanics govern where things can go and how fast.
- Resource mechanics control how currency, health, or ammunition are gained, spent, and lost.
- Turn and timing mechanics set who acts when, and how long they have.
- Information mechanics decide who can see what: hidden hands, fog of war, a shared board.
- Victory and failure conditions define when the game ends and who wins.
Most games combine several of these. A card game has a resolution mechanic (compare card values), a resource mechanic (cards in hand), and an information mechanic (hidden hands). The interaction between them is where dynamics start.
Mechanics are not dynamics
The most common error at this layer is describing a dynamic as if it were a mechanic. Two statements can sound alike and still sit on different layers.
| Statement | Layer | Why |
|---|---|---|
| "Trailing racers move up to 30% faster." | Mechanic | It is a rule with a number you can set. |
| "Races stay close." | Dynamic | It describes behavior over many steps and players. |
| "Players feel tense in the final lap." | Aesthetic | It describes an emotional response. |
You can set a mechanic directly. You cannot set a dynamic directly. You can only choose mechanics and then observe what they produce. A designer who writes "races should stay close" into a design document has stated a goal. The mechanics that might achieve it still have to be proposed and tested.
Why small rule changes matter
Mechanics tend to have an effect out of proportion to their size, because they run repeatedly and interact with each other. A rule that gives a small bonus in one step can change the shape of an entire match after one hundred steps.
You can see this by running a racing rule many times. The next program simulates a two-racer race for 100 steps, once without the catch-up mechanic and once with it. It reports the number of lead changes and the final gap.
import random
def simulate_race(catch_up, steps=100, seed=1):
rng = random.Random(seed)
pos = [0.0, 0.0]
leaders = []
for _ in range(steps):
for i in range(2):
gap = max(pos[1 - i] - pos[i], 0.0)
base = rng.uniform(0.8, 1.2)
boost = min(gap * 0.05, 0.3) if catch_up else 0.0
pos[i] += base * (1 + boost)
leaders.append(0 if pos[0] > pos[1] else 1)
lead_changes = sum(1 for a, b in zip(leaders, leaders[1:]) if a != b)
return lead_changes, abs(pos[0] - pos[1])
for flag in (False, True):
print("catch_up =", flag, "->", simulate_race(flag))The program changes one mechanic, the boost, and compares two outputs. The numbers it prints are dynamics: they describe what happened over the whole run. The exact values depend on the random seed, and a single run is only one sample. To draw a conclusion you would repeat the race with many seeds and compare averages. Later chapters on tuning and simulation cover that step.
Designing mechanics well
Good mechanics share a few traits. These are working guidelines, and each has exceptions.
- Make rules precise. Ambiguous rules cause arguments in board games and bugs in video games. If two players could read a rule differently, rewrite it.
- Expose the parameters. Put tunable numbers in one place, with names. Hard-coded numbers scattered through code make tuning slow and error-prone.
- Keep rules few and interacting. A small set of rules that combine in interesting ways usually gives more variety than a long list of rules that do not touch each other.
- Guard the edges. Ask what happens at zero, at the maximum, and with a negative or missing value. The
maxandmincalls inracer_speedare examples. - Tie each mechanic to a goal. If you cannot say which dynamic a rule is meant to produce, you cannot tell whether it works.
Common errors
- Treating a rule as proven because it looks right. A rule that seems sensible on paper can have no effect, or the opposite effect, when it runs. Observe the dynamics before trusting it.
- Changing several mechanics at once. If you alter three rules and the game improves, you do not know which change helped.
- Hiding numbers inside logic. A bonus written as
* 1.15in the middle of a function is hard to find and hard to adjust. - Forgetting the players. Mechanics produce dynamics only when players act on them. A rule tested against a scripted bot may behave differently with people who adapt to it.
- Confusing a rule's intent with its effect. A catch-up rule intended to keep races close can also make leading feel pointless. That is a dynamic you did not plan.
Where mechanics fit in the chain
Mechanics are the starting point of the designer's chain. A designer states an aesthetic goal, names the dynamics that should support it, and then proposes mechanics. The following record shows the chain for the racing example.
design_chain = {
"aesthetic_goal": "challenge: close, tense races",
"target_dynamics": ["lead changes happen often", "no player is ever hopelessly behind"],
"candidate_mechanics": ["catch-up speed boost for trailing racers", "item drops weighted toward trailing racers"],
}
for layer, value in design_chain.items():
print(layer, "=", value)The last entry is the only one a programmer can implement directly. The first two are claims you must test.
The loop back from aesthetics to mechanics is the working method of design. You rarely get the rules right the first time. You change a mechanic, watch what the dynamics do, and judge the result against your goal.
Summary
Mechanics are the rules, algorithms, and data of a game. They are the only layer a designer sets directly. They can be changed by parameter or by structure, and they fall into families such as resolution, resources, and information. Their effects appear only when they run, so every mechanic is a hypothesis about a dynamic that you have to check.
Exercise
Sort each statement into mechanic, dynamic, or aesthetic: (a) "A player draws two cards at the start of each turn." (b) "Players hoard cards and rarely play them early." (c) "Players feel anxious about running out of cards." For (b), name one parameter change to a mechanic that might reduce the hoarding.
Show answer
(a) is a mechanic: it is a rule with a number. (b) is a dynamic: it describes behavior that appears when the rules run with players. (c) is an aesthetic: it describes an emotional response. For (b), one parameter change is to lower the hand size limit, so that hoarded cards are discarded, or to raise the number of cards drawn so that hoarding is less necessary. After the change, you would play again and check whether hoarding actually decreased.
Exercise
In racer_speed, what does the racer's speed become if gap_behind_leader is 6.0, base_speed is 10.0, boost_per_unit is 0.05, and max_boost is 0.2? Is this a parameter change or a structural change from the default version?
Show answer
The raw boost is 6.0 0.05 = 0.30, but the cap is 0.2, so the boost is 0.2 and the speed is 10.0 1.2 = 12.0. Changing max_boost from 0.3 to 0.2 is a parameter change, because the rule keeps its shape: a proportional boost with a cap.
Exercise
A designer says, "I added a catch-up mechanic, so now games are close." What is missing from this claim, and how would you test it using the simulation in this chapter?
Show answer
The claim treats a dynamic (close games) as a direct result of a mechanic, without evidence. To test it, run simulate_race for the same set of many seeds with catch_up set to False and to True. Compare the average number of lead changes and the average final gap between the two settings. If the catch-up setting does not increase lead changes or reduce the final gap, the mechanic does not produce the intended dynamic.