From 9549858c7525d3a330d49bd1f8e353d8a9d6eb96 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 13 Jun 2025 08:11:46 +0200 Subject: Add steps into words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a way to make more granular the accounting of successful runs, so we don't give a word for done until we have run it successfully at least MAX_STEPS times in a row. Signed-off-by: Miquel Sabaté Solà --- crates/cli/src/run.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs index fe193b9..0cce6d6 100644 --- a/crates/cli/src/run.rs +++ b/crates/cli/src/run.rs @@ -1,6 +1,10 @@ use inquire::Text; use mihi::{select_random_words, update_success, Category, Word}; +// Maximum number of times a word has to be run in order to increase the number +// of successful runs. +const MAX_STEPS: usize = 5; + fn help(msg: Option<&str>) { if msg.is_some() { println!("{}.\n", msg.unwrap()); @@ -56,11 +60,15 @@ fn run_words(words: Vec, locale: Locale) -> i32 { let found = !answer.is_empty() && tr.split(',').any(|tr| tr.trim().contains(&answer)); if found { - let _ = update_success(&word, word.succeeded + 1); + if word.steps == MAX_STEPS - 1 { + let _ = update_success(&word, word.succeeded + 1, 0); + } else { + let _ = update_success(&word, word.succeeded, word.steps + 1); + } println!("\x1b[92m✓ {}\x1b[0m", tr); } else { if word.succeeded > 0 { - let _ = update_success(&word, word.succeeded - 1); + let _ = update_success(&word, word.succeeded - 1, 0); } println!("\x1b[91m❌{}\x1b[0m", tr); errors += 1; -- cgit v1.2.3