Documentation ¶
Index ¶
- Constants
- func ToMachineOnlyString(word string, alph *Alphabet) (string, error)
- type Alphabet
- func (a Alphabet) CurIdx() MachineLetter
- func (a *Alphabet) Init()
- func (a Alphabet) Letter(b MachineLetter) rune
- func (a Alphabet) Letters() map[MachineLetter]rune
- func (a Alphabet) NumLetters() uint8
- func (a *Alphabet) Reconcile()
- func (a *Alphabet) Serialize() []uint32
- func (a *Alphabet) Update(word string) error
- func (a Alphabet) Val(r rune) (MachineLetter, error)
- func (a Alphabet) Vals() map[rune]MachineLetter
- type Bag
- func (b *Bag) Draw(n int) ([]MachineLetter, error)
- func (b *Bag) DrawAtMost(n int) []MachineLetter
- func (b *Bag) Exchange(letters []MachineLetter) ([]MachineLetter, error)
- func (b *Bag) GetAlphabet() *Alphabet
- func (b *Bag) Refill()
- func (b *Bag) RemoveTiles(tiles []MachineLetter)
- func (b *Bag) Score(ml MachineLetter) int
- func (b *Bag) Shuffle()
- func (b *Bag) TilesRemaining() int
- type LetterDistribution
- type LetterSet
- type LetterSlice
- type MachineLetter
- type MachineWord
- type Rack
- func (r *Rack) Add(letter MachineLetter)
- func (r *Rack) Empty() bool
- func (r *Rack) NumTiles() uint8
- func (r *Rack) ScoreOn(numPossibleLetters int, bag *Bag) int
- func (r *Rack) Set(mls []MachineLetter)
- func (r *Rack) String() string
- func (r *Rack) Take(letter MachineLetter)
- func (r *Rack) TilesOn(numPossibleLetters int) MachineWord
- type Word
Constants ¶
const ( // MaxAlphabetSize is the maximum size of the alphabet, and is also // the "code" for the separation token. // It should be below 64 so that it can fit in one 64-bit word. // Gwich'in Scrabble has 62 separate letters, including the blank. // Lojban has even more, but that's a weird constructed language. MaxAlphabetSize = 50 // SeparationMachineLetter is the "MachineLetter" corresponding to // the separation token. It is set at the max alphabet size. SeparationMachineLetter = MaxAlphabetSize // BlankMachineLetter is the MachineLetter corresponding to the // blank. It is also set at the max alphabet size. Based on the context // in which it is used, it should not be confused with the // SeparationMachineLetter above. BlankMachineLetter = MaxAlphabetSize // BlankOffset is the offset at which letters with a code >= offset // represent blanks. BlankOffset = 100 // SeparationToken is the GADDAG separation token. SeparationToken = '^' // EmptySquareMarker is a MachineLetter representation of an empty square EmptySquareMarker = MaxAlphabetSize + 1 // PlayedThroughMarker is a MachineLetter representation of a filled-in square // that was played through. PlayedThroughMarker = MaxAlphabetSize + 2 // ASCIIPlayedThrough is a somewhat user-friendly representation of a // played-through letter, used mostly for debug purposes. // Note that in order to actually be visible on a computer screen, we // should use `(`and `)` around letters already on a board. ASCIIPlayedThrough = '.' // BlankToken is the user-friendly representation of a blank. BlankToken = '?' )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Alphabet ¶
type Alphabet struct {
// contains filtered or unexported fields
}
Alphabet defines an alphabet.
func FromSlice ¶
FromSlice creates an alphabet from a serialized array. It is the opposite of the Serialize function, except the length is implicitly passed in as the length of the slice.
func (Alphabet) CurIdx ¶
func (a Alphabet) CurIdx() MachineLetter
func (Alphabet) Letter ¶
func (a Alphabet) Letter(b MachineLetter) rune
Letter returns the letter that this position in the alphabet corresponds to.
func (Alphabet) Letters ¶
func (a Alphabet) Letters() map[MachineLetter]rune
func (Alphabet) NumLetters ¶
NumLetters returns the number of letters in this alphabet.
func (*Alphabet) Reconcile ¶
func (a *Alphabet) Reconcile()
Reconcile will take a populated alphabet, sort the glyphs, and re-index the numbers.
func (Alphabet) Val ¶
func (a Alphabet) Val(r rune) (MachineLetter, error)
Val returns the 'value' of this rune in the alphabet; i.e a number from 0 to maxsize + blank offset. Takes into account blanks (lowercase letters).
func (Alphabet) Vals ¶
func (a Alphabet) Vals() map[rune]MachineLetter
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
A Bag is the bag o'tiles!
func NewBag ¶
func NewBag(tiles []MachineLetter, numUniqueTiles int, alphabet *Alphabet, scores []int) *Bag
func (*Bag) Draw ¶
func (b *Bag) Draw(n int) ([]MachineLetter, error)
Draw draws n tiles from the bag.
func (*Bag) DrawAtMost ¶
func (b *Bag) DrawAtMost(n int) []MachineLetter
DrawAtMost draws at most n tiles from the bag. It can draw fewer if there are fewer tiles than n, and even draw no tiles at all :o
func (*Bag) Exchange ¶
func (b *Bag) Exchange(letters []MachineLetter) ([]MachineLetter, error)
Exchange exchanges the junk in your rack with new tiles.
func (*Bag) GetAlphabet ¶
func (*Bag) RemoveTiles ¶
func (b *Bag) RemoveTiles(tiles []MachineLetter)
RemoveTiles removes the given tiles from the bag.
func (*Bag) Score ¶
func (b *Bag) Score(ml MachineLetter) int
Score gives the score of the given machine letter. This is used by the move generator to score plays more rapidly than looking up a map.
func (*Bag) TilesRemaining ¶
type LetterDistribution ¶
type LetterDistribution struct { Distribution map[rune]uint8 PointValues map[rune]uint8 SortOrder map[rune]int Vowels []rune // contains filtered or unexported fields }
LetterDistribution encodes the tile distribution for the relevant game.
func EnglishLetterDistribution ¶
func EnglishLetterDistribution() *LetterDistribution
func PolishLetterDistribution ¶ added in v0.2.1
func PolishLetterDistribution() *LetterDistribution
func SpanishLetterDistribution ¶
func SpanishLetterDistribution() *LetterDistribution
func (*LetterDistribution) MakeBag ¶
func (ld *LetterDistribution) MakeBag(alph *Alphabet) *Bag
MakeBag returns a bag of tiles.
type LetterSet ¶
type LetterSet uint64
LetterSet is a bit mask of acceptable letters, with indices from 0 to the maximum alphabet size.
type LetterSlice ¶
type LetterSlice []rune
LetterSlice is a slice of runes. We make it a separate type for ease in defining sort functions on it.
func (LetterSlice) Len ¶
func (a LetterSlice) Len() int
func (LetterSlice) Less ¶
func (a LetterSlice) Less(i, j int) bool
func (LetterSlice) Swap ¶
func (a LetterSlice) Swap(i, j int)
type MachineLetter ¶
type MachineLetter byte
MachineLetter is a machine-only representation of a letter. It goes from 0 to the maximum alphabet size.
func ToMachineLetters ¶
func ToMachineLetters(word string, alph *Alphabet) ([]MachineLetter, error)
ToMachineLetters creates an array of MachineLetters from the given string.
func (MachineLetter) Blank ¶
func (ml MachineLetter) Blank() MachineLetter
Blank blankifies a letter; i.e. it adds the BlankOffset to it. It returns a new MachineLetter; it does not modify the one that is passed in!
func (MachineLetter) IsBlanked ¶
func (ml MachineLetter) IsBlanked() bool
IsBlanked returns true if this is the blank version of a letter.
func (MachineLetter) IsVowel ¶
func (ml MachineLetter) IsVowel(alph *Alphabet) bool
IsVowel returns true for vowels. Note that this needs an alphabet.
func (MachineLetter) Unblank ¶
func (ml MachineLetter) Unblank() MachineLetter
Unblank is the opposite of the above function; it removes the blank offset from a letter.
func (MachineLetter) UserVisible ¶
func (ml MachineLetter) UserVisible(alph *Alphabet) rune
UserVisible turns the passed-in machine letter into a user-visible rune.
type MachineWord ¶
type MachineWord []MachineLetter
MachineWord is an array of MachineLetters
func ToMachineWord ¶
func ToMachineWord(word string, alph *Alphabet) (MachineWord, error)
ToMachineWord creates a MachineWord from the given string.
func (MachineWord) Score ¶
func (mw MachineWord) Score(bag *Bag) int
Score returns the score of this word given the bag.
func (MachineWord) String ¶
func (mw MachineWord) String() string
String() returns a non-printable string version of this machineword. This is useful for hashing purposes.
func (MachineWord) UserVisible ¶
func (mw MachineWord) UserVisible(alph *Alphabet) string
UserVisible turns the passed-in machine word into a user-visible string.
type Rack ¶
type Rack struct { // letArr is an array of letter codes from 0 to MaxAlphabetSize. // The blank can go at the MaxAlphabetSize place. LetArr []int // contains filtered or unexported fields }
Rack is a machine-friendly representation of a user's rack.
func RackFromString ¶
RackFromString creates a Rack from a string and an alphabet
func (*Rack) Add ¶
func (r *Rack) Add(letter MachineLetter)
func (*Rack) Set ¶
func (r *Rack) Set(mls []MachineLetter)
Set sets the rack from a list of machine letters
func (*Rack) Take ¶
func (r *Rack) Take(letter MachineLetter)
func (*Rack) TilesOn ¶
func (r *Rack) TilesOn(numPossibleLetters int) MachineWord
TilesOn returns the MachineLetters of the rack's current tiles.
type Word ¶
type Word struct { Word string Dist *LetterDistribution // contains filtered or unexported fields }