Documentation
¶
Overview ¶
Package banana contains the domain types for playing a game of Bananagrams.
Index ¶
- func StartingTileCount(pc, scale int) int
- type Board
- func (b *Board) AddWord(w Word) error
- func (b *Board) AddWords(words []Word) error
- func (b *Board) AsTiles() *Tiles
- func (b *Board) Clone() *Board
- func (b *Board) Count() int
- func (b *Board) Diff(tiles *Tiles) *Tiles
- func (b *Board) Validate(tiles *Tiles, dict Dictionary) *BoardValidation
- func (b *Board) Words() []Word
- type BoardStatus
- type BoardStatusCode
- type BoardValidation
- type Bunch
- type CharLoc
- type CharLocs
- type Config
- type DB
- type Dictionary
- type Distribution
- type Game
- type GameID
- type GameStatus
- type Letter
- type Loc
- type Orientation
- type Player
- type PlayerID
- type Tiles
- type Word
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StartingTileCount ¶
Types ¶
type Board ¶
type Board struct {
// contains filtered or unexported fields
}
Board represents an individual players game board.
func (*Board) AddWord ¶
AddWord attempts to add a word to the board, and calculates a few common data structures for later Board validation steps. If the word doesn't fit with existing words on the board, an error is returned.
func (*Board) Validate ¶
func (b *Board) Validate(tiles *Tiles, dict Dictionary) *BoardValidation
Validate returns the status of the board.
type BoardStatus ¶
type BoardStatus struct { Code BoardStatusCode Errors []string }
BoardStatus describes if a board is valid, or how it is invalid.
type BoardStatusCode ¶
type BoardStatusCode int
BoardStatusCode describes the current validity of a board.
const ( Success BoardStatusCode = iota InvalidWord DetachedBoard NotAllLetters ExtraLetters InvalidBoard )
type BoardValidation ¶
type Bunch ¶
type Bunch struct {
// contains filtered or unexported fields
}
func NewBunch ¶
func NewBunch(dist Distribution) *Bunch
type CharLocs ¶
CharLocs is a list of letters and the word they make up, this is currently only used for returning bad words.
type Config ¶
type Config struct { // The minimum number of letters that a word needs to have to be considered // valid. MinLettersInWord int }
type DB ¶
type DB interface { // Creates a new game with the given name and creator. NewGame(name string, creator PlayerID, config *Config) (GameID, error) // Get all of the games. Games() ([]*Game, error) // Loads a game with the given ID. Game(id GameID) (*Game, error) // Loads the bunch for the game with the given ID. Bunch(id GameID) (*Bunch, error) // Registers a player in our system. RegisterPlayer(name string) (PlayerID, error) // Adds a player to a not-yet-started game. AddPlayerToGame(gID GameID, pID PlayerID) error // Get all the players for a game. Players(id GameID) ([]*Player, error) // Loads a player with the given ID. Player(id PlayerID) (*Player, error) // Loads the board for the given game and player IDs. Board(gID GameID, pID PlayerID) (*Board, error) // Loads tiles for the given game and player IDs. Tiles(gID GameID, pID PlayerID) (*Tiles, error) // Updates a player's board. UpdateBoard(gID GameID, pID PlayerID, board *Board) error // Updates a player's tiles. UpdateTiles(gID GameID, pID PlayerID, tiles *Tiles) error // Updates the bunch for the game. UpdateBunch(id GameID, bunch *Bunch) error // Starts a game, and sets everyone's initial tile sets. StartGame(id GameID, players map[PlayerID]*Tiles, bunch *Bunch) error // Ends a given game, stops players from adding more to their boards. EndGame(id GameID) error }
type Dictionary ¶
func NewDictionary ¶
func NewDictionary(r io.Reader) (Dictionary, error)
type Distribution ¶
func Bananagrams ¶
func Bananagrams() Distribution
Bananagrams returns the distribution of letters on a Bananagrams board.
func None ¶
func None() Distribution
func Scale ¶
func Scale(dist Distribution, scale int) (Distribution, error)
func TestDistribution ¶
func TestDistribution() Distribution
TestDistribution returns a small distribution for more easily testing end-game scenarios.
type Game ¶
type GameStatus ¶
type GameStatus int
const ( UnknownStatus GameStatus = iota WaitingForPlayers InProgress Finished )
func (GameStatus) String ¶
func (g GameStatus) String() string
type Orientation ¶
type Orientation int
Orientation describes how a board is placed on the board.
const ( // NoOrientation is a catch-all for unknown orientations. NoOrientation Orientation = iota // Horizontal means the word is placed on the board from left to right. Horizontal // Vertical means the word is placed on the board from top to bottom. Vertical )
type Tiles ¶
type Tiles struct {
// contains filtered or unexported fields
}
Tiles represents a set of tiles.
func (*Tiles) Add ¶
Add adds tiles from one tile set to another, without modifying the tile set to add.
func (*Tiles) Dec ¶
Dec removes one from the count of the given letter. This is allowed to be negative and is actually a key part of diffing tile sets.