features and docs

This commit is contained in:
Christoph J. Scherr 2024-03-21 11:44:02 +01:00
parent 76453dedf6
commit 837a28fb37
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
3 changed files with 53 additions and 3 deletions

View File

@ -13,8 +13,9 @@ keywords = ["wordle", "benchmark"]
default-run = "wordlec"
[features]
default = ["game", "bench", "tui"]
default = ["game", "bench", "tui", "solvers"]
game = []
solvers = []
tui = ["game"]
bench = []

View File

@ -43,6 +43,38 @@ impl Game {
}
}
/// Build and Configure a [`Game`]
///
/// This struct is used to build and configure a [`Game`] of Wordle.
///
/// ## Examples
///
/// [`GameBuilder`] implements [`Default`]. [`Game::builder`] uses [`GameBuilder::default`].
/// You don't need to set custom values if you accept the defaults.
///
/// ```
/// # use wordle_analyzer::game::*;
/// # use anyhow::Result;
/// # fn main() -> Result<()> {
/// let game: Game = GameBuilder::default()
/// .build()?;
/// # Ok(())
/// # }
/// ```
///
/// ```
/// # use wordle_analyzer::game::*;
/// # use anyhow::Result;
/// # fn main() -> Result<()> {
/// let game: Game = Game::builder()
/// .length(5)
/// .precompute(false)
/// .max_steps(6)
/// .build()?;
/// # Ok(())
/// # }
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct GameBuilder {
length: usize,
@ -57,17 +89,30 @@ impl GameBuilder {
Ok(game)
}
/// Sets the precompute of this [`GameBuilder`].
/// Should we pre compute all possible answers? This will make startup significantly more
/// expensive, but reduce the computing time while playing.
///
/// Default is [`false`]
pub fn precompute(mut self, precompute: bool) -> Self {
self.precompute = precompute;
self
}
/// Sets the length of this [`GameBuilder`].
/// Set the length of words for the game
///
/// Default is [`super::DEFAULT_WORD_LENGTH`]
pub fn length(mut self, length: usize) -> Self {
self.length = length;
self
}
/// Set the amount of guesses per game
///
/// Default is [`super::DEFAULT_MAX_STEPS`]
pub fn max_steps(mut self, max_steps: usize) -> Self {
self.max_steps = max_steps;
self
}
}
impl Default for GameBuilder {

View File

@ -7,5 +7,9 @@ pub const DEFAULT_WORD_LENGTH: usize = 5;
/// Default amount of guesses per game
pub const DEFAULT_MAX_STEPS: usize = 6;
#[cfg(feature = "game")]
pub mod game;
#[cfg(feature = "solvers")]
pub mod solvers;
#[cfg(feature = "bench")]
pub mod bench;