mirror of
https://gitlab.com/MisterBiggs/wordle-rs.git
synced 2025-06-16 14:06:40 +00:00
begin implementing cli
This commit is contained in:
parent
68685da37d
commit
4ded67039a
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -2,6 +2,15 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "owo-colors"
|
||||||
|
version = "3.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "20448fd678ec04e6ea15bbe0476874af65e98a01515d667aa49f1434dc44ebf4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wordlers"
|
name = "wordlers"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"owo-colors",
|
||||||
|
]
|
||||||
|
@ -6,3 +6,4 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
owo-colors = "3.2.0"
|
||||||
|
81
src/main.rs
81
src/main.rs
@ -5,51 +5,57 @@ fn main() {
|
|||||||
.expect("Cannot read file.")
|
.expect("Cannot read file.")
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(|&word| word.trim().len() == 5)
|
.filter(|&word| word.trim().len() == 5)
|
||||||
.map(|word| word.trim().to_owned().to_lowercase())
|
.map(|word| word.trim().to_lowercase())
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
let needed = "kilis";
|
let mut exact = "ak..";
|
||||||
let banned = "pourane";
|
let mut close: Vec<(char, usize)> = vec![('a', 2)];
|
||||||
|
let mut banned = "ponieu";
|
||||||
// let mut count: usize = 0;
|
|
||||||
|
|
||||||
words = words
|
words = words
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|word| check_valid(word, needed, banned))
|
.filter(|&word| check_exact(word, exact))
|
||||||
|
.filter(|&word| check_close(word, &close))
|
||||||
|
.filter(|&word| check_banned(word, banned))
|
||||||
.map(|word| word.to_owned())
|
.map(|word| word.to_owned())
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
let values = words
|
print_guesses(words);
|
||||||
.iter()
|
// let mut count: usize = 0;
|
||||||
.map(|word| word_value(word))
|
|
||||||
.collect::<Vec<usize>>();
|
|
||||||
|
|
||||||
let &max = values.iter().max().unwrap();
|
|
||||||
|
|
||||||
println!("Total Words: {}\nBest Guesses:", words.len());
|
|
||||||
for (word, value) in words.iter().zip(values) {
|
|
||||||
if value == max {
|
|
||||||
println!("{}", word);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_valid(word: &String, needed: &str, banned: &str) -> bool {
|
fn check_exact(word: &String, exact: &str) -> bool {
|
||||||
check_banned(word, banned) && check_needed(word, needed)
|
assert!(
|
||||||
|
word.len() == exact.len(),
|
||||||
|
"Exact match string has invalid length!"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (w, e) in word.chars().into_iter().zip(exact.chars()) {
|
||||||
|
if e == '.' {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_banned(word: &String, banned: &str) -> bool {
|
if w != e {
|
||||||
for b in banned.chars() {
|
|
||||||
if word.contains(b) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_needed(word: &String, needed: &str) -> bool {
|
fn check_close(word: &String, close: &Vec<(char, usize)>) -> bool {
|
||||||
for need in needed.chars() {
|
let mut w = word.chars();
|
||||||
if !word.contains(need) {
|
|
||||||
|
for (character, index) in close {
|
||||||
|
if character.to_owned() == w.nth(index - 1).unwrap() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_banned(word: &String, banned: &str) -> bool {
|
||||||
|
for b in banned.chars() {
|
||||||
|
if word.contains(b) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,3 +80,24 @@ fn word_value(word: &String) -> usize {
|
|||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_guesses(words: Vec<String>) {
|
||||||
|
if words.is_empty() {
|
||||||
|
println!("Out of guesses!!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let values = words
|
||||||
|
.iter()
|
||||||
|
.map(|word| word_value(word))
|
||||||
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
|
let &max = values.iter().max().unwrap();
|
||||||
|
|
||||||
|
println!("Total Words: {}\nBest Guesses:", words.len());
|
||||||
|
for (word, value) in words.iter().zip(values) {
|
||||||
|
if value == max {
|
||||||
|
println!("{}", word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user