Tabletop.Board (tabletop v1.1.2)
This module provides the struct for representing the board of a tabletop game as well as the functions for creating and manipulating it.
The Tabletop.Board Struct
The public fields are:
pieces
- A map comprised of position keys and piece values, empty positions containnil
valuesattributes
- A map of attributes held by the boardturn
- A number that represents the current turneffects
- A list of functions that are applied at the end of each turn
Effects
At the end of each turn, the board will invoke each of its' effects in turn. Each effect should accept the board as input and return a board as output. This allows a game to perform updates before the end of each turn like spawning some zombies or determining if the game is over.
Link to this section Summary
Functions
Adds the provided effects
to the board
. Each effect should be a function that accepts a board
and then returns a board.
Increments the turn count of the board
by 1.
Applies the list of actions
to the board
in order and then returns the resulting board.
Invokes each of the board's effects in order and then returns the affected board.
Assigns the provided attributes
to the board
. Any existing attributes that share
a key will be overriden.
Gets the value of the attribute named attribute_name
. Raises a KeyError if it doesn't exist.
Creates a %Tabletop.Board
with empty positions forming a square grid. Each position
is a tuple containing x
and y
coordinates.
Link to this section Functions
add_effects(board, effects)
Adds the provided effects
to the board
. Each effect should be a function that accepts a board
and then returns a board.
A single effect
may also be provided.
advance_turn(board)
Increments the turn count of the board
by 1.
apply_actions(board, actions)
Applies the list of actions
to the board
in order and then returns the resulting board.
apply_effects(board)
Invokes each of the board's effects in order and then returns the affected board.
assign(board, attributes)
Assigns the provided attributes
to the board
. Any existing attributes that share
a key will be overriden.
get(board, attribute_name)
Gets the value of the attribute named attribute_name
. Raises a KeyError if it doesn't exist.
square(size)
Creates a %Tabletop.Board
with empty positions forming a square grid. Each position
is a tuple containing x
and y
coordinates.