Compare commits

...
This repository has been archived on 2026-09-13. You can view files and clone it, but cannot push or open issues or pull requests.

1 Commits

Author SHA1 Message Date
Dandaedre 6874411672 Adds/Sub 2025-09-27 22:10:37 +02:00
4 changed files with 40 additions and 15 deletions

View File

@ -2,6 +2,8 @@ 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 {
@ -10,6 +12,14 @@ 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::TotalScore;
use crate::word_representation::{Penalty, 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();
let weights = wl.make_weights(Penalty::Set(0));
match args.command {
cli::Commands::Solve {

View File

@ -44,20 +44,39 @@ 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() -> Self {
pub(crate) fn new(penalty: Penalty) -> Self {
Self {
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;
}
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 {
@ -71,7 +90,10 @@ impl Weightlist {
let mut found = vec![];
for letter in guess.origin.chars() {
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)
}
}
@ -142,13 +164,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) -> Weightlist {
let mut weights = Weightlist::new();
pub(crate) fn make_weights(&self, penalty: Penalty) -> Weightlist {
let mut weights = Weightlist::new(penalty);
self.inner.iter().for_each(|w| {
let mut found = Vec::new();
w.origin.chars().for_each(|c| {
if !found.contains(&c) {
weights.addweight(c);
weights.incweight(c);
found.push(c);
}
});
@ -221,7 +243,6 @@ 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,7 +836,6 @@ arian
arias
arica
ariel
aries
arils
arioi
arion
@ -2810,7 +2809,6 @@ claes
clags
claik
claim
clamb
clame
clamp
clams
@ -3405,7 +3403,6 @@ cylix
cymae
cymar
cymas
cymba
cymes
cymol
cymru
@ -4227,7 +4224,6 @@ dwell
dwelt
dwine
dwyer
dwyka
dyads
dyaks
dyaus
@ -6573,7 +6569,6 @@ hullo
hulls
hully
human
humbo
humet
humic
humid
@ -9820,7 +9815,6 @@ orcin
order
ordos
oread
oreas
oreos
orfes
orgal