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 contain nil values
  • attributes - A map of attributes held by the board
  • turn - A number that represents the current turn
  • effects - 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

Link to this function

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.

Link to this function

advance_turn(board)

Increments the turn count of the board by 1.

Link to this function

apply_actions(board, actions)

Applies the list of actions to the board in order and then returns the resulting board.

Link to this function

apply_effects(board)

Invokes each of the board's effects in order and then returns the affected board.

Link to this function

assign(board, attributes)

Assigns the provided attributes to the board. Any existing attributes that share a key will be overriden.

Link to this function

get(board, attribute_name)

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.