Initial commit
This commit is contained in:
commit
4148ec387b
11 changed files with 471529 additions and 0 deletions
42
src/dictionary.rs
Normal file
42
src/dictionary.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue