Compare commits

..

1 Commits

Author SHA1 Message Date
Dandaedre bf2afafbf5 Updates cargo 2025-10-06 00:48:13 +02:00
5 changed files with 25 additions and 40 deletions

View File

@ -13,3 +13,13 @@ strip = true
lto = true
codegen-units = 1
panic = "abort"
[profile.zip]
inherits = "release"
opt-level = "z"
debug = false
strip = true
lto = true
codegen-units = 1
incremental = false
panic = "abort"

View File

@ -2,8 +2,6 @@ use std::fmt::Display;
use clap::{Parser, Subcommand, ValueEnum};
use crate::word_representation::Penalty;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub(crate) struct Args {
@ -12,14 +10,6 @@ pub(crate) struct Args {
#[arg(long, short, value_enum, default_value_t=Wordtypes::Full)]
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)]

View File

@ -5,7 +5,7 @@
// #![allow(dead_code)]
use crate::cli::Args;
use crate::solver::{backtrack_best, create_list_best};
use crate::word_representation::{Penalty, TotalScore};
use crate::word_representation::TotalScore;
use clap::Parser;
use regex::Regex;
@ -19,7 +19,7 @@ fn main_dispatch(args: Args) {
cli::Wordtypes::Full => 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 {
cli::Commands::Solve {

View File

@ -44,39 +44,20 @@ impl PartialOrd for Word {
#[derive(Default, Eq, PartialEq, Debug, Clone)]
pub(crate) struct Weightlist {
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 {
pub(crate) fn new(penalty: Penalty) -> Self {
pub(crate) fn new() -> Self {
Self {
weights: vec![0; 26],
penalty,
}
}
pub(crate) fn incweight(&mut self, c: char) {
pub(crate) fn addweight(&mut self, c: char) {
self.weights[c as usize - 'a' as usize] += 1;
}
pub(crate) fn setweight(&mut self, c: char, val: isize) {
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)]
pub(crate) fn getid(&self, id: usize) -> isize {
@ -90,10 +71,7 @@ impl Weightlist {
let mut found = vec![];
for letter in guess.origin.chars() {
if !found.contains(&letter) {
match self.penalty {
Penalty::Set(v) => self.setweight(letter, v),
Penalty::Add(v) => self.addweight(letter, v),
}
self.setweight(letter, 0);
found.push(letter)
}
}
@ -164,13 +142,13 @@ impl Wordlist {
/// Create a weightlist from the wordlist
///
/// Calling this method DOES NOT update the Weight of words
pub(crate) fn make_weights(&self, penalty: Penalty) -> Weightlist {
let mut weights = Weightlist::new(penalty);
pub(crate) fn make_weights(&self) -> Weightlist {
let mut weights = Weightlist::new();
self.inner.iter().for_each(|w| {
let mut found = Vec::new();
w.origin.chars().for_each(|c| {
if !found.contains(&c) {
weights.incweight(c);
weights.addweight(c);
found.push(c);
}
});
@ -243,6 +221,7 @@ impl TotalScore {
}
/// Add a word to the score
// TODO: Remove word ?
pub(crate) fn add_word(&mut self, word: Word) {
self.score += word.weight;
self.weights.remove_word(&word);

View File

@ -836,6 +836,7 @@ arian
arias
arica
ariel
aries
arils
arioi
arion
@ -2809,6 +2810,7 @@ claes
clags
claik
claim
clamb
clame
clamp
clams
@ -3403,6 +3405,7 @@ cylix
cymae
cymar
cymas
cymba
cymes
cymol
cymru
@ -4224,6 +4227,7 @@ dwell
dwelt
dwine
dwyer
dwyka
dyads
dyaks
dyaus
@ -6569,6 +6573,7 @@ hullo
hulls
hully
human
humbo
humet
humic
humid
@ -9815,6 +9820,7 @@ orcin
order
ordos
oread
oreas
oreos
orfes
orgal