Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidatePlacements ¶
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 ¶
func (e InvalidTilePlacementError) Error() string
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 ¶
func (r InvalidTilePlacementReason) String() 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 ¶
PlacementValidator represents a function which validates whether the positions of tiles being placed on a board are valid.
type TilePlacement ¶
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) 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) 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.