rs_wordle_solver/lib.rs
1//! Provides tools to algorithmically select the answer to a game of [Wordle](https://www.nytimes.com/games/wordle/index.html).
2//!
3//! ## Quick start
4//!
5//! ### Solving a game in one function
6//!
7//! ```
8//! use rs_wordle_solver::*;
9//!
10//! // Construct a WordBank to select guesses from.
11//! let bank = WordBank::from_iterator(&["abc", "bcd", "def"])?;
12//! // Construct a guesser.
13//! let guesser = RandomGuesser::new(bank);
14//! // Play the game.
15//! let max_number_of_guesses = 3;
16//! let objective = "bcd";
17//! let result = play_game_with_guesser(objective, max_number_of_guesses, guesser);
18//!
19//! assert!(matches!(result, GameResult::Success(_guesses_made)));
20//! # Ok::<(), WordleError>(())
21//! ```
22//!
23//! ### Solving a game interactively
24//!
25//! ```
26//! use rs_wordle_solver::*;
27//!
28//! // Construct a WordBank to select guesses from.
29//! let bank = WordBank::from_iterator(&["abc", "bcd", "def"])?;
30//! // Construct a guesser.
31//! let mut guesser = RandomGuesser::new(bank);
32//!
33//! // Take a guess
34//! let objective = "abc";
35//! let guess = guesser.select_next_guess().unwrap();
36//!
37//! // Get the results
38//! let results = get_result_for_guess(objective, &guess)?;
39//!
40//! // Update the guesser
41//! guesser.update(&results)?;
42//!
43//! // Repeat!
44//! let guess = guesser.select_next_guess().unwrap();
45//!
46//! // ...
47//!
48//! # Ok::<(), WordleError>(())
49//! ```
50//!
51//! ## Solving algorithms
52//!
53//! See the implementations of [`Guesser`] for more information on the available guessing
54//! algorithms.
55//!
56//! If you want to implement your own algorithm, the easiest place to start is likely by
57//! implementing the [`scorers::WordScorer`] trait, and using this with [`MaxScoreGuesser`]. There
58//! are additional helpful utilities for implementing your own algorithms in the [`details`] mod.
59
60mod data;
61mod engine;
62mod restrictions;
63mod results;
64
65pub use data::WordBank;
66pub use engine::*;
67pub use results::{
68 get_result_for_guess, GameData, GameResult, GuessResult, LetterResult, TurnData, WordleError,
69};
70
71/// Scorers for determining which word is the best guess.
72///
73/// Each scorer implements the [`scorers::WordScorer`] trait. Scorers can be used with the
74/// [`MaxScoreGuesser`].
75pub mod scorers;
76
77/// Internals and other things that may be useful if you want to implement your own Wordle solving
78/// algorithms.
79pub mod details {
80 pub use crate::data::LocatedLetter;
81 pub use crate::data::WordCounter;
82 pub use crate::data::WordTracker;
83 pub use crate::restrictions::*;
84 pub use crate::results::CompressedGuessResult;
85 pub use crate::results::MAX_LETTERS_IN_COMPRESSED_GUESS_RESULT;
86}