ritchie/game
Top-level module that manages an entire game, from beginning to end, across rounds, keeping track of everything. This is the one type you should hold.
Types
pub type GameError {
GameFinished
RoundAlreadyStarted
}
Constructors
-
GameFinished -
RoundAlreadyStarted
pub type GameStatus {
NotStarted
InRound
BetweenRounds
Finished
}
Constructors
-
NotStarted -
InRound -
BetweenRounds -
Finished
Result of advancing one turn.
pub type GameStepOutcome {
GameStepOutcome(
game: Game,
game_step: history.GameStep,
round_end: option.Option(boundary.RoundEnd),
)
}
Constructors
-
GameStepOutcome( game: Game, game_step: history.GameStep, round_end: option.Option(boundary.RoundEnd), )
Values
pub fn all_reactions(
game: Game,
) -> List(#(player.Player, List(reaction.Reaction)))
pub fn completed_rounds(game: Game) -> List(history.RoundHistory)
pub fn current_state(game: Game) -> option.Option(state.State)
pub fn is_finished(game: Game) -> Bool
pub fn jump_to_state(
game: Game,
current: state.State,
) -> Result(Game, error.EngineError)
Replaces the current round state. Lets you jump around, for things like replay or reconnect.
pub fn legal_actions(game: Game) -> List(action.Action)
pub fn legal_reactions(
game: Game,
reactor: player.Player,
) -> List(reaction.Reaction)
pub fn new(ruleset: rules.Ruleset, points: List(Int)) -> Game
Starts a new game with the provided rules and starting points.
pub fn new_at(
ruleset: rules.Ruleset,
points: List(Int),
round_id: boundary.RoundId,
pot: Int,
) -> Game
Starts a game with rules, points, and additionally a round ID, and pot. Mostly there so you can “jump” to a specific round in progress, perhaps when reconstructing a game from nothing.
pub fn new_default() -> Game
pub fn pending_action(game: Game) -> option.Option(action.Action)
pub fn register_action(
game: Game,
act: action.Action,
) -> Result(Game, error.EngineError)
Small wrapper over engine.register_action.
pub fn register_reaction(
game: Game,
reactor: player.Player,
reaction: reaction.Reaction,
) -> Result(Game, error.EngineError)
Small wrapper over engine.register_reaction.
pub fn round_begin(
game: Game,
) -> option.Option(boundary.RoundBegin)
pub fn round_end(game: Game) -> option.Option(boundary.RoundEnd)
pub fn round_history(
game: Game,
) -> option.Option(history.RoundHistory)
pub fn round_id(game: Game) -> boundary.RoundId
pub fn ruleset(game: Game) -> rules.Ruleset
pub fn start_round(
game: Game,
wall: wall.Wall,
) -> Result(Game, GameError)
Starts the current round with the supplied (already shuffled) wall.
pub fn status(game: Game) -> GameStatus
pub fn step(
game: Game,
) -> Result(GameStepOutcome, error.EngineError)
Advances the round by one turn. When the round ends, updates points, pot, round id, and status for the next round.