generated from PlexSheep/rs-base
structure of Game (very cool)
cargo devel CI / cargo CI (push) Failing after 38s
Details
cargo devel CI / cargo CI (push) Failing after 38s
Details
my commits are super professional
This commit is contained in:
parent
8a38b9ec6f
commit
6c267b66a5
17
Cargo.toml
17
Cargo.toml
|
@ -10,16 +10,25 @@ readme = "README.md"
|
|||
homepage = "https://git.cscherr.de/PlexSheep/wordle-analyzer"
|
||||
repository = "https://git.cscherr.de/PlexSheep/wordle-analyzer"
|
||||
keywords = ["wordle", "benchmark"]
|
||||
default-run = "wordle"
|
||||
default-run = "wordlec"
|
||||
|
||||
[features]
|
||||
default = ["game", "bench"]
|
||||
default = ["game", "bench", "tui"]
|
||||
game = []
|
||||
tui = ["game"]
|
||||
bench = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.81"
|
||||
clap = { version = "4.5.3", features = ["derive"] }
|
||||
libpt = "0.4.2"
|
||||
|
||||
[[bin]]
|
||||
name = "cliwordle"
|
||||
path = "src/bin/cliwordle.rs"
|
||||
name = "wordlec"
|
||||
path = "src/bin/game/cli.rs"
|
||||
required-features = ["game"]
|
||||
|
||||
[[bin]]
|
||||
name = "wordlet"
|
||||
path = "src/bin/game/tui.rs"
|
||||
required-features = ["tui", "game"]
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
unimplemented!();
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
use clap::Parser;
|
||||
use libpt::log::*;
|
||||
use wordle_analyzer::{game,self};
|
||||
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
#[command(version, about, long_about, author)]
|
||||
struct Cli {
|
||||
/// precompute all possibilities for better performance at runtime
|
||||
#[arg(short, long)]
|
||||
precompute: bool,
|
||||
/// how long should the word be?
|
||||
#[arg(short, long, default_value_t = wordle_analyzer::DEFAULT_WORD_LENGTH)]
|
||||
length: usize,
|
||||
/// how many times can we guess?
|
||||
#[arg(short, long, default_value_t = wordle_analyzer::DEFAULT_MAX_STEPS)]
|
||||
max_steps: usize
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
Logger::build_mini(Some(Level::TRACE))?;
|
||||
debug!("dumping CLI: {:#?}", cli);
|
||||
|
||||
let game = game::Game::builder()
|
||||
.length(cli.length)
|
||||
.precompute(cli.precompute).build()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_word(cli: &Cli) -> String {
|
||||
let mut word = String::new();
|
||||
|
||||
todo!("get user input");
|
||||
todo!("validate user input");
|
||||
|
||||
assert_eq!(word.len(), cli.length);
|
||||
word
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
pub struct Game {
|
||||
length: usize,
|
||||
precompute: bool,
|
||||
max_steps: usize,
|
||||
step: usize,
|
||||
solution: String
|
||||
}
|
||||
|
||||
impl Game {
|
||||
/// get a new [`GameBuilder`]
|
||||
pub fn builder() -> GameBuilder {
|
||||
GameBuilder::default()
|
||||
}
|
||||
/// Create a [Game] of wordle
|
||||
///
|
||||
/// This method will load the wordlist, determine if a word may be used as a solution for a
|
||||
/// game, and select a solution at random.
|
||||
///
|
||||
/// It will also set a few values to their initial state.
|
||||
///
|
||||
/// Don't use this method directly, instead, make use of the [`GameBuilder`].
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if .
|
||||
pub(crate) fn build(length: usize, precompute: bool, max_steps: usize) -> anyhow::Result<(Self)> {
|
||||
let mut game = Game {
|
||||
length, precompute, max_steps,
|
||||
step: 0,
|
||||
solution: String::default() // we actually set this later
|
||||
};
|
||||
|
||||
|
||||
// TODO: load wordlist of possible answers
|
||||
// TODO: select one as a solution at random
|
||||
// NOTE: The possible answers should be determined with a wordlist that has the
|
||||
// frequencies/probabilities of the words. We then use a sigmoid function to determine if a
|
||||
// word can be a solution based on that value. Only words above some threshold of
|
||||
// commonness will be available as solutions then. Next, we choose one of the allowed words
|
||||
// randomly.
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Game {
|
||||
fn default() -> Self {
|
||||
GameBuilder::default()
|
||||
.build()
|
||||
.expect("could not build game with defaults")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GameBuilder {
|
||||
length: usize,
|
||||
precompute: bool,
|
||||
max_steps: usize
|
||||
}
|
||||
|
||||
impl GameBuilder {
|
||||
/// build a [`Game`] with the stored configuration
|
||||
pub fn build(self) -> anyhow::Result<Game> {
|
||||
let game: Game = Game::build(self.length, self.precompute, self.max_steps)?;
|
||||
Ok(game)
|
||||
}
|
||||
|
||||
/// Sets the precompute of this [`GameBuilder`].
|
||||
pub fn precompute(mut self, precompute: bool) -> Self {
|
||||
self.precompute = precompute;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the length of this [`GameBuilder`].
|
||||
pub fn length(mut self, length: usize) -> Self {
|
||||
self.length = length;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GameBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
length: super::DEFAULT_WORD_LENGTH,
|
||||
precompute: false,
|
||||
max_steps: super::DEFAULT_MAX_STEPS
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
pub const DEFAULT_WORD_LENGTH: usize = 5;
|
||||
pub const DEFAULT_MAX_STEPS: usize = 6;
|
||||
|
||||
pub mod game;
|
||||
pub mod solvers;
|
Loading…
Reference in New Issue