3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-14 07:59:33 +01:00

Plugin/Wordle: minor refactor

This commit is contained in:
Pragmatic Software 2024-03-07 08:59:41 -08:00
parent 435faaa18c
commit 440a72c71e
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
2 changed files with 13 additions and 15 deletions

View File

@ -27,7 +27,7 @@ use constant {
USAGE => 'Usage: wordle start [word length] | guess <word> | show | giveup',
NO_WORDLE => 'There is no Wordle yet. Use `wordle start` to begin a game.',
DEFAULT_LENGTH => 5,
MIN_LENGTH => 4,
MIN_LENGTH => 3,
MAX_LENGTH => 10,
WORDLIST => '/usr/share/dict/words',
};
@ -90,10 +90,10 @@ sub wordle($self, $context) {
return "Failed to load words: $@";
}
my @words = keys $self->{$channel}->{words}->%*;
my @words = keys $self->{$channel}->{words}->%*;
my @wordle = split //, $words[rand @words];
$self->{$channel}->{wordle} = \@wordle;
$self->{$channel}->{wordle} = \@wordle;
$self->{$channel}->{guesses} = [];
$self->{$channel}->{correct} = 0;
@ -115,7 +115,7 @@ sub wordle($self, $context) {
return "Wordle already solved. " . $self->show_wordle($channel);
}
return $self->guess_wordle($channel, uc $args[0]);
return $self->guess_wordle($channel, $args[0]);
}
default {
@ -133,7 +133,8 @@ sub load_words($self, $length) {
my %words;
while (chomp(my $line = <$fh>)) {
while (my $line = <$fh>) {
chomp $line;
next if $line !~ /^[a-z]+$/;
if (length $line == $length) {
@ -167,21 +168,18 @@ sub guess_wordle($self, $channel, $guess) {
my %seen;
my %correct;
foreach my $letter (@wordle) {
$count{$letter}++;
$seen{$letter} = 0;
$correct{$letter} = 0;
}
my @result;
my $correct = 0;
for (my $i = 0; $i < @wordle; $i++) {
$count{$wordle[$i]}++;
$seen{$wordle[$i]} = 0;
if ($guess[$i] eq $wordle[$i]) {
$correct{$guess[$i]}++;
}
}
my @result;
my $correct = 0;
for (my $i = 0; $i < @wordle; $i++) {
if ($guess[$i] eq $wordle[$i]) {
$seen{$guess[$i]}++;

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4707,
BUILD_REVISION => 4708,
BUILD_DATE => "2024-03-07",
};