use scrable dict

This commit is contained in:
Matthieu Jolimaitre 2024-10-30 12:01:44 +01:00
parent 0abb5d1d62
commit 5c56fc7540
7 changed files with 1109073 additions and 15 deletions

336531
data/dict/gutenberg.txt Normal file

File diff suppressed because it is too large Load diff

386264
data/dict/scrable-2012.txt Normal file

File diff suppressed because it is too large Load diff

386264
data/scrable.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,7 @@ struct Args {
fn main() {
let args = Args::parse();
dbg!(&args);
let mut dict = dictionnary::gutenberg(7);
let mut dict = dictionnary::scrable(7);
// let dict = dictionnary::francais(7);
let count = if args.target.is_some() { 1 } else { args.count };
(0..count).for_each(|_| {

View file

@ -4,23 +4,22 @@ use rand::{seq::SliceRandom, thread_rng};
pub fn load(path: impl AsRef<Path>, width: usize) -> Vec<String> {
let content = fs::read_to_string(path).expect("Can read file.");
content
.lines()
.filter(|w| w.len() == width)
.map(|l| l.to_string())
.collect()
lines_of(width, &content)
}
pub fn francais(width: usize) -> Vec<String> {
let raw = include_str!("../data/francais.txt");
raw.lines()
.filter(|w| w.len() == width)
.map(|l| l.to_string())
.collect()
lines_of(width, include_str!("../data/francais.txt"))
}
pub fn gutenberg(width: usize) -> Vec<String> {
let raw = include_str!("../data/gutenberg.txt");
let mut res = raw
lines_of(width, include_str!("../data/gutenberg.txt"))
}
pub fn scrable(width: usize) -> Vec<String> {
lines_of(width, include_str!("../data/scrable.txt"))
}
fn lines_of(width: usize, content: &str) -> Vec<String> {
let mut res = content
.lines()
.filter(|w| w.len() == width)
.map(|l| l.to_string())

View file

@ -12,7 +12,7 @@ mod solve;
pub fn main() {
let (mut game, infos) = Proxy::init();
let dict = dictionnary::gutenberg(infos.len());
let dict = dictionnary::scrable(infos.len());
let mut solver = Grouping::new(dict.into_iter().filter(|w| matches(w, &infos)));
solver.learn(infos);
let result = game.play_all(solver, Some(6));

View file

@ -12,7 +12,7 @@ mod solve;
fn main() {
let first_arg = args().nth(1);
let dict = dictionnary::gutenberg(first_arg.clone().map(|w| w.len()).unwrap_or(7));
let dict = dictionnary::scrable(first_arg.clone().map(|w| w.len()).unwrap_or(7));
let random_word = || dict.choose(&mut rand::thread_rng()).unwrap().to_string();
let target = first_arg.unwrap_or_else(random_word);
dbg!(&target);