Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
6874411672 |
10
src/cli.rs
10
src/cli.rs
|
|
@ -2,6 +2,8 @@ use std::fmt::Display;
|
||||||
|
|
||||||
use clap::{Parser, Subcommand, ValueEnum};
|
use clap::{Parser, Subcommand, ValueEnum};
|
||||||
|
|
||||||
|
use crate::word_representation::Penalty;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
pub(crate) struct Args {
|
pub(crate) struct Args {
|
||||||
|
|
@ -10,6 +12,14 @@ pub(crate) struct Args {
|
||||||
|
|
||||||
#[arg(long, short, value_enum, default_value_t=Wordtypes::Full)]
|
#[arg(long, short, value_enum, default_value_t=Wordtypes::Full)]
|
||||||
pub(crate) wordlist: Wordtypes,
|
pub(crate) wordlist: Wordtypes,
|
||||||
|
|
||||||
|
/// Duplicate letters are set to this value
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub(crate) set: isize,
|
||||||
|
|
||||||
|
/// Duplicate letters instead decrease the value by this amount
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub(crate) sub: isize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// #![allow(dead_code)]
|
// #![allow(dead_code)]
|
||||||
use crate::cli::Args;
|
use crate::cli::Args;
|
||||||
use crate::solver::{backtrack_best, create_list_best};
|
use crate::solver::{backtrack_best, create_list_best};
|
||||||
use crate::word_representation::TotalScore;
|
use crate::word_representation::{Penalty, TotalScore};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ fn main_dispatch(args: Args) {
|
||||||
cli::Wordtypes::Full => word_representation::load_full_words(),
|
cli::Wordtypes::Full => word_representation::load_full_words(),
|
||||||
// cli::Wordtypes::Mixed => word_representation::load_full_words(),
|
// cli::Wordtypes::Mixed => word_representation::load_full_words(),
|
||||||
});
|
});
|
||||||
let weights = wl.make_weights();
|
let weights = wl.make_weights(Penalty::Set(0));
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
cli::Commands::Solve {
|
cli::Commands::Solve {
|
||||||
|
|
|
||||||
|
|
@ -44,20 +44,39 @@ impl PartialOrd for Word {
|
||||||
#[derive(Default, Eq, PartialEq, Debug, Clone)]
|
#[derive(Default, Eq, PartialEq, Debug, Clone)]
|
||||||
pub(crate) struct Weightlist {
|
pub(crate) struct Weightlist {
|
||||||
pub(crate) weights: Vec<isize>,
|
pub(crate) weights: Vec<isize>,
|
||||||
|
penalty: Penalty,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A penalty value
|
||||||
|
#[derive(Eq, PartialEq, Debug, Clone)]
|
||||||
|
pub(crate) enum Penalty {
|
||||||
|
Set(isize),
|
||||||
|
Add(isize),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Penalty {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Set(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Weightlist {
|
impl Weightlist {
|
||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new(penalty: Penalty) -> Self {
|
||||||
Self {
|
Self {
|
||||||
weights: vec![0; 26],
|
weights: vec![0; 26],
|
||||||
|
penalty,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub(crate) fn addweight(&mut self, c: char) {
|
|
||||||
|
pub(crate) fn incweight(&mut self, c: char) {
|
||||||
self.weights[c as usize - 'a' as usize] += 1;
|
self.weights[c as usize - 'a' as usize] += 1;
|
||||||
}
|
}
|
||||||
pub(crate) fn setweight(&mut self, c: char, val: isize) {
|
pub(crate) fn setweight(&mut self, c: char, val: isize) {
|
||||||
self.weights[c as usize - 'a' as usize] = val;
|
self.weights[c as usize - 'a' as usize] = val;
|
||||||
}
|
}
|
||||||
|
pub(crate) fn addweight(&mut self, c: char, val: isize) {
|
||||||
|
self.weights[c as usize - 'a' as usize] += val;
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn getid(&self, id: usize) -> isize {
|
pub(crate) fn getid(&self, id: usize) -> isize {
|
||||||
|
|
@ -71,7 +90,10 @@ impl Weightlist {
|
||||||
let mut found = vec![];
|
let mut found = vec![];
|
||||||
for letter in guess.origin.chars() {
|
for letter in guess.origin.chars() {
|
||||||
if !found.contains(&letter) {
|
if !found.contains(&letter) {
|
||||||
self.setweight(letter, 0);
|
match self.penalty {
|
||||||
|
Penalty::Set(v) => self.setweight(letter, v),
|
||||||
|
Penalty::Add(v) => self.addweight(letter, v),
|
||||||
|
}
|
||||||
found.push(letter)
|
found.push(letter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,13 +164,13 @@ impl Wordlist {
|
||||||
/// Create a weightlist from the wordlist
|
/// Create a weightlist from the wordlist
|
||||||
///
|
///
|
||||||
/// Calling this method DOES NOT update the Weight of words
|
/// Calling this method DOES NOT update the Weight of words
|
||||||
pub(crate) fn make_weights(&self) -> Weightlist {
|
pub(crate) fn make_weights(&self, penalty: Penalty) -> Weightlist {
|
||||||
let mut weights = Weightlist::new();
|
let mut weights = Weightlist::new(penalty);
|
||||||
self.inner.iter().for_each(|w| {
|
self.inner.iter().for_each(|w| {
|
||||||
let mut found = Vec::new();
|
let mut found = Vec::new();
|
||||||
w.origin.chars().for_each(|c| {
|
w.origin.chars().for_each(|c| {
|
||||||
if !found.contains(&c) {
|
if !found.contains(&c) {
|
||||||
weights.addweight(c);
|
weights.incweight(c);
|
||||||
found.push(c);
|
found.push(c);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -221,7 +243,6 @@ impl TotalScore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a word to the score
|
/// Add a word to the score
|
||||||
// TODO: Remove word ?
|
|
||||||
pub(crate) fn add_word(&mut self, word: Word) {
|
pub(crate) fn add_word(&mut self, word: Word) {
|
||||||
self.score += word.weight;
|
self.score += word.weight;
|
||||||
self.weights.remove_word(&word);
|
self.weights.remove_word(&word);
|
||||||
|
|
|
||||||
|
|
@ -836,7 +836,6 @@ arian
|
||||||
arias
|
arias
|
||||||
arica
|
arica
|
||||||
ariel
|
ariel
|
||||||
aries
|
|
||||||
arils
|
arils
|
||||||
arioi
|
arioi
|
||||||
arion
|
arion
|
||||||
|
|
@ -2810,7 +2809,6 @@ claes
|
||||||
clags
|
clags
|
||||||
claik
|
claik
|
||||||
claim
|
claim
|
||||||
clamb
|
|
||||||
clame
|
clame
|
||||||
clamp
|
clamp
|
||||||
clams
|
clams
|
||||||
|
|
@ -3405,7 +3403,6 @@ cylix
|
||||||
cymae
|
cymae
|
||||||
cymar
|
cymar
|
||||||
cymas
|
cymas
|
||||||
cymba
|
|
||||||
cymes
|
cymes
|
||||||
cymol
|
cymol
|
||||||
cymru
|
cymru
|
||||||
|
|
@ -4227,7 +4224,6 @@ dwell
|
||||||
dwelt
|
dwelt
|
||||||
dwine
|
dwine
|
||||||
dwyer
|
dwyer
|
||||||
dwyka
|
|
||||||
dyads
|
dyads
|
||||||
dyaks
|
dyaks
|
||||||
dyaus
|
dyaus
|
||||||
|
|
@ -6573,7 +6569,6 @@ hullo
|
||||||
hulls
|
hulls
|
||||||
hully
|
hully
|
||||||
human
|
human
|
||||||
humbo
|
|
||||||
humet
|
humet
|
||||||
humic
|
humic
|
||||||
humid
|
humid
|
||||||
|
|
@ -9820,7 +9815,6 @@ orcin
|
||||||
order
|
order
|
||||||
ordos
|
ordos
|
||||||
oread
|
oread
|
||||||
oreas
|
|
||||||
oreos
|
oreos
|
||||||
orfes
|
orfes
|
||||||
orgal
|
orgal
|
||||||
|
|
|
||||||
Reference in New Issue