Sub topic 3
Mechanics: The Rules and Algorithms of a Game
Assume you already understand basic game rules and game state. You can treat a game as a system whose state changes when players act, time passes, or random events occur. Optional Python experience will help with the examples, but the ideas apply to board, card, tabletop, and video games.
What mechanics are
In the MDA framework, mechanics are the rules, algorithms, data, and tools that define what a game can do. They include both player-facing rules and hidden implementation details.
A mechanic answers questions such as:
- What actions are available?
- What conditions allow or prevent an action?
- How are rewards, penalties, and resources calculated?
- How does the game resolve conflict?
- What information is visible or hidden?
- How does randomness work?
- How does the game state change after an action?
For example, “a player may move one space per turn” is a rule. “A character gains 10 experience points after defeating an enemy” is a reward calculation. “The trailing racer receives a capped speed bonus” is an algorithm.
Mechanics are easier to tune when their important parameters are explicit:
| Mechanic | Parameters | State it changes |
|---|---|---|
| Movement | speed, movement points, terrain cost | position, remaining movement |
| Combat | attack, defense, damage formula | health, status effects |
| Trading | prices, inventory limits, transaction rules | currency, items |
| Catch-up boost | gap, boost rate, maximum boost | racer position |
A mechanic is not the same as its result during play. The rule “draw a card” is a mechanic. The changing card advantage, risk, and player decisions that result are dynamics.
Rules, algorithms, and data
A complete mechanic usually has three parts:
- Rules define legal actions and outcomes.
- Algorithms calculate outcomes from inputs.
- Data stores the values needed by those calculations.
Suppose a racing game gives a slower racer a temporary speed increase. The rule says when the bonus applies. The algorithm calculates its size. The data stores the base speed and tuning parameters.
def racer_speed(base_speed, gap_behind_leader,
boost_per_unit=0.05, max_boost=0.3):
"""Return speed after applying a capped catch-up bonus."""
gap = max(gap_behind_leader, 0.0)
boost = min(gap * boost_per_unit, max_boost)
return base_speed * (1 + boost)
print(racer_speed(10.0, 2.0))This function makes several design decisions visible:
- A negative gap is treated as zero.
- The bonus grows with the gap.
- The bonus cannot exceed 30 percent.
- The bonus changes speed rather than directly changing position.
Making these choices explicit helps you test and revise the mechanic. It also prevents an unclear rule from being hidden inside unrelated code.
Mechanics as state transitions
You can model a mechanic as a state transition:
- Read the current state.
- Accept or reject an action.
- Apply rules and calculations.
- Produce a new state.
- Report the result to the player.
For a combat action, the state may contain health, armor, position, cooldowns, and inventory. The action may be “attack.” The mechanic checks range and cooldown, calculates damage, subtracts health, and records an event.
This model exposes edge cases. What happens if the player has no movement points? What if damage reduces health below zero? What if two players act at the same time? Good mechanics specify these cases instead of leaving them to accidental behavior.
Designing mechanics from a goal
A designer normally starts with an intended experience, then proposes mechanics that might support it. At this layer, keep the goal visible but evaluate the rule itself:
- Identify the state the mechanic reads.
- Identify the state it changes.
- List its parameters.
- Define legal and illegal inputs.
- Predict likely side effects.
- Decide how players learn and perceive the result.
For example, a catch-up mechanic may support close races, but its parameters determine whether it creates fair competition, removes the value of skill, or barely matters. The mechanic is the proposal. Its behavior during play must be checked separately through playtests or simulation.
Exercise
A card game lets a player draw two cards instead of one when they have fewer than three cards. Which parts are the rule, the condition, and the changed state?
Show answer
The rule is “draw two cards.” The condition is having fewer than three cards. The changed state is the player’s hand size and the deck’s remaining cards.