ritchie/engine

Driver of the main game logic.

Types

Driver of the main game logic. This has the following main functions:

  • register_action: Given State, is some Action valid?
  • register_reaction: Given State and a valid Action, is some Reaction valid?
  • step: Given State, a valid Action, and any valid Reactions, proceed to the next state.
pub opaque type Engine

Result of advancing one turn.

pub type StepOutcome {
  StepOutcome(
    engine: Engine,
    game_step: history.GameStep,
    round_end: option.Option(boundary.RoundEnd),
  )
}

Constructors

Values

pub fn begin_round(
  engine: Engine,
  begin: boundary.RoundBegin,
) -> Engine

Starts a new round, resetting any pending turn and history.

pub fn current_state(
  engine: Engine,
) -> option.Option(state.State)
pub fn jump_to_state(
  engine: Engine,
  current: state.State,
) -> Result(Engine, error.EngineError)

Replaces the current round state, e.g. for replay or testing.

pub fn new() -> Engine
pub fn pending_action(
  engine: Engine,
) -> option.Option(action.Action)
pub fn register_action(
  engine: Engine,
  act: action.Action,
) -> Result(Engine, error.EngineError)

Validates and stores an action for the current turn. Any previously registered reactions are discarded.

pub fn register_reaction(
  engine: Engine,
  reactor: player.Player,
  reaction: reaction.Reaction,
) -> Result(Engine, error.EngineError)

Validates and stores one player’s reaction to the pending action.

pub fn round_end(
  engine: Engine,
) -> option.Option(boundary.RoundEnd)
pub fn step(
  engine: Engine,
) -> Result(StepOutcome, error.EngineError)

Resolves the pending action and reactions, advancing the engine by one turn or ending the round.

✨ Search Document