Crate rs_wordle_solver

Source
Expand description

Provides tools to algorithmically select the answer to a game of Wordle.

§Quick start

§Solving a game in one function

use rs_wordle_solver::*;

// Construct a WordBank to select guesses from.
let bank = WordBank::from_iterator(&["abc", "bcd", "def"])?;
// Construct a guesser.
let guesser = RandomGuesser::new(bank);
// Play the game.
let max_number_of_guesses = 3;
let objective = "bcd";
let result = play_game_with_guesser(objective, max_number_of_guesses, guesser);

assert!(matches!(result, GameResult::Success(_guesses_made)));

§Solving a game interactively

use rs_wordle_solver::*;

// Construct a WordBank to select guesses from.
let bank = WordBank::from_iterator(&["abc", "bcd", "def"])?;
// Construct a guesser.
let mut guesser = RandomGuesser::new(bank);

// Take a guess
let objective = "abc";
let guess = guesser.select_next_guess().unwrap();

// Get the results
let results = get_result_for_guess(objective, &guess)?;

// Update the guesser
guesser.update(&results)?;

// Repeat!
let guess = guesser.select_next_guess().unwrap();

// ...

§Solving algorithms

See the implementations of Guesser for more information on the available guessing algorithms.

If you want to implement your own algorithm, the easiest place to start is likely by implementing the scorers::WordScorer trait, and using this with MaxScoreGuesser. There are additional helpful utilities for implementing your own algorithms in the details mod.

Modules§

details
Internals and other things that may be useful if you want to implement your own Wordle solving algorithms.
scorers
Scorers for determining which word is the best guess.

Structs§

GameData
The data from a game that was played.
GuessResult
The result of a single word guess.
MaxScoreGuesser
Selects the next guess that maximizes the score according to the owned scorer.
RandomGuesser
Guesses at random from the possible words that meet the restrictions.
ScoredGuess
Represents a guess with a ‘score’ estimating how useful the guess is. Higher scores are better.
TurnData
Data about a single turn of a Wordle game.
WordBank
Contains all the possible words for a Wordle game.

Enums§

GameResult
Whether the game was won or lost by the guesser.
GuessFrom
Indicates which set of words to guess from. See MaxScoreGuesser::new().
LetterResult
The result of a given letter at a specific location. There is some complexity here when a letter appears in a word more than once. See GuessResult for more details.
WordleError
Indicates that an error occurred while trying to guess the objective word.

Traits§

Guesser
Guesses words in order to solve a single Wordle.

Functions§

get_result_for_guess
Determines the result of the given guess when applied to the given objective.
play_game_with_guesser
Attempts to guess the given word within the maximum number of guesses, using the given word guesser.