mundane.engine.rules

The one door: apply_action(state, action) validates a move, then transitions.

Every state change in the game goes through here. Each branch runs its _require preconditions first (which raise IllegalAction on a bad move, mutating nothing) and only then mutates. The function returns the state so it composes as a reducer: final = reduce(partial(apply_action, cards=pool), actions, initial).

Functions

_require(→ None)

Reject the action with IllegalAction(message) when condition is false.

apply_action(→ mundane.engine.state.GameState)

Validate action against state, then transition. Returns state.

_push_stack(→ None)

Put a card on the stack with a fresh id, then hand priority back to the active player.

_grant_priority_after_stack_change(→ None)

After anything goes on the stack, the active player gets priority and the pass count resets.

_resolve_top(→ None)

Resolve the top stack item (LIFO): permanents hit the board, others fire then go to discard.

_advance_phase(→ None)

Move to the next phase, or end the turn after the last phase.

_end_turn(→ None)

Hand the turn to the next player and run Wake Up housekeeping (refresh Time, draw).

_check_win(→ None)

Set the winner if any player's Composure has dropped to 0.

Module Contents

mundane.engine.rules._require(condition: bool, message: str) None[source]

Reject the action with IllegalAction(message) when condition is false.

mundane.engine.rules.apply_action(state: mundane.engine.state.GameState, action: mundane.engine.actions.Action, cards: dict[str, mundane.engine.state.Card]) mundane.engine.state.GameState[source]

Validate action against state, then transition. Returns state.

mundane.engine.rules._push_stack(state: mundane.engine.state.GameState, card_id: str, controller: int, target_id: int | None = None) None[source]

Put a card on the stack with a fresh id, then hand priority back to the active player.

mundane.engine.rules._grant_priority_after_stack_change(state: mundane.engine.state.GameState) None[source]

After anything goes on the stack, the active player gets priority and the pass count resets.

mundane.engine.rules._resolve_top(state: mundane.engine.state.GameState, cards: dict[str, mundane.engine.state.Card]) None[source]

Resolve the top stack item (LIFO): permanents hit the board, others fire then go to discard.

mundane.engine.rules._advance_phase(state: mundane.engine.state.GameState) None[source]

Move to the next phase, or end the turn after the last phase.

mundane.engine.rules._end_turn(state: mundane.engine.state.GameState) None[source]

Hand the turn to the next player and run Wake Up housekeeping (refresh Time, draw).

mundane.engine.rules._check_win(state: mundane.engine.state.GameState) None[source]

Set the winner if any player’s Composure has dropped to 0.