42 lines
868 B
Rust
42 lines
868 B
Rust
use std::fmt::Display;
|
|
|
|
use crate::baggy::Tile;
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct Word {
|
|
tiles: Vec<Tile>,
|
|
}
|
|
|
|
impl Display for Word {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
for tile in &self.tiles {
|
|
write!(f, "{}", tile.letter())?;
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct Dictionary {
|
|
words: Vec<String>,
|
|
}
|
|
|
|
impl Dictionary {
|
|
pub fn new() -> Self {
|
|
let words = include_str!("../lexicons/CSW22.txt");
|
|
Dictionary {
|
|
words: words.lines().map(|x| x.to_string()).collect(),
|
|
}
|
|
}
|
|
|
|
/// Checks if a word is in the dictionary
|
|
pub fn contains(&self, word: Word) -> bool {
|
|
self.words.contains(&word.to_string())
|
|
}
|
|
}
|
|
|
|
impl Default for Dictionary {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|