Skip to main content
A stage describes the current phase of play. It decides who can act, which commands are accepted, and which stage comes next. Create one stage factory for your state and events:

Single active player

Use a single-player stage for ordinary turns:
.activePlayer() runs whenever the engine enters the stage. .transition() runs after an accepted command. For self-references such as playerTurn, add an explicit stage type or create stages through functions that resolve references lazily.

Automatic stage

Use an automatic stage for rule work that needs no player input:
The engine runs .run() immediately, then follows .transition(). It continues through automatic stages until it reaches a stage waiting for players or an automatic stage with no transition.

Multiple active players

Use a multi-active-player stage when several players may submit independently, such as choosing a card at the same time.
Stage memory tracks temporary progress and is saved in runtime state. Call execute(command) inside .onSubmit() when you want the submitted command’s .execute() handler to run.

End a game

A terminal automatic stage can omit .transition():
It accepts no commands and leaves the final view available to clients.
Keep transitions short. Put state changes in command execution or .run() so it is clear where rules mutate the game.

Assemble the definition

Connect state, events, setup, and the initial stage.