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

Plugin/WordMorph: improve hints with ? in place of next letter change

This commit is contained in:
Pragmatic Software 2022-08-24 23:11:47 -07:00
parent d5c336c058
commit b9dc225763
2 changed files with 20 additions and 3 deletions

View File

@ -19,7 +19,7 @@ sub initialize {
$self->{pbot}->{commands}->add(
name => 'wordmorph',
help => 'Word Morph game',
help => 'Word Morph game! Solve a path between two words by changing one letter at a time: love > shot = love > lose > lost > loot > soot > shot.',
subref => sub { $self->wordmorph(@_) },
);
@ -68,7 +68,24 @@ sub wordmorph {
my @hints;
for (my $i = 0; $i < $self->{$channel}->{hint}; $i++) {
push @hints, $self->{$channel}->{morph}->[$i];
my $hint = '';
if ($i > 0) {
my $word1 = $self->{$channel}->{morph}->[$i - 1];
my $word2 = $self->{$channel}->{morph}->[$i];
for (0 .. length $word1) {
if (substr($word1, $_, 1) eq substr($word2, $_, 1)) {
$hint .= substr($word1, $_, 1);
} else {
$hint .= "?";
}
}
} else {
$hint = $self->{$channel}->{morph}->[$i];
}
push @hints, $hint;
}
my $hint = '_' x length $self->{$channel}->{morph}->[0];

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 => 4573,
BUILD_REVISION => 4574,
BUILD_DATE => "2022-08-24",
};