play

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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidatePlacements

func ValidatePlacements(placements Tiles, b *board.Board) (err error)

ValidatePlacements checks the intended placement of tiles on a board for legality. This includes: that at least one tile is placed, that tiles are placed contiguously, that tiles are placed only in a straight line, that there are no gaps created in the result, that tiles do not overlap with each other or with tiles already on the board, and that no tiles are placed out of bounds.

If any violations are detected, InvalidTilePlacementError is returned with the reason indicating the violation.

Otherwise, nil is returned, indicating that it would be safe to place the given tiles on the board (word validity not withstanding).

Types

type InvalidTilePlacementError

type InvalidTilePlacementError struct {
	Reason InvalidTilePlacementReason
}

InvalidTilePlacementError indicates that a play called for placing tiles in an invalid manner.

func (InvalidTilePlacementError) Error

type InvalidTilePlacementReason

type InvalidTilePlacementReason int

InvalidTilePlacementReason indicates the reason for an InvalidTilePlacementError.

const (
	// UnknownInvalidTilePlacementReason indicates that a reason was undefined.
	UnknownInvalidTilePlacementReason InvalidTilePlacementReason = iota

	// NoTilesPlacedReason indicates that a play attempted to place zero tiles.
	NoTilesPlacedReason

	// PositionOccupiedReason indicates that a play attempted to place a tile in
	// an already occupied position.
	PositionOccupiedReason

	// PlacementOutOfBoundsReason indicates that a play attempted to place a
	// tile outside the valid bounds of the board.
	PlacementOutOfBoundsReason

	// PlacementOverlapReason indicates that a play attempted to place tiles in
	// an overlapping manner.
	PlacementOverlapReason

	// PlacementNotLinearReason indicates that a play was attempted such that
	// the tiles were not all in a straight (horizontal or vertical) line.
	PlacementNotLinearReason

	// PlacementNotContiguousReason indicates that a play was attempted such
	// that gaps would be created in the tiles.
	PlacementNotContiguousReason

	// PlacementNotConnectedReason indicates that a play attempted to set tiles
	// down such that they were not on a starting position and not touching any
	// existing tiles.
	PlacementNotConnectedReason
)

func (InvalidTilePlacementReason) GoString

func (r InvalidTilePlacementReason) GoString() string

GoString returns the Go syntax representation of the reason, or UnknownInvalidTilePlacementReason if it is not a valid reason.

func (InvalidTilePlacementReason) String

String returns the textual representation of the reason, or "Unknown" if it is not a valid reason.

type InvalidWordError

type InvalidWordError struct {
	Words []Word
}

InvalidWordError indicates that one or more formed words is not valid for play and cannot be scored.

func (InvalidWordError) Error

func (e InvalidWordError) Error() string

type PlacementValidator

type PlacementValidator func(placements Tiles, board *board.Board) error

PlacementValidator represents a function which validates whether the positions of tiles being placed on a board are valid.

type TilePlacement

type TilePlacement struct {
	Tile tile.Tile
	coord.Coord
}

TilePlacement represents the placement of a single tile on a board.

type Tiles

type Tiles []TilePlacement

Tiles represents a set of tile placements on a board.

func (Tiles) Bounds

func (tp Tiles) Bounds() coord.Range

Bounds returns the minimum and maximum coordinates spanned by the placements.

func (Tiles) Find

func (tp Tiles) Find(c coord.Coord) *TilePlacement

Find returns the first placement corresponding to the given coordinate, or nil if no matching placement exists.

func (*Tiles) Place

func (tp *Tiles) Place(b *board.Board)

Place sets the specified board positions to the specified tiles.

func (*Tiles) Take

func (tp *Tiles) Take(c coord.Coord) *TilePlacement

Take removes and returns a placement for the specified coordinate, returning nil if no tile is being placed at that coordinate.

func (*Tiles) TakeLast

func (tp *Tiles) TakeLast() *TilePlacement

TakeLast removes the last placement and returns it, or nil if there are no placements left.

func (Tiles) Tiles

func (tp Tiles) Tiles() []tile.Tile

Tiles returns the collection of tiles being placed.

type Word

type Word struct {
	Word  string
	Score int
	coord.Range
}

Word represents a word formed on the board by playing tiles.

Jump to

Keyboard shortcuts

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