board

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

type Board struct {
	Rows      int
	Columns   int
	Positions []Position
}

Board represents a game board, which is a grid of positions on which tiles can be placed. The zero-value of a Board is a zero-sized board.

func WithLayout

func WithLayout(layout Layout) Board

WithLayout creates a board with no tiles, with the specified layout.

Example
__, st, dl, dw, tl, tw := AllPositionTypes()

board := WithLayout(Layout{
	{tw, __, __, dl, __, __, __, tw, __, __, __, dl, __, __, tw},
	{__, dw, __, __, __, tl, __, __, __, tl, __, __, __, dw, __},
	{__, __, dw, __, __, __, dl, __, dl, __, __, __, dw, __, __},
	{dl, __, __, dw, __, __, __, dl, __, __, __, dw, __, __, dl},
	{__, __, __, __, dw, __, __, __, __, __, dw, __, __, __, __},
	{__, tl, __, __, __, tl, __, __, __, tl, __, __, __, tl, __},
	{__, __, dl, __, __, __, dl, __, dl, __, __, __, dl, __, __},
	{tw, __, __, dl, __, __, __, st, __, __, __, dl, __, __, tw},
	{__, __, dl, __, __, __, dl, __, dl, __, __, __, dl, __, __},
	{__, tl, __, __, __, tl, __, __, __, tl, __, __, __, tl, __},
	{__, __, __, __, dw, __, __, __, __, __, dw, __, __, __, __},
	{dl, __, __, dw, __, __, __, dl, __, __, __, dw, __, __, dl},
	{__, __, dw, __, __, __, dl, __, dl, __, __, __, dw, __, __},
	{__, dw, __, __, __, tl, __, __, __, tl, __, __, __, dw, __},
	{tw, __, __, dl, __, __, __, tw, __, __, __, dl, __, __, tw},
})

fmt.Printf("The board: %v", board)
Output:

func WithStandardLayout

func WithStandardLayout() Board

WithStandardLayout returns an empty Board with a standardised layout.

func (*Board) NeighbourHasTile

func (b *Board) NeighbourHasTile(c coord.Coord) bool

NeighbourHasTile returns true if any neighbouring position of the position at the specified coordinate has a tile on it.

func (*Board) Neighbours

func (b *Board) Neighbours(c coord.Coord) [4]*Position

Neighbours returns the cardinal neighbouring positions to the specified coordinate. If a neighbour would be out of bounds, nil is returned in its place. Neighbours are always returned in North, South, East, West order.

func (*Board) Position

func (b *Board) Position(c coord.Coord) *Position

Position returns the board position related to the specified coordinate. If the requested position is out of bounds, nil is returned.

type Layout

type Layout [][]PositionType

Layout represents a layout for creating a Board. Layouts are specified from the top row down, from the leftmost column to the rightmost.

func (Layout) WidestRow

func (l Layout) WidestRow() int

WidestRow returns the number of columns in the widest row of the layout.

type Position

type Position struct {
	Type PositionType
	Tile *tile.Tile
}

Position represents a single position on a Board, which may be occupied by a tile and may have a special property.

type PositionType

type PositionType interface {
	CountsAsConnected() bool
	ModifyTileScore(score int) int
	ModifyWordScore(score int) int
	Name() string
}

PositionType represents a type of board position, which may be a starting position, or a position with a score bonus, etc.

func AllPositionTypes

func AllPositionTypes() (__, st, dl, dw, tl, tw PositionType)

AllPositionTypes returns a set of built in position types which can be used to conveniently specify board Layouts. The position types returned are: normal/empty, start, double letter score, double word score, triple letter score, triple word score.

The same instances of the position types are always returned so they can be compared to each other.

See WithLayout for example usage.

Jump to

Keyboard shortcuts

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