Documentation ¶
Index ¶
- Constants
- Variables
- func FindLeftParts(dawg *Dawg, rack string) [][]*LeftPart
- type AdjSquares
- type Alphabet
- type Axis
- type Bag
- type BitMap
- type Board
- func (board *Board) CrossScore(row, col int, horizontal bool) (hasCrossing bool, score int)
- func (board *Board) CrossWords(row, col int, horizontal bool) (left, right string)
- func (board *Board) Fragment(row, col int, direction int) []*Tile
- func (board *Board) Init()
- func (board *Board) NumAdjacentTiles(row, col int) int
- func (board *Board) Sq(row, col int) *Square
- func (board *Board) String() string
- func (board *Board) TileAt(row, col int) *Tile
- func (board *Board) WordFragment(row, col int, direction int) (result string)
- type Coding
- type Coordinate
- type Cover
- type Covers
- type Dawg
- func (dawg *Dawg) CrossSet(left, right string) uint
- func (dawg *Dawg) Find(word string) bool
- func (dawg *Dawg) Init(filePath string, alphabet string) error
- func (dawg *Dawg) Match(pattern string) []string
- func (dawg *Dawg) MatchRunes(pattern []rune) []string
- func (dawg *Dawg) Navigate(navigator Navigator)
- func (dawg *Dawg) NavigateResumable(navigator Navigator)
- func (dawg *Dawg) Permute(rack string, minLen int) []string
- func (dawg *Dawg) Resume(navigator Navigator, state *navState, matched string)
- type ExchangeMove
- type ExtendRightNavigator
- func (ern *ExtendRightNavigator) Accept(matched string, final bool, state *navState)
- func (ern *ExtendRightNavigator) Accepts(letter rune) bool
- func (ern *ExtendRightNavigator) Done()
- func (ern *ExtendRightNavigator) Init(axis *Axis, anchor int, rack string)
- func (ern *ExtendRightNavigator) IsAccepting() bool
- func (ern *ExtendRightNavigator) PopEdge() bool
- func (ern *ExtendRightNavigator) PushEdge(letter rune) bool
- type FinalMove
- type FindNavigator
- func (fn *FindNavigator) Accept(matched string, final bool, state *navState)
- func (fn *FindNavigator) Accepts(chr rune) bool
- func (fn *FindNavigator) Done()
- func (fn *FindNavigator) Init(word string)
- func (fn *FindNavigator) IsAccepting() bool
- func (fn *FindNavigator) PopEdge() bool
- func (fn *FindNavigator) PushEdge(chr rune) bool
- type Game
- func (game *Game) Apply(move Move) bool
- func (game *Game) ApplyValid(move Move) bool
- func (game *Game) ForceRack(player int, letters string) bool
- func (game *Game) Init(tileSet *TileSet, dawg *Dawg)
- func (game *Game) IsOver() bool
- func (game *Game) MakePassMove() bool
- func (game *Game) MakeTileMove(row, col int, horizontal bool, tiles []*Tile) bool
- func (game *Game) PlayTile(tile *Tile, row, col int) bool
- func (game *Game) PlayerToMove() int
- func (game *Game) SetPlayerNames(player0, player1 string)
- func (game *Game) State() *GameState
- func (game *Game) String() string
- func (game *Game) TileAt(row, col int) *Tile
- func (game *Game) TilesOnBoard() int
- type GameState
- type HighScoreRobot
- type LeftFindNavigator
- func (lfn *LeftFindNavigator) Accept(matched string, final bool, state *navState)
- func (lfn *LeftFindNavigator) Accepts(chr rune) bool
- func (lfn *LeftFindNavigator) Done()
- func (lfn *LeftFindNavigator) Init(prefix Prefix)
- func (lfn *LeftFindNavigator) IsAccepting() bool
- func (lfn *LeftFindNavigator) PopEdge() bool
- func (lfn *LeftFindNavigator) PushEdge(chr rune) bool
- type LeftPart
- type LeftPermutationNavigator
- func (lpn *LeftPermutationNavigator) Accept(matched string, final bool, state *navState)
- func (lpn *LeftPermutationNavigator) Accepts(chr rune) bool
- func (lpn *LeftPermutationNavigator) Done()
- func (lpn *LeftPermutationNavigator) Init(rack string)
- func (lpn *LeftPermutationNavigator) IsAccepting() bool
- func (lpn *LeftPermutationNavigator) LeftParts(length int) []*LeftPart
- func (lpn *LeftPermutationNavigator) PopEdge() bool
- func (lpn *LeftPermutationNavigator) PushEdge(chr rune) bool
- type MatchNavigator
- func (mn *MatchNavigator) Accept(matched string, final bool, state *navState)
- func (mn *MatchNavigator) Accepts(chr rune) bool
- func (mn *MatchNavigator) Done()
- func (mn *MatchNavigator) Init(pattern []rune)
- func (mn *MatchNavigator) IsAccepting() bool
- func (mn *MatchNavigator) PopEdge() bool
- func (mn *MatchNavigator) PushEdge(chr rune) bool
- type Move
- type MoveItem
- type Navigation
- type Navigator
- type OneOfNBestRobot
- type PassMove
- type PermutationNavigator
- func (pn *PermutationNavigator) Accept(matched string, final bool, state *navState)
- func (pn *PermutationNavigator) Accepts(chr rune) bool
- func (pn *PermutationNavigator) Done()
- func (pn *PermutationNavigator) Init(rack string, minLen int)
- func (pn *PermutationNavigator) IsAccepting() bool
- func (pn *PermutationNavigator) PopEdge() bool
- func (pn *PermutationNavigator) PushEdge(chr rune) bool
- type Prefix
- type Rack
- func (rack *Rack) AsRunes() []rune
- func (rack *Rack) AsSet(alphabet *Alphabet) uint
- func (rack *Rack) AsString() string
- func (rack *Rack) Extract(numTiles int, meaning rune) []*Tile
- func (rack *Rack) Fill(bag *Bag) bool
- func (rack *Rack) FillByLetters(bag *Bag, letters []rune) bool
- func (rack *Rack) FindTile(letter rune) *Tile
- func (rack *Rack) FindTiles(letters []rune) []*Tile
- func (rack *Rack) HasTile(tile *Tile) bool
- func (rack *Rack) Init()
- func (rack *Rack) IsEmpty() bool
- func (rack *Rack) RemoveTile(tile *Tile) bool
- func (rack *Rack) ReturnToBag(bag *Bag)
- func (rack *Rack) String() string
- type Robot
- type RobotWrapper
- type Square
- type Tile
- type TileMove
- type TileSet
Constants ¶
const ( ABOVE = 0 LEFT = 1 RIGHT = 2 BELOW = 3 )
Indices into AdjSquares
const BingoBonus = 50
BingoBonus is the number of extra points awarded for laying down all the 7 tiles in the rack in one move
const BoardSize = 15
BoardSize is the size of the Board
const EnglishAlphabet = "abcdefghijklmnopqrstuvwxyz"
EnglishAlphabet contains the English SCRABBLE(tm) alphabet.
const IcelandicAlphabet = "aábdðeéfghiíjklmnoóprstuúvxyýþæö"
IcelandicAlphabet contains the Icelandic letters as they are indexed in the compressed binary DAWG. Note that the Icelandic alphabet does not contain 'c', 'q', w' or 'z'. TODO: move this to the DAWG file.
const IllegalMoveWord = "[???]"
IllegalMoveWord is the move.Word of an illegal move
const RackSize = 7
RackSize contains the number of slots in the Rack
Variables ¶
var EnglishTileSet = initEnglishTileSet()
EnglishTileSet is the standard English SCRABBLE(tm) tile set
var IcelandicDictionary = makeDawg("ordalisti.bin.dawg", IcelandicAlphabet)
IcelandicDictionary is a Dawg instance containing the Icelandic Scrabble(tm) dictionary, as derived from the BÍN database (Beygingarlýsing íslensks nútímamáls)
var NewIcelandicTileSet = initNewIcelandicTileSet()
NewIcelandicTileSet is the new standard Icelandic tile set
var SowpodsDictionary = makeDawg("sowpods.bin.dawg", EnglishAlphabet)
SowpodsDictionary is a Dawg instance containing the SOWPODS word list, used in European and U.S. SCRABBLE(tm).
var Twl06Dictionary = makeDawg("TWL06.bin.dawg", EnglishAlphabet)
Twl06Dictionary is a Dawg instance containing the Tournament Word List 06, used in U.S. SCRABBLE(tm).
Functions ¶
func FindLeftParts ¶
FindLeftParts returns all left part permutations that can be generated from the given rack, grouped by length
Types ¶
type AdjSquares ¶
type AdjSquares [4]*Square
AdjSquares is a list of four Square pointers, with a nil if the corresponding adjacent Square does not exist
type Alphabet ¶
type Alphabet struct {
// contains filtered or unexported fields
}
Alphabet stores the set of runes found within the DAWG, and supports bit map (set) operations
func (*Alphabet) Init ¶
Init initializes an Alphabet, including a precalculated bit map for its runes
type Axis ¶
type Axis struct {
// contains filtered or unexported fields
}
Axis stores information about a row or column on the board where the robot player is looking for valid moves
func (*Axis) Allows ¶
Allows returns true if the given letter can be placed in the indexed square within the Axis, in compliance with the cross checks
func (*Axis) GenerateMoves ¶
GenerateMoves returns a list of all legal moves along this Axis
type Bag ¶
type Bag struct { // Tiles is a fixed array of all tiles in a game, // copied at the start of the game from a TileSet Tiles []Tile // Contents is a list of pointers into the Tiles array, // corresponding to the current contents of the bag Contents []*Tile }
Bag is a randomized list of tiles, initialized from a tile set, that is yet to be drawn and used in a game
func (*Bag) DrawTileByLetter ¶
DrawTileByLetter draws the specified tile from the bag and returns it
func (*Bag) ExchangeAllowed ¶
ExchangeAllowed returns true if there are at least RackSize tiles left in the bag, thus allowing exchange of tiles
func (*Bag) ReturnTile ¶
ReturnTile returns a previously drawn Tile to the Bag
type BitMap ¶
BitMap maps runes to corresponding bit positions within an uint. It follows that the Alphabet cannot have more runes in it than uint has bits. Fortunately, few alphabets have more than 32/64 runes in them.
type Board ¶
type Board struct { Squares [BoardSize][BoardSize]Square Adjacents [BoardSize][BoardSize]AdjSquares // The number of tiles on the board NumTiles int }
Board represents the board as a matrix of Squares, and caches an adjacency matrix for each Square, consisting of pointers to adjacent Squares
func (*Board) CrossScore ¶
CrossScore returns the sum of the scores of the tiles crossing the given tile, either horizontally or vertically. If there are no crossings, returns false, 0. (Note that true, 0 is a valid return value, if a crossing has only blank tiles.)
func (*Board) CrossWords ¶
CrossWords returns the word fragments above and below, or to the left and right of, the given co-ordinate on the board.
func (*Board) Fragment ¶
Fragment returns a list of the tiles that extend from the square at row, col in the direction specified (ABOVE/BELOW/LEFT/RIGHT).
func (*Board) NumAdjacentTiles ¶
NumAdjacentTiles returns the number of tiles on the Board that are adjacent to the given coordinate
type Coding ¶
Coding maps an encoded byte to a legal letter, eventually suffixed with '|' to denote a final node in the Dawg
type Coordinate ¶
type Coordinate struct {
Row, Col int
}
Coordinate stores a Board co-ordinate as as row, col tuple
type Cover ¶
Cover is a part of a TileMove, describing the covering of a single Square by a Letter. The Letter may be '?' indicating a blank tile, in which case the Meaning gives its meaning.
type Covers ¶
type Covers map[Coordinate]Cover
Covers is a map of board coordinates to a tile covering
type Dawg ¶
type Dawg struct {
// contains filtered or unexported fields
}
Dawg encapsulates the externally generated, compressed Directed Acyclic Word Graph as a byte buffer. Within the DAWG, letters from the alphabet are represented as indices into the alphabet string (below). The Coding map translates these indices to the actual letters. The iterNodeCache map is built on the fly, when each Dawg node is traversed for the first time. In practice, many nodes will never be traversed.
func (*Dawg) CrossSet ¶
CrossSet calculates a bit-mapped set of allowed letters in a cross-check set, given a left/top and right/bottom string that intersects the square being checked.
func (*Dawg) Find ¶
Find attempts to find a word in a DAWG, returning true if found or false if not.
func (*Dawg) Match ¶
Match returns all words in the Dawg that match a given pattern string, which can include '?' wildcards/blanks.
func (*Dawg) MatchRunes ¶
MatchRunes returns all words in the Dawg that match a given pattern, which can include '?' wildcards/blanks.
func (*Dawg) Navigate ¶
Navigate performs a navigation through the DAWG under the control of a Navigator
func (*Dawg) NavigateResumable ¶
NavigateResumable performs a resumable navigation through the DAWG under the control of a Navigator
type ExchangeMove ¶
type ExchangeMove struct {
Letters string
}
ExchangeMove is a move that exchanges 1-7 tiles from the player's Rack with the Bag. It is only valid when at least 7 tiles are left in the Bag.
func NewExchangeMove ¶
func NewExchangeMove(letters string) *ExchangeMove
NewExchangeMove returns a reference to a fresh ExchangeMove
func (*ExchangeMove) Apply ¶
func (move *ExchangeMove) Apply(game *Game) bool
Apply replenishes the exchanged tiles in the Rack from the Bag
func (*ExchangeMove) IsValid ¶
func (move *ExchangeMove) IsValid(game *Game) bool
IsValid returns true if an exchange is allowed and all exchanged tiles are actually in the player's rack
func (*ExchangeMove) Score ¶
func (move *ExchangeMove) Score(state *GameState) int
Score is always 0 for an ExchangeMove
func (*ExchangeMove) String ¶
func (move *ExchangeMove) String() string
String return a string description of the ExchangeMove
type ExtendRightNavigator ¶
type ExtendRightNavigator struct {
// contains filtered or unexported fields
}
ExtendRightNavigator implements the core of the Appel-Jacobson algorithm. It proceeds along an Axis, covering empty Squares with Tiles from the Rack while obeying constraints from the Dawg and the cross-check sets. As final nodes in the Dawg are encountered, valid tile moves are generated and saved.
func (*ExtendRightNavigator) Accept ¶
func (ern *ExtendRightNavigator) Accept(matched string, final bool, state *navState)
Accept is called to inform the navigator of a match and whether it is a final word
func (*ExtendRightNavigator) Accepts ¶
func (ern *ExtendRightNavigator) Accepts(letter rune) bool
Accepts returns true if the navigator should accept and 'eat' the given character
func (*ExtendRightNavigator) Done ¶
func (ern *ExtendRightNavigator) Done()
Done is called when the navigation is complete
func (*ExtendRightNavigator) Init ¶
func (ern *ExtendRightNavigator) Init(axis *Axis, anchor int, rack string)
Init initializes a fresh ExtendRightNavigator for an axis, starting from the given anchor, using the indicated rack
func (*ExtendRightNavigator) IsAccepting ¶
func (ern *ExtendRightNavigator) IsAccepting() bool
IsAccepting returns false if the navigator should not expect more characters
func (*ExtendRightNavigator) PopEdge ¶
func (ern *ExtendRightNavigator) PopEdge() bool
PopEdge returns false if there is no need to visit other edges after this one has been traversed
func (*ExtendRightNavigator) PushEdge ¶
func (ern *ExtendRightNavigator) PushEdge(letter rune) bool
PushEdge determines whether the navigation should proceed into an edge having chr as its first letter
type FinalMove ¶
FinalMove represents the final adjustments that are made to player scores at the end of a Game
func NewFinalMove ¶
NewFinalMove returns a reference to a fresh FinalMove
type FindNavigator ¶
type FindNavigator struct {
// contains filtered or unexported fields
}
FindNavigator stores the state for a plain word search in the Dawg, and implements the Navigator interface
func (*FindNavigator) Accept ¶
func (fn *FindNavigator) Accept(matched string, final bool, state *navState)
Accept is called to inform the navigator of a match and whether it is a final word
func (*FindNavigator) Accepts ¶
func (fn *FindNavigator) Accepts(chr rune) bool
Accepts returns true if the navigator should accept and 'eat' the given character
func (*FindNavigator) Done ¶
func (fn *FindNavigator) Done()
Done is called when the navigation is complete
func (*FindNavigator) Init ¶
func (fn *FindNavigator) Init(word string)
Init initializes a FindNavigator with the word to search for
func (*FindNavigator) IsAccepting ¶
func (fn *FindNavigator) IsAccepting() bool
IsAccepting returns false if the navigator should not expect more characters
func (*FindNavigator) PopEdge ¶
func (fn *FindNavigator) PopEdge() bool
PopEdge returns false if there is no need to visit other edges after this one has been traversed
func (*FindNavigator) PushEdge ¶
func (fn *FindNavigator) PushEdge(chr rune) bool
PushEdge determines whether the navigation should proceed into an edge having chr as its first letter
type Game ¶
type Game struct { PlayerNames [2]string Scores [2]int Board Board Racks [2]Rack Bag *Bag MoveList []*MoveItem // The DAWG dictionary to use in the game Dawg *Dawg // The tile set to use in the game TileSet *TileSet // The number of consecutive non-tile, zero-point moves // (when 6 consecutive such moves have been made, // the game is over) NumPassMoves int // Whether to validate words formed by tile moves in // the game ValidateWords bool }
Game is a container for an in-progress game between two players, having a Board and two Racks, as well as a Bag and a list of Moves made so far. We also keep track of the number of Tiles that have been placed on the Board.
func NewIcelandicGame ¶
func NewIcelandicGame() *Game
NewIcelandicGame instantiates a new Game with the Icelandic TileSet and returns a reference to it
func NewSowpodsGame ¶
func NewSowpodsGame() *Game
NewSowpodsGame instantiates a new Game with the English TileSet and returns a reference to it
func NewTwl06Game ¶
func NewTwl06Game() *Game
NewTwl06Game instantiates a new Game with the English TileSet and returns a reference to it
func (*Game) ApplyValid ¶
ApplyValid applies an already validated Move to a Game, appends it to the move list, replenishes the player's Rack if needed, and updates scores.
func (*Game) ForceRack ¶
ForceRack forces the rack of the given player (or -1 = player whose move it is) to contain the given tiles. The tiles that were previously in the rack are first returned to the bag, and then the specified new tiles are drawn. If any of them is not found in the bag, the operation is aborted and false is returned.
func (*Game) Init ¶
Init initializes a new game with a fresh bag copied from the given tile set, and draws the player racks from the bag
func (*Game) MakePassMove ¶
MakePassMove appends a pass move to the Game's move list
func (*Game) MakeTileMove ¶
MakeTileMove creates a tile move and appends it to the Game's move list
func (*Game) PlayerToMove ¶
PlayerToMove returns 0 or 1 depending on which player's move it is
func (*Game) SetPlayerNames ¶
SetPlayerNames sets the names of the two players
func (*Game) State ¶
State returns a new GameState instance describing the state of the game in a minimal manner so that a robot player can decide on a move
func (*Game) TileAt ¶
TileAt is a convenience function for returning the Tile at a given coordinate on the Game Board
func (*Game) TilesOnBoard ¶
TilesOnBoard returns the number of tiles already laid down on the board
type GameState ¶
type GameState struct { Dawg *Dawg TileSet *TileSet Board *Board // The rack of the player whose move it is Rack *Rack // contains filtered or unexported fields }
GameState contains the bare minimum of information that is needed for a robot player to decide on a move in a Game.
func (*GameState) GenerateMoves ¶
GenerateMoves returns a list of all legal moves in the GameState, considering the Board and the player's Rack. The generation works by dividing the task into 30 sub-tasks of finding legal moves within each Axis, i.e. all columns and rows of the board. These sub-tasks are performed concurrently (and hopefully in parallel to some extent) by 30 goroutines.
type HighScoreRobot ¶
type HighScoreRobot struct { }
HighScoreRobot implements a simple strategy: it always picks the highest-scoring move available, or exchanges all tiles if there is no valid tile move, or passes if exchange is not allowed.
type LeftFindNavigator ¶
type LeftFindNavigator struct {
// contains filtered or unexported fields
}
LeftFindNavigator is similar to FindNavigator, but instead of returning only a bool result, it returns the full navigation state as it is when the requested word prefix is found. This makes it possible to continue the navigation later with further constraints.
func (*LeftFindNavigator) Accept ¶
func (lfn *LeftFindNavigator) Accept(matched string, final bool, state *navState)
Accept is called to inform the navigator of a match and whether it is a final word
func (*LeftFindNavigator) Accepts ¶
func (lfn *LeftFindNavigator) Accepts(chr rune) bool
Accepts returns true if the navigator should accept and 'eat' the given character
func (*LeftFindNavigator) Done ¶
func (lfn *LeftFindNavigator) Done()
Done is called when the navigation is complete
func (*LeftFindNavigator) Init ¶
func (lfn *LeftFindNavigator) Init(prefix Prefix)
Init initializes a LeftFindNavigator with the word to search for
func (*LeftFindNavigator) IsAccepting ¶
func (lfn *LeftFindNavigator) IsAccepting() bool
IsAccepting returns false if the navigator should not expect more characters
func (*LeftFindNavigator) PopEdge ¶
func (lfn *LeftFindNavigator) PopEdge() bool
PopEdge returns false if there is no need to visit other edges after this one has been traversed
func (*LeftFindNavigator) PushEdge ¶
func (lfn *LeftFindNavigator) PushEdge(chr rune) bool
PushEdge determines whether the navigation should proceed into an edge having chr as its first letter
type LeftPart ¶
type LeftPart struct {
// contains filtered or unexported fields
}
LeftPart stores the navigation state after matching a particular left part within the DAWG, so we can resume navigation from that point to complete an anchor square followed by a right part
type LeftPermutationNavigator ¶
type LeftPermutationNavigator struct {
// contains filtered or unexported fields
}
LeftPermutationNavigator finds all left parts of words that are possible with a particular rack, and accumulates them by length. This is done once at the start of move generation.
func (*LeftPermutationNavigator) Accept ¶
func (lpn *LeftPermutationNavigator) Accept(matched string, final bool, state *navState)
Accept is called to inform the navigator of a match and whether it is a final word
func (*LeftPermutationNavigator) Accepts ¶
func (lpn *LeftPermutationNavigator) Accepts(chr rune) bool
Accepts returns true if the navigator should accept and 'eat' the given character
func (*LeftPermutationNavigator) Done ¶
func (lpn *LeftPermutationNavigator) Done()
Done is called when the navigation is complete
func (*LeftPermutationNavigator) Init ¶
func (lpn *LeftPermutationNavigator) Init(rack string)
Init initializes a fresh LeftPermutationNavigator using the given rack
func (*LeftPermutationNavigator) IsAccepting ¶
func (lpn *LeftPermutationNavigator) IsAccepting() bool
IsAccepting returns false if the navigator should not expect more characters
func (*LeftPermutationNavigator) LeftParts ¶
func (lpn *LeftPermutationNavigator) LeftParts(length int) []*LeftPart
LeftParts returns a list of strings containing the left parts of words that could be found in the given Rack
func (*LeftPermutationNavigator) PopEdge ¶
func (lpn *LeftPermutationNavigator) PopEdge() bool
PopEdge returns false if there is no need to visit other edges after this one has been traversed
func (*LeftPermutationNavigator) PushEdge ¶
func (lpn *LeftPermutationNavigator) PushEdge(chr rune) bool
PushEdge determines whether the navigation should proceed into an edge having chr as its first letter
type MatchNavigator ¶
type MatchNavigator struct {
// contains filtered or unexported fields
}
MatchNavigator stores the state for a pattern matching navigation of a Dawg, and implements the Navigator interface
func (*MatchNavigator) Accept ¶
func (mn *MatchNavigator) Accept(matched string, final bool, state *navState)
Accept is called to inform the navigator of a match and whether it is a final word
func (*MatchNavigator) Accepts ¶
func (mn *MatchNavigator) Accepts(chr rune) bool
Accepts returns true if the navigator should accept and 'eat' the given character
func (*MatchNavigator) Done ¶
func (mn *MatchNavigator) Done()
Done is called when the navigation is complete
func (*MatchNavigator) Init ¶
func (mn *MatchNavigator) Init(pattern []rune)
Init initializes a MatchNavigator with the word to search for
func (*MatchNavigator) IsAccepting ¶
func (mn *MatchNavigator) IsAccepting() bool
IsAccepting returns false if the navigator should not expect more characters
func (*MatchNavigator) PopEdge ¶
func (mn *MatchNavigator) PopEdge() bool
PopEdge returns false if there is no need to visit other edges after this one has been traversed
func (*MatchNavigator) PushEdge ¶
func (mn *MatchNavigator) PushEdge(chr rune) bool
PushEdge determines whether the navigation should proceed into an edge having chr as its first letter
type MoveItem ¶
MoveItem is an entry in the MoveList of a Game. It contains the player's Rack as it was before the move, as well as the move itself.
type Navigation ¶
type Navigation struct {
// contains filtered or unexported fields
}
Navigation contains the state of a single navigation that is underway within a Dawg
func (*Navigation) FromEdge ¶
func (nav *Navigation) FromEdge(state *navState, matched string)
FromEdge navigates along an edge in the Dawg. An edge consists of a prefix string, which may be longer than one letter.
func (*Navigation) FromNode ¶
func (nav *Navigation) FromNode(offset uint32, matched string)
FromNode continues a navigation from a node in the Dawg, enumerating through outgoing edges until the navigator is satisfied
func (*Navigation) Go ¶
func (nav *Navigation) Go(dawg *Dawg, navigator Navigator)
Go starts a navigation on the underlying Dawg using the given Navigator
type Navigator ¶
type Navigator interface {}
Navigator is an interface that describes behaviors that control the navigation of a Dawg
type OneOfNBestRobot ¶
type OneOfNBestRobot struct {
N int
}
OneOfNBestRobot picks one of the N highest-scoring moves at random.
type PassMove ¶
type PassMove struct { }
PassMove is a move that is always valid, has no effect when applied, and has a score of 0
type PermutationNavigator ¶
type PermutationNavigator struct {
// contains filtered or unexported fields
}
PermutationNavigator stores the state for a plain word search in the Dawg, and implements the Navigator interface
func (*PermutationNavigator) Accept ¶
func (pn *PermutationNavigator) Accept(matched string, final bool, state *navState)
Accept is called to inform the navigator of a match and whether it is a final word
func (*PermutationNavigator) Accepts ¶
func (pn *PermutationNavigator) Accepts(chr rune) bool
Accepts returns true if the navigator should accept and 'eat' the given character
func (*PermutationNavigator) Done ¶
func (pn *PermutationNavigator) Done()
Done is called when the navigation is complete
func (*PermutationNavigator) Init ¶
func (pn *PermutationNavigator) Init(rack string, minLen int)
Init initializes a PermutationNavigator with the word to search for
func (*PermutationNavigator) IsAccepting ¶
func (pn *PermutationNavigator) IsAccepting() bool
IsAccepting returns false if the navigator should not expect more characters
func (*PermutationNavigator) PopEdge ¶
func (pn *PermutationNavigator) PopEdge() bool
PopEdge returns false if there is no need to visit other edges after this one has been traversed
func (*PermutationNavigator) PushEdge ¶
func (pn *PermutationNavigator) PushEdge(chr rune) bool
PushEdge determines whether the navigation should proceed into an edge having chr as its first letter
type Prefix ¶
type Prefix []rune
A Prefix is an array of runes that prefixes an outgoing edge in the Dawg
type Rack ¶
type Rack struct { Slots [RackSize]Square // Letters is a map of letters in the rack with their count, // with blank tiles being represented by '?' Letters map[rune]int }
Rack represents a player's rack of Tiles
func (*Rack) AsSet ¶
AsSet returns the rack as a bit-mapped set of runes. If the rack contains a blank tile ('?'), the bitmap will have all bits set.
func (*Rack) Extract ¶
Extract obtains the given number of tiles from the rack, returning them as a list. If a tile is blank, assign the given meaning to it. This function is useful for debugging and testing purposes.
func (*Rack) Fill ¶
Fill draws tiles from the bag to fill a rack. Returns false if unable to fill all empty slots.
func (*Rack) FillByLetters ¶
FillByLetters draws tiles identified by the given array of letters from the Bag to fill the Rack, at least as far as possible. Returns false if a tile corresponding to a letter from the array is not found in the bag.
func (*Rack) FindTile ¶
FindTile finds a tile with the given letter (or '?') in the rack and returns a pointer to it, or nil if not found
func (*Rack) FindTiles ¶
FindTiles finds tiles corresponding to the given letters (or '?') in the rack and returns a list. If tiles are not found in the rack, they are not included in the result. Note that the same tile is not returned twice, even if a particular letter is requested twice.
func (*Rack) RemoveTile ¶
RemoveTile removes a tile from a Rack
func (*Rack) ReturnToBag ¶
ReturnToBag returns the tiles in the Rack to a Bag
type Robot ¶
Robot is an interface for automatic players that implement a playing strategy to pick a move given a list of legal tile moves.
type RobotWrapper ¶
type RobotWrapper struct {
Robot
}
RobotWrapper wraps a Robot implementation
func NewHighScoreRobot ¶
func NewHighScoreRobot() *RobotWrapper
NewHighScoreRobot returns a fresh instance of a HighestScoreRobot
func NewOneOfNBestRobot ¶
func NewOneOfNBestRobot(n int) *RobotWrapper
NewOneOfNBestRobot returns a fresh instance of a OneOfNBestRobot
func (*RobotWrapper) GenerateMove ¶
func (rw *RobotWrapper) GenerateMove(state *GameState) Move
GenerateMove generates a list of legal tile moves, then asks the wrapped robot to pick one of them to play
type Square ¶
type Square struct { Tile *Tile LetterMultiplier int WordMultiplier int Row int // Board row 0..14, or -1 if rack square Col int // Board column 0..14, or rack square 0..6 }
Square is a Board square or Rack slot that can hold a Tile
type Tile ¶
type Tile struct { Letter rune Meaning rune // Meaning of blank tile (if Letter=='?') Score int // The nominal score of the tile PlayedBy int // Which player played the tile }
Tile is a tile from the Bag
type TileMove ¶
type TileMove struct { TopLeft Coordinate BottomRight Coordinate Covers Covers Horizontal bool Word string CachedScore *int // If ValidateWords is true, IsValid() should check all words // formed by this move against the game dictionary ValidateWords bool }
TileMove represents a normal tile move by a player, where one or more Squares are covered by a Tile from the player's Rack
func NewTileMove ¶
NewTileMove creates a new TileMove object with the given Covers, i.e. Tile coverings
func NewUncheckedTileMove ¶
NewUncheckedTileMove creates a new TileMove object with the given Covers, i.e. Tile coverings. In contrast to NewTileMove(), this function does not check that the words formed by the tile move are valid. It is intended for testing purposes.
func (*TileMove) Apply ¶
Apply moves the tiles in the Covers from the player's Rack to the board Squares
func (*TileMove) Init ¶
Init initializes a TileMove instance for a particular Board using a map of Coordinate to Cover