Documentation ¶
Overview ¶
Package board stores the tiles for a game and handles queries to read and update tiles
Index ¶
- type Board
- func (b *Board) AddTile(t tile.Tile) error
- func (b *Board) CanBeFinished() bool
- func (b Board) CanMoveTiles(tilePositions map[tile.ID]tile.Position) bool
- func (b Board) MarshalJSON() ([]byte, error)
- func (b *Board) MoveTiles(tilePositions map[tile.ID]tile.Position) error
- func (b *Board) RemoveTile(t tile.Tile) error
- func (b *Board) Resize(cfg Config) (*ResizeResult, error)
- func (b *Board) UnmarshalJSON(d []byte) error
- func (b Board) UsedTileWords() []string
- type Config
- type ResizeResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Board ¶
type Board struct { UnusedTiles map[tile.ID]tile.Tile UnusedTileIDs []tile.ID UsedTiles map[tile.ID]tile.Position UsedTileLocs map[tile.X]map[tile.Y]tile.Tile Config }
Board represents the positioning of a player's tiles from a game. (Each player has their own board)
func New ¶
New creates a new board with the tiles as unusedTiles and tilePositions as used tiles. The config is preserved.
func (*Board) AddTile ¶
AddTile adds a tile to the board's unused tiles. An error is returned and the tile is not added if the player already has it.
func (*Board) CanBeFinished ¶
CanBeFinished determines if all the bord's tiles are used and form a single group.
func (Board) CanMoveTiles ¶
CanMoveTiles determines if the player's tiles can be moved to/in the used area without overlapping any other tiles
func (Board) MarshalJSON ¶
MarshalJSON implements the encoding/json.Marshaler interface. Returns an object containing the array of unused tiles, map of tile positions, and the board config.
func (*Board) MoveTiles ¶
MoveTiles moves the tiles to the specified positions. No action is taken and an error is returned if the tiles cannot be moved.
func (*Board) RemoveTile ¶
RemoveTile removes a single tile from the board's tiles. An error is returned if the board does not have the tile.
func (*Board) Resize ¶
func (b *Board) Resize(cfg Config) (*ResizeResult, error)
Resize resizes the board to use the new config. Any board size change information is returned in the message.
func (*Board) UnmarshalJSON ¶
UnmarshalJSON implements the encoding/json.Unmarshaler interface. UsedTiles and UnusedTiles are read from arrays and converted into maps for quick lookup.
func (Board) UsedTileWords ¶
UsedTileWords computes all the horizontal and vertical words formed by used tiles.