Documentation ¶
Index ¶
- Constants
- type CommonLettersStrategy
- type FilteringStrategy
- type Fixed
- type Freq
- type Game
- type Guess
- type HailMary
- type LetterCounts
- type Letters
- type Logger
- type Match
- type Naive
- type Scoring
- type ScoringCache
- type SelectiveScoring
- type Strategy
- type Top
- type UniqueLettersScoring
- type WeightedStrategy
- type Word
Constants ¶
const GuessLimit = 6
const WordLen = 5
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommonLettersStrategy ¶
type CommonLettersStrategy struct { }
CommonLettersStrategy is a strategy to choose words with the most common letters among the possible words. The hypothesis is that this will get more "yellow" squares, which is useful.
In practice this is a losing strategy.
func NewCommonLettersStrategy ¶
func NewCommonLettersStrategy() CommonLettersStrategy
func (CommonLettersStrategy) Weights ¶
func (x CommonLettersStrategy) Weights(words []Word) []float64
type FilteringStrategy ¶
type FilteringStrategy struct {
// contains filtered or unexported fields
}
func NewFilteringStrategy ¶
func NewFilteringStrategy(rng *rand.Rand, log Logger, fallback Strategy, threshold int, tiebreaker Scoring) *FilteringStrategy
Select the word that filters the most from the Possible game words. We can only know this based on the actual answer, so we estimate this by finding the average removed across all possible answers.
This is expensive, so we need another strategy for the early game when there are many possible answers.
This strategy helps the endgame where most letters are known, but the number of remaining possible words is higher than the number of remaining guesses. For example, if we play "arbas" and match "gg.gg", we have five possible words to try: "areas", "arias", "arnas", "arpas" and "arras" Trying them 1 by 1, we might run out of guesses. Guessing a word that can't be the answer, but that tests the uncommon letters between the words, can filter out possibilities more quickly. In the above case, "ferny" (where E, R and N) are in 3 of the 5 possible answers, guarantees finding the solution in 1 or 2 additional guesses.
func (FilteringStrategy) Guess ¶
func (n FilteringStrategy) Guess(game *Game) Word
type Fixed ¶
type Fixed struct {
// contains filtered or unexported fields
}
Play a fixed opening sequence before continuing with a follow-on strategy.
func FixedStrategy ¶
type Freq ¶
type Freq struct {
// contains filtered or unexported fields
}
type Game ¶
type Game struct { // Guesses made by the player, up to GuessLimit. Guesses []Guess // contains filtered or unexported fields }
func (Game) Guess ¶
Guess at the answer
TODO: the calculation of possible answers from the Match is not correct because this implementation assumes that Match yellow, "y", is set for _every_ matching instance of a character, when in fact it's only set for the first _n_ characters where _n_ is the number of instances of that character in the answer. For example, if I guess "geese" and the answer is "embed", I'll get a match of ".yy...", not ".yy.y" as this code expects.
func (Game) PossibleAnswers ¶
func (*Game) RemoveWord ¶
Don't try Guess the given word. Useful if the official game doesn't like a word that we choose.
type Guess ¶
Guess is the guess at an answer, along with the Match corresponding to that guess.
func (Guess) FilterPossible ¶
Filter a given list of words to include only those that are possible answers given this Guess.
func (Guess) GreenAllows ¶
Allows returns true if what we know from this Guess's Green squares allows the given answer.
func (Guess) MustInclude ¶
type HailMary ¶
type HailMary struct {
// contains filtered or unexported fields
}
func NewHailMary ¶
A meta strategy which uses a normal strategy for the first five guesses and a "hailmary" strategy for the final guess.
type LetterCounts ¶
type LetterCounts [26]byte
func (*LetterCounts) Add ¶
func (lc *LetterCounts) Add(c byte)
func (LetterCounts) Len ¶
func (lc LetterCounts) Len() (n int)
func (*LetterCounts) Remove ¶
func (lc *LetterCounts) Remove(c byte) bool
type Letters ¶
type Letters uint32
Letters is a set of wordle letters
func NewLetters ¶
NewLetters constructs a new Letters set, initialized with the given characters
type Logger ¶
type Logger interface {
Printf(template string, args ...interface{})
}
Generic debug logger used by some strategies. Compatible with the zerolog package.
type Match ¶
type Match struct {
// contains filtered or unexported fields
}
Match is the result of guessing the answer: each letter is colored one of: Grey when the letter is not in the answer; Yellow when the letter is in the answer; Green when the letter is in the answer, in this position.
func ParseMatch ¶
ParseMatch parses a 5-letter string describing the "match" of a guess with the answer.
type Scoring ¶
Scoring assigns a score, or "weight", to each word in the given array. The weights can be independent or dependent on the other words in the array.
type ScoringCache ¶
type ScoringCache struct {
// contains filtered or unexported fields
}
func NewScoringCache ¶
func NewScoringCache(scoring Scoring, words []Word) *ScoringCache
func (*ScoringCache) Weights ¶
func (c *ScoringCache) Weights(words []Word) []float64
type SelectiveScoring ¶
type SelectiveScoring struct { }
func NewSelectiveScale ¶
func NewSelectiveScale() SelectiveScoring
func (SelectiveScoring) Weights ¶
func (x SelectiveScoring) Weights(words []Word) []float64
type Top ¶
type Top struct {
// contains filtered or unexported fields
}
Top is a strategy to choose word the top words for a given score. If multiple words have the same score, choose randomly among them.
type UniqueLettersScoring ¶
type UniqueLettersScoring struct { }
func NewUniqueLettersScoring ¶
func NewUniqueLettersScoring() UniqueLettersScoring
func (UniqueLettersScoring) Weights ¶
func (n UniqueLettersScoring) Weights(words []Word) []float64
Weight words based on letter diversity
type WeightedStrategy ¶
type WeightedStrategy struct {
// contains filtered or unexported fields
}
WeightedStrategy is a strategy to choose words randomly, weighted by the score from a given scoring function.
func NewWeightedStrategy ¶
func NewWeightedStrategy(rng *rand.Rand, scoring Scoring, pow float64) *WeightedStrategy
func (*WeightedStrategy) Guess ¶
func (x *WeightedStrategy) Guess(game *Game) Word
type Word ¶
func (Word) LetterCounts ¶
func (w Word) LetterCounts() (lc LetterCounts)