Sub topic 4
Rules: Defining What Is and Is Not Allowed
This chapter assumes you have read the earlier chapters on players and objectives. It also assumes you can read short Python functions and dataclasses. The code is optional, and the prose stands alone.
What a rule is
A rule is a statement that limits or enables what players can do. Rules decide which actions exist, which are forbidden, and what each action changes. A game's objective tells players what to aim for. Its rules tell them what they may do while aiming for it.
Rules belong to the formal elements because they stay the same when you change the theme. A chess set carved from glass and a chess app on a phone run under the same rules. If you rename the pieces "dragons" and "wizards" but keep the same movement and capture rules, you have the same game.
Rules versus objectives
Beginners often write an objective as a rule, or the other way around. The two have different jobs.
- An objective defines success. "Take the last stone" is an objective.
- A rule defines permitted action. "On your turn, take 1 to 3 stones" is a rule.
A useful test is to ask whether a player could break the statement in the middle of play. You can break a rule: taking four stones is an illegal move. You cannot break an objective. You can only fail to reach it.
A good objective is testable. Someone who reads the game state should be able to say whether the objective has been met, without opinion or interpretation. "Be the better strategist" is not testable. "Hold the most territory when the last tile is placed" is.
Three kinds of rules
Rules come in three kinds. Treating them as one group causes most of the confusion in rulebooks and in game analysis.
| Kind | What it does | Example |
|---|---|---|
| Constitutive | Defines what the game's objects and states are, and what counts as what | "A piece with no legal move and its king attacked is checkmated." |
| Operational | Tells players what they may and may not do, and in what order | "Take 1 to 3 stones per turn." |
| Implicit | Unwritten expectations that players follow without being told | "Don't look at another player's hand." |
Constitutive rules
Constitutive rules create the game's meaning. They say that a certain state counts as something. Checkmate, a goal, a trick won, and a bankrupt player are all defined this way. Without these rules, the physical actions have no game meaning. Moving a piece to a square is just moving a piece until a rule says it counts as a capture.
Operational rules
Operational rules are what most people mean by "the rules". They cover turn order, legal moves, costs, and limits. They are directive: do this, don't do that. Operational rules are usually the easiest to turn into code, because each one maps to a check or a state change.
Implicit rules
Implicit rules are not printed in the rulebook. Players learn them by playing. Examples are not stalling on purpose, not touching pieces without moving them (as in "touch-move" in chess clubs), and not showing hidden information. Digital games turn many implicit rules into explicit ones because the software must decide each case. A board game that relies on trust cannot be ported to a screen without writing those rules down.
Writing rules unambiguously
A rule is ambiguous if two careful readers can apply it and reach different legal states. Four habits reduce this.
- Name the actor. Write "the active player draws two cards", not "two cards are drawn".
- State the timing. Say whether an effect happens before, during, or after another event.
- Give numbers a range. "Take 1 to 3 stones" has a minimum and a maximum. "Take a few stones" has neither.
- Say what happens at the limits. What if the pile has two stones left and the rule allows up to three?
The fourth habit is where most rulebooks fail. A rule that works in the middle of a game often says nothing about the end of it. The Nim rule "take 1 to 3 stones" must still say what happens when only two remain. The answer, "take 1 to the number remaining, up to three", is the real rule.
Rules as code
Writing rules as code forces you to answer every edge case, because a program has to do something. The model below is the Nim game from the topic plan. The objective, taking the last stone, is kept separate from the rules.
from dataclasses import dataclass
PLAYERS = 2 # players: two alternating players
MAX_TAKE = 3 # rule: take 1 to 3 stones per turn
@dataclass(frozen=True)
class State:
stones: int # resource: a shared pile of stones
current: int # index of the player whose turn it is
def legal_moves(state):
return list(range(1, min(MAX_TAKE, state.stones) + 1))
def apply_move(state, take):
if take not in legal_moves(state):
raise ValueError('illegal move')
return State(state.stones - take, (state.current + 1) % PLAYERS)
def winner(state):
# objective: take the last stone
if state.stones == 0:
return (state.current - 1) % PLAYERS
return None
start = State(10, 0)
print(legal_moves(start)) # [1, 2, 3]
print(legal_moves(State(2, 1))) # [1, 2]
print(legal_moves(State(0, 1))) # []
try:
apply_move(start, 4)
except ValueError as error:
print(error) # illegal moveEach part of the code is one kind of rule:
legal_movesholds the operational rules. Themin(MAX_TAKE, state.stones)expression is the edge case: it stops a player from taking stones that are not there.apply_moveenforces those rules. It rejects any move thatlegal_movesdoes not list, and it also advances the turn. Turn order is an operational rule.winneris a constitutive rule. It says that a state with zero stones counts as a win for the player who just moved. It is also where the objective is encoded.
Notice that legal_moves(State(0, 1)) returns an empty list. The game is over, so no action exists. The rules do not need a separate "game over" check for that case, because the move list and the winner check agree.
Making the rules a parameter
When rules are hard-coded constants, you cannot compare variants. Moving them into a small object lets you change one rule and observe the effect.
from dataclasses import dataclass
@dataclass(frozen=True)
class Rules:
max_take: int = 3
players: int = 2
@dataclass(frozen=True)
class State:
stones: int
current: int
def legal_moves(state, rules):
return list(range(1, min(rules.max_take, state.stones) + 1))
def apply_move(state, take, rules):
if take not in legal_moves(state, rules):
raise ValueError('illegal move')
return State(state.stones - take, (state.current + 1) % rules.players)
def play(stones, rules, choose):
state = State(stones, 0)
while state.stones > 0:
state = apply_move(state, choose(state, rules), rules)
return (state.current - 1) % rules.players
def leave_multiple(state, rules):
take = state.stones % (rules.max_take + 1)
return take if take else 1
print(play(10, Rules(max_take=3), leave_multiple)) # 0
print(play(10, Rules(max_take=4), leave_multiple)) # 1The same strategy and the same starting pile give a different winner when one number changes. With max_take=3, the first player takes 2 and leaves 8, a multiple of 4. With max_take=4, a pile of 10 leaves the first player no way to reach a multiple of 5, so the second player wins. A one-number change to one rule changed who the game favors.
Rule changes versus objective changes
The earlier chapter on objectives showed a misère variant of Nim, where taking the last stone loses. Compare that with the change above:
| Change | Element changed | Effect |
|---|---|---|
| `max_take` from 3 to 4 | Rule | Same goal, different safe pile sizes |
| Last stone wins to last stone loses | Objective | Same moves, different good choices |
Both changes alter which move is best, but they do it differently. A rule change reshapes the set of available moves. An objective change keeps the set and reshapes how each move is valued. When you analyze a game, ask which element you touched. That tells you where to look for side effects.
Common errors and edge cases
- Rules that conflict. Two rules can demand opposite things in the same state, such as "you must attack" and "you cannot attack on the first turn". Good rulebooks state a precedence, for example "a card's text overrides the general rulebook".
- Rules with no limit case. The two-stones example above is typical. Check every rule against the smallest and largest values of each resource.
- Hidden rules. If your analysis of a game ignores the implicit rules, your model will allow moves that real players never make. Add them to the model if they affect play.
- Rules that act as objectives. "You must take at least one stone" looks like a goal but is a rule: it forbids passing. Passing would break the game's progress, so the rule exists to guarantee the game ends.
- House rules. Players often change rules without noticing. When two groups disagree about a game, compare their rules before blaming strategy.
Summary
Rules define what is and is not allowed. Separate them from the objective, which defines success. Classify each rule as constitutive, operational, or implicit. Write them with a named actor, a timing, a numeric range, and a defined limit case. Writing them as code exposes gaps, and parameterizing them shows how one rule change shifts the whole game.
Exercise
In the parameterized Nim code, a designer adds the sentence "A player may not take the same number of stones their opponent took on the previous turn." Classify this as constitutive, operational, or implicit, and name one edge case the sentence leaves undefined.
Show answer
It is an operational rule, because it restricts which moves a player may make. The sentence does not define the first turn, when there is no previous move. It also does not say what happens when the only legal take equals the opponent's last take (for example, one stone remains and the opponent just took one). The designer must decide whether that player passes, loses, or is excused from the restriction.
Exercise
A group changes Nim so that the player who takes the last stone loses, and also lowers the limit to 2 stones per turn. Which changes are to rules and which are to the objective? Why is it harder to predict the effect of changing both at once?
Show answer
Taking the last stone now loses is an objective change. Lowering the limit from 3 to 2 is a rule change. Each change alters which moves are good through a different mechanism: the rule change reshapes the set of legal moves, and the objective change reshapes how each result is valued. Changing both together means you cannot attribute a shift in strategy to either one, so test them one at a time.