update grouping solver avg ranking and add biggest ranking
This commit is contained in:
parent
40d06b0fa4
commit
0abb5d1d62
4 changed files with 43 additions and 15 deletions
2
loop.ts
2
loop.ts
|
@ -24,7 +24,7 @@ async function main() {
|
|||
}
|
||||
|
||||
function run() {
|
||||
const [cmd, ...args] = ["cargo", "run", "--release"];
|
||||
const [cmd, ...args] = ["cargo", "run", "--release", "--bin=proxy"];
|
||||
return new Deno.Command(cmd, { args, stdin: "inherit", stderr: "null" })
|
||||
.spawn();
|
||||
}
|
||||
|
|
|
@ -42,7 +42,9 @@ pub fn wordle_buffs_for(target: &str) -> (Vec<Option<InfoKind>>, Vec<Option<char
|
|||
(infos, letters, result)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn wordle_inner(target: &str, word: &str, buffs: &mut (Vec<Option<InfoKind>>, Vec<Option<char>>, Vec<Info>)) {
|
||||
#[inline]
|
||||
fn to_info(letter: &mut Option<char>, info: &mut Option<InfoKind>, kind: InfoKind) {
|
||||
*letter = None;
|
||||
info.insert(kind);
|
||||
|
|
|
@ -15,6 +15,6 @@ pub fn main() {
|
|||
let dict = dictionnary::gutenberg(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(5));
|
||||
let result = game.play_all(solver, Some(6));
|
||||
println!("{result:?}");
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Grouping {
|
|||
}
|
||||
|
||||
/// Gives a score to the word (lowest is best).
|
||||
fn rank_word(&self, word: &str) -> usize {
|
||||
fn rank_word_avg_groups(&self, word: &str) -> (usize, usize) {
|
||||
let mut groups = [0; 3];
|
||||
let mut buffs = wordle_buffs_for(word);
|
||||
for target in &self.candidates {
|
||||
|
@ -46,7 +46,28 @@ impl Grouping {
|
|||
}
|
||||
let min = groups.iter().min().unwrap();
|
||||
let max = groups.iter().max().unwrap();
|
||||
(max - min)
|
||||
let there_count = groups[2];
|
||||
(max - min, there_count)
|
||||
}
|
||||
|
||||
fn rank_word_biggest_group(&self, word: &str) -> (usize, usize) {
|
||||
let mut there_count = 0;
|
||||
let mut biggest = 0;
|
||||
let mut buffs = wordle_buffs_for(word);
|
||||
for target in &self.candidates {
|
||||
let mut groups = [0; 3];
|
||||
wordle_inner(target, word, &mut buffs);
|
||||
let infos = &buffs.2;
|
||||
for i in infos {
|
||||
match i.kind {
|
||||
InfoKind::Abscent => groups[0] += 1,
|
||||
InfoKind::Elsewhere => groups[1] += 1,
|
||||
InfoKind::There => (groups[2] += 1, there_count += 1).0,
|
||||
}
|
||||
}
|
||||
biggest = biggest.max(groups.into_iter().max().unwrap_or_default());
|
||||
}
|
||||
(biggest, there_count)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,12 +77,19 @@ impl Solver for Grouping {
|
|||
return self.candidates.first().cloned();
|
||||
}
|
||||
|
||||
self.dict
|
||||
let scored = self
|
||||
.dict
|
||||
.iter()
|
||||
.take(10_000)
|
||||
.take(100_000)
|
||||
.par_bridge()
|
||||
.map(|word| (word, self.rank_word(word)))
|
||||
.min_by_key(|(_, score)| *score)
|
||||
.map(|word| (word, self.rank_word_avg_groups(word)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let best_score = scored.iter().map(|(_, (s, _))| *s).min()?;
|
||||
scored
|
||||
.into_iter()
|
||||
.filter(|(_, (s, _))| *s == best_score)
|
||||
.max_by_key(|(_, (_, t))| *t)
|
||||
.map(|(w, _)| w.to_string())
|
||||
.or_else(|| self.candidates.first().cloned())
|
||||
}
|
||||
|
@ -77,8 +105,6 @@ impl Solver for Grouping {
|
|||
self.dict.remove(index);
|
||||
}
|
||||
self.candidates = self.candidates.drain(..).filter(|w| matches(w, &infos)).collect();
|
||||
dbg!(&self.candidates);
|
||||
dbg!(self.candidates.len());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,8 +147,8 @@ fn test_misc() {
|
|||
// assert!(grouping.rank_word("coton") > grouping.rank_word("abaca"));
|
||||
|
||||
let grouping = Grouping::new(["abregee", "amorcee", "marquee", "assuree", "separee"]);
|
||||
dbg!(grouping.rank_word("volitif"));
|
||||
dbg!(grouping.rank_word("amorcee"));
|
||||
dbg!(grouping.rank_word_avg_groups("volitif"));
|
||||
dbg!(grouping.rank_word_avg_groups("amorcee"));
|
||||
|
||||
let mut gut = gutenberg(7);
|
||||
dbg!(gut.len());
|
||||
|
@ -158,9 +184,9 @@ fn test_misc() {
|
|||
character: 't',
|
||||
},
|
||||
]);
|
||||
dbg!(grouping.rank_word("jouxtee"));
|
||||
dbg!(grouping.rank_word("jutions"));
|
||||
dbg!(grouping.rank_word("jaspine"));
|
||||
dbg!(grouping.rank_word_avg_groups("jouxtee"));
|
||||
dbg!(grouping.rank_word_avg_groups("jutions"));
|
||||
dbg!(grouping.rank_word_avg_groups("jaspine"));
|
||||
dbg!(grouping.guess());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue