Documentation ¶
Index ¶
- Constants
- func HashableToUserVisible(s string, alph *Alphabet) string
- 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) Copy(randSource *rand.Rand) *Bag
- func (b *Bag) CopyFrom(other *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) LetterDistribution() *LetterDistribution
- func (b *Bag) Peek() []MachineLetter
- func (b *Bag) PutBack(letters []MachineLetter)
- func (b *Bag) Redraw(currentRack []MachineLetter) []MachineLetter
- func (b *Bag) Refill()
- func (b *Bag) RemoveTiles(tiles []MachineLetter) error
- func (b *Bag) Shuffle()
- func (b *Bag) TilesRemaining() int
- type LetterDistribution
- type LetterSet
- type LetterSlice
- type MachineLetter
- func (ml MachineLetter) Blank() MachineLetter
- func (ml MachineLetter) IntrinsicTileIdx() (MachineLetter, bool)
- func (ml MachineLetter) IsBlanked() bool
- func (ml MachineLetter) IsPlayedTile() bool
- func (ml MachineLetter) IsVowel(alph *Alphabet) bool
- func (ml MachineLetter) Unblank() MachineLetter
- func (ml MachineLetter) UserVisible(alph *Alphabet) rune
- type MachineWord
- type Rack
- func (r *Rack) Add(letter MachineLetter)
- func (r *Rack) Alphabet() *Alphabet
- func (r *Rack) Clear()
- func (r *Rack) Copy() *Rack
- func (r *Rack) CopyFrom(other *Rack)
- func (r *Rack) Empty() bool
- func (r *Rack) Has(letter MachineLetter) bool
- func (r *Rack) Hashable() string
- func (r *Rack) NumTiles() uint8
- func (r *Rack) ScoreOn(ld *LetterDistribution) int
- func (r *Rack) Set(mls []MachineLetter)
- func (r *Rack) String() string
- func (r *Rack) Take(letter MachineLetter)
- func (r *Rack) TilesOn() 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 ¶
func HashableToUserVisible ¶ added in v0.2.11
HashableToUserVisible converts a non-printable representation of a machine word to a printable one. The machine word is not required as an argument, just the non-printable string.
Types ¶
type Alphabet ¶
type Alphabet struct {
// contains filtered or unexported fields
}
Alphabet defines an alphabet.
func EnglishAlphabet ¶ added in v0.2.11
func EnglishAlphabet() *Alphabet
EnglishAlphabet returns an alphabet that corresponds to the English alphabet. This function should be used for testing. In production we will load the alphabet from the gaddag.
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 SpanishAlphabet ¶ added in v0.4.0
func SpanishAlphabet() *Alphabet
SpanishAlphabet returns an alphabet that corresponds to the Spanish alphabet. This function should be used for testing. In production we will load the alphabet from the gaddag.
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 (*Bag) Copy ¶ added in v0.2.11
Copy copies to a new bag and returns it. Note that the initialTiles are only shallowly copied. This is fine because we don't ever expect these to change after initialization. If randSource is not nil, it is set as the rand source for the copy. Otherwise, use the original's rand source.
func (*Bag) CopyFrom ¶ added in v0.2.11
CopyFrom copies back the tiles from another bag into this bag. The caller of this function is responsible for ensuring `other` has the other structures we need! (letter distribution, etc). It should have been created from the Copy function above.
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) LetterDistribution ¶ added in v0.4.0
func (b *Bag) LetterDistribution() *LetterDistribution
func (*Bag) Peek ¶ added in v0.2.11
func (b *Bag) Peek() []MachineLetter
func (*Bag) PutBack ¶ added in v0.4.0
func (b *Bag) PutBack(letters []MachineLetter)
PutBack puts the tiles back in the bag, and shuffles the bag.
func (*Bag) Redraw ¶ added in v0.4.0
func (b *Bag) Redraw(currentRack []MachineLetter) []MachineLetter
Redraw is basically a do-over; throw the current rack in the bag and draw a new rack.
func (*Bag) RemoveTiles ¶
func (b *Bag) RemoveTiles(tiles []MachineLetter) error
RemoveTiles removes the given tiles from the bag, and returns an error if it can't.
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(alph *Alphabet) *LetterDistribution
func NamedLetterDistribution ¶ added in v0.4.0
func NamedLetterDistribution(name string, alph *Alphabet) *LetterDistribution
func PolishLetterDistribution ¶ added in v0.2.1
func PolishLetterDistribution(alph *Alphabet) *LetterDistribution
func SpanishLetterDistribution ¶
func SpanishLetterDistribution(alph *Alphabet) *LetterDistribution
func (*LetterDistribution) MakeBag ¶
func (ld *LetterDistribution) MakeBag(randSource *rand.Rand) *Bag
MakeBag returns a bag of tiles.
func (*LetterDistribution) NumTotalTiles ¶ added in v0.4.0
func (ld *LetterDistribution) NumTotalTiles() int
func (*LetterDistribution) Score ¶ added in v0.4.0
func (ld *LetterDistribution) 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.
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) IntrinsicTileIdx ¶ added in v0.2.11
func (ml MachineLetter) IntrinsicTileIdx() (MachineLetter, bool)
IntrinsicTileIdx returns the index that this tile would have in a rack's LetArr. If it is not a letter (for example a played-thru marker) will return false as the second arg. It essentially checks whether the relevant ml is an actual played tile or not.
func (MachineLetter) IsBlanked ¶
func (ml MachineLetter) IsBlanked() bool
IsBlanked returns true if this is the blank version of a letter.
func (MachineLetter) IsPlayedTile ¶ added in v0.2.11
func (ml MachineLetter) IsPlayedTile() bool
IsPlayedTile returns true if this represents a tile that was actually played on the board. It has to be an assigned blank or a letter, not a played-through-marker.
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) Bytes ¶ added in v0.2.11
func (mw MachineWord) Bytes() []byte
Bytes converts the machine word to bytes. Also useful for hashing purposes.
func (MachineWord) Score ¶
func (mw MachineWord) Score(ld *LetterDistribution) int
Score returns the score of this word given the ld.
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) Has ¶ added in v0.4.4
func (r *Rack) Has(letter MachineLetter) bool
func (*Rack) Hashable ¶ added in v0.2.11
Hashable returns a hashable representation of this rack, that is not necessarily user-friendly.
func (*Rack) ScoreOn ¶
func (r *Rack) ScoreOn(ld *LetterDistribution) int
ScoreOn returns the total score of the tiles on this rack.
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() MachineWord
TilesOn returns the MachineLetters of the rack's current tiles. It is alphabetized.
type Word ¶
type Word struct { Word string Dist *LetterDistribution // contains filtered or unexported fields }