board

package
v0.0.0-...-c857007 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package board stores the tiles for a game and handles queries to read and update tiles

Index

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
	NumRows       int
	NumCols       int
}

Board represents the positioning of a player's tiles from a game. (Each player has their own board)

func (*Board) AddTile

func (b *Board) AddTile(t tile.Tile) error

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) CanMoveTiles

func (b Board) CanMoveTiles(tilePositions []tile.Position) bool

CanMoveTiles determines if the player's tiles can be moved to/in the used area without overlapping any other tiles

func (*Board) HasSingleUsedGroup

func (b *Board) HasSingleUsedGroup() bool

HasSingleUsedGroup determines if the player's tiles form a single group, with all tiles connected via immediate horizontal and vertical neighbors

func (*Board) MoveTiles

func (b *Board) MoveTiles(tilePositions []tile.Position) error

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

func (b *Board) RemoveTile(t tile.Tile) error

RemoveTile removes a single tile from the board's tiles. An error is returned if the board does not have the tile.

func (Board) UsedTileWords

func (b Board) UsedTileWords() []string

UsedTileWords computes all the horizontal and vertical words formed by used tiles.

type Config

type Config struct {
	NumRows int
	NumCols int
}

Config stores fields for creating a board.

func (Config) New

func (cfg Config) New(unusedTiles []tile.Tile) (*Board, error)

New creates a new board with the unused tiles.

func (Config) Validate

func (cfg Config) Validate() error

Validate returns an error if the number of rows or columns is invalid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL