Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
bf2afafbf5 |
10
Cargo.toml
10
Cargo.toml
|
|
@ -13,3 +13,13 @@ strip = true
|
||||||
lto = true
|
lto = true
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
||||||
|
[profile.zip]
|
||||||
|
inherits = "release"
|
||||||
|
opt-level = "z"
|
||||||
|
debug = false
|
||||||
|
strip = true
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
incremental = false
|
||||||
|
panic = "abort"
|
||||||
|
|
|
||||||
10
src/cli.rs
10
src/cli.rs
|
|
@ -2,8 +2,6 @@ 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 {
|
||||||
|
|
@ -12,14 +10,6 @@ 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::{Penalty, TotalScore};
|
use crate::word_representation::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(Penalty::Set(0));
|
let weights = wl.make_weights();
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
cli::Commands::Solve {
|
cli::Commands::Solve {
|
||||||
|
|
|
||||||
|
|
@ -44,39 +44,20 @@ 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(penalty: Penalty) -> Self {
|
pub(crate) fn new() -> 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 {
|
||||||
|
|
@ -90,10 +71,7 @@ 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) {
|
||||||
match self.penalty {
|
self.setweight(letter, 0);
|
||||||
Penalty::Set(v) => self.setweight(letter, v),
|
|
||||||
Penalty::Add(v) => self.addweight(letter, v),
|
|
||||||
}
|
|
||||||
found.push(letter)
|
found.push(letter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,13 +142,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, penalty: Penalty) -> Weightlist {
|
pub(crate) fn make_weights(&self) -> Weightlist {
|
||||||
let mut weights = Weightlist::new(penalty);
|
let mut weights = Weightlist::new();
|
||||||
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.incweight(c);
|
weights.addweight(c);
|
||||||
found.push(c);
|
found.push(c);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -243,6 +221,7 @@ 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,6 +836,7 @@ arian
|
||||||
arias
|
arias
|
||||||
arica
|
arica
|
||||||
ariel
|
ariel
|
||||||
|
aries
|
||||||
arils
|
arils
|
||||||
arioi
|
arioi
|
||||||
arion
|
arion
|
||||||
|
|
@ -2809,6 +2810,7 @@ claes
|
||||||
clags
|
clags
|
||||||
claik
|
claik
|
||||||
claim
|
claim
|
||||||
|
clamb
|
||||||
clame
|
clame
|
||||||
clamp
|
clamp
|
||||||
clams
|
clams
|
||||||
|
|
@ -3403,6 +3405,7 @@ cylix
|
||||||
cymae
|
cymae
|
||||||
cymar
|
cymar
|
||||||
cymas
|
cymas
|
||||||
|
cymba
|
||||||
cymes
|
cymes
|
||||||
cymol
|
cymol
|
||||||
cymru
|
cymru
|
||||||
|
|
@ -4224,6 +4227,7 @@ dwell
|
||||||
dwelt
|
dwelt
|
||||||
dwine
|
dwine
|
||||||
dwyer
|
dwyer
|
||||||
|
dwyka
|
||||||
dyads
|
dyads
|
||||||
dyaks
|
dyaks
|
||||||
dyaus
|
dyaus
|
||||||
|
|
@ -6569,6 +6573,7 @@ hullo
|
||||||
hulls
|
hulls
|
||||||
hully
|
hully
|
||||||
human
|
human
|
||||||
|
humbo
|
||||||
humet
|
humet
|
||||||
humic
|
humic
|
||||||
humid
|
humid
|
||||||
|
|
@ -9815,6 +9820,7 @@ orcin
|
||||||
order
|
order
|
||||||
ordos
|
ordos
|
||||||
oread
|
oread
|
||||||
|
oreas
|
||||||
oreos
|
oreos
|
||||||
orfes
|
orfes
|
||||||
orgal
|
orgal
|
||||||
|
|
|
||||||
Reference in New Issue