Snek v0.2.0 Snek.Ruleset behaviour View Source

A behaviour module for implementing variations of game rules.

Implementations define how a game plays out from start to finish, by dynamically specifying:

  1. init/2: The initial board position
  2. c:next/2: Each next turn's board position after moves are applied
  3. done?/1: When the game is considered over

Link to this section Summary

Types

Valid moves for a snake to play.

Callbacks

Decide whether the game is over at this board position.

Decide the initial board position for a new game.

Apply moves and decide the next turn's board position.

Link to this section Types

Specs

valid_move() :: :north | :south | :east | :west

Valid moves for a snake to play.

Link to this section Callbacks

Link to this callback

done?(board)

View Source (since 0.1.0)

Specs

done?(board :: Snek.Board.t()) :: boolean()

Decide whether the game is over at this board position.

Link to this callback

init(board_size, snake_ids)

View Source (since 0.1.0)

Specs

init(
  board_size :: Snek.Board.Size.t(),
  snake_ids :: MapSet.t(Snek.Board.Snake.id())
) :: {:ok, Snek.Board.t()} | {:error, atom()}

Decide the initial board position for a new game.

Link to this callback

next(board, snake_moves, apple_spawn_chance)

View Source (since 0.1.0)

Specs

next(
  board :: Snek.Board.t(),
  snake_moves :: [{Snek.Board.Snake.id(), valid_move()}],
  apple_spawn_chance :: float()
) :: Snek.Board.t()

Apply moves and decide the next turn's board position.