Better results
This commit is contained in:
61
src/main.rs
61
src/main.rs
@@ -72,7 +72,7 @@ fn main() {
|
|||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
|
|
||||||
words_score.sort_by(|a, b| {
|
words_score.sort_by(|a, b| {
|
||||||
if (a.1 - 0.5).abs() > (b.1 - 0.5).abs() {
|
if (a.1 - 0.0).abs() > (b.1 - 0.0).abs() {
|
||||||
std::cmp::Ordering::Greater
|
std::cmp::Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
std::cmp::Ordering::Less
|
std::cmp::Ordering::Less
|
||||||
@@ -119,8 +119,9 @@ fn get_score(word: &str, words: &[&str], hmap: &mut HashMap<u128, Result>) -> f3
|
|||||||
possible += score;
|
possible += score;
|
||||||
} else {
|
} else {
|
||||||
let c = get_number_rem_words(word, &res, &other_words);
|
let c = get_number_rem_words(word, &res, &other_words);
|
||||||
score_hmap.insert((word, res), c as f32 / l as f32);
|
let s = ((c as f32 / l as f32) - 0.5).abs();
|
||||||
possible += c as f32 / l as f32;
|
score_hmap.insert((word, res), s);
|
||||||
|
possible += s; // (c as f32 / l as f32) *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +198,26 @@ fn get_result(guess: &str, real_acc: &str, hmap: &mut HashMap<u128, Result>) ->
|
|||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if the second word passed could be a possible
|
||||||
|
/// solution, given a guessed word and the result.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// let result = is_possible(
|
||||||
|
/// "hucha",
|
||||||
|
/// &Result([
|
||||||
|
/// LetterState::Gray,
|
||||||
|
/// LetterState::Green,
|
||||||
|
/// LetterState::Green,
|
||||||
|
/// LetterState::Green,
|
||||||
|
/// LetterState::Green
|
||||||
|
/// ]),
|
||||||
|
/// "mucha"
|
||||||
|
/// )
|
||||||
|
///
|
||||||
|
/// assert!(result);
|
||||||
|
/// ```
|
||||||
fn is_possible(guessed: &str, result: &Result, to_check: &str) -> bool {
|
fn is_possible(guessed: &str, result: &Result, to_check: &str) -> bool {
|
||||||
let mut count_g: HashMap<char, u8> = HashMap::new();
|
let mut count_g: HashMap<char, u8> = HashMap::new();
|
||||||
let mut count_r: HashMap<char, u8> = HashMap::new();
|
let mut count_r: HashMap<char, u8> = HashMap::new();
|
||||||
@@ -256,6 +277,9 @@ fn hash_words(word: &str, real: &str) -> u128 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* --------------- TESTS --------------- */
|
/* --------------- TESTS --------------- */
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_result_aureo_manga() {
|
fn test_get_result_aureo_manga() {
|
||||||
@@ -465,3 +489,34 @@ fn test_is_possible_ulula_valor() {
|
|||||||
"valor"
|
"valor"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_remaining_words_opaco() {
|
||||||
|
let mut all_words: Vec<&str> = HashSet::from(WORDS).iter().copied().collect();
|
||||||
|
get_remaining_words(
|
||||||
|
"opaco",
|
||||||
|
&Result([
|
||||||
|
LetterState::Gray,
|
||||||
|
LetterState::Yellow,
|
||||||
|
LetterState::Gray,
|
||||||
|
LetterState::Gray,
|
||||||
|
LetterState::Yellow,
|
||||||
|
]),
|
||||||
|
&mut all_words,
|
||||||
|
);
|
||||||
|
let l1 = all_words.len();
|
||||||
|
get_remaining_words(
|
||||||
|
"opaco",
|
||||||
|
&Result([
|
||||||
|
LetterState::Gray,
|
||||||
|
LetterState::Yellow,
|
||||||
|
LetterState::Gray,
|
||||||
|
LetterState::Gray,
|
||||||
|
LetterState::Yellow,
|
||||||
|
]),
|
||||||
|
&mut all_words,
|
||||||
|
);
|
||||||
|
let l2 = all_words.len();
|
||||||
|
assert_eq!(l1, l2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user