Sub topic 6
Procedures: the Actions Players Can Take
Assume you understand basic game design terms and can read simple Python. This chapter focuses on procedures: the ordered actions that let players operate within a game's rules.
What a procedure is
A procedure is a defined sequence of actions that changes the game state. The game state is the information that describes the current situation, such as whose turn it is, how many stones remain, or which cards are in play.
Procedures answer questions such as:
- Who acts now?
- What choices are available?
- What information can the acting player use?
- What changes after the action?
- Who acts next?
- When does the procedure stop?
A rule says what is allowed or required. A procedure explains how play moves from one state to another. An objective says what players are trying to achieve.
For example, in a game of Nim:
- The objective is to take the last stone.
- The rule allows a player to take one to three stones.
- The procedure gives the player a turn, checks the chosen amount, removes the stones, and passes the turn.
Modeling actions as state transitions
A useful working model is:
current state + chosen action → next state
An action is legal only when it satisfies the current rules. The procedure should reject an illegal action instead of silently repairing it. Silent repairs hide design errors and make testing difficult.
from dataclasses import dataclass
MAX_TAKE = 3
PLAYER_COUNT = 2
@dataclass(frozen=True)
class State:
stones: int
current_player: int
def legal_actions(state):
return list(range(1, min(MAX_TAKE, state.stones) + 1))
def apply_action(state, take):
if take not in legal_actions(state):
raise ValueError("That action is not legal.")
return State(
stones=state.stones - take,
current_player=(state.current_player + 1) % PLAYER_COUNT,
)
def play_one_turn(state, take):
next_state = apply_action(state, take)
if next_state.stones == 0:
winner = state.current_player
return next_state, winner
return next_state, None
state = State(stones=10, current_player=0)
print("Legal actions:", legal_actions(state))
state, winner = play_one_turn(state, 3)
print("Remaining stones:", state.stones)
print("Next player:", state.current_player)
print("Winner:", winner)The legal_actions procedure exposes the player's action space: the set of choices available in a particular state. The action space changes as the state changes. With two stones remaining, a player cannot choose three.
Sequencing and atomic actions
A turn often contains several smaller steps. A card game turn might be:
- Untap or refresh pieces.
- Draw a card.
- Take one or more actions.
- Resolve effects.
- Check for a winning condition.
- End the turn.
The order matters. Drawing before choosing an action produces different decisions from drawing afterward. Each step should have a clear trigger and result.
An atomic action is treated as one complete operation. In Nim, removing stones and passing the turn belong to the same successful move. If the game passes the turn before removing the stones, another procedure could observe an impossible intermediate state.
| Procedure part | Design question | Nim example |
|---|---|---|
| Input state | What must already be true? | At least one stone remains |
| Choice | What can the player select? | Take one to three stones |
| Validation | What makes the choice legal? | The amount cannot exceed the pile |
| Effect | What changes? | Stones are removed |
| Continuation | What happens next? | The other player acts |
Procedures and player experience
Procedures shape the decisions players actually make. A rule may permit many actions, but a procedure can constrain when those actions appear. A player might have a powerful ability, yet need to spend a resource before using it or wait until a particular phase.
When designing a procedure, check for:
- Clarity: Can players tell what step comes next?
- Agency: Does the player make a meaningful choice?
- Pacing: Does the procedure create useful rhythm or unnecessary waiting?
- Reversibility: Can an accidental action be undone?
- Termination: Does the sequence always reach an ending?
Analyzing and changing procedures
To analyze a procedure, record its inputs, legal choices, state changes, and stopping conditions. Then change one part and predict the consequences.
Suppose Nim allows a player to take one to five stones instead of one to three. The resource decreases faster, the action space becomes larger, and the winning strategy changes. The objective did not change, but the procedure changed the available decisions and therefore the game's strategic structure.
Exercise
In the Nim example, what should the procedure do if a player chooses to take four stones while six stones remain and MAX_TAKE is 3?
Show answer
It should reject the action with an error and leave the state unchanged. The action is outside the legal action space.