summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Bot/Games/Game/Ghost.pm7
-rw-r--r--lib/Bot/Games/Game/Superghost.pm7
-rw-r--r--lib/Bot/Games/Game/Xghost.pm6
3 files changed, 17 insertions, 3 deletions
diff --git a/lib/Bot/Games/Game/Ghost.pm b/lib/Bot/Games/Game/Ghost.pm
index 740ecd2..29d75e9 100644
--- a/lib/Bot/Games/Game/Ghost.pm
+++ b/lib/Bot/Games/Game/Ghost.pm
@@ -93,11 +93,11 @@ command challenge => sub {
}
elsif ($self->valid_word($word)) {
$self->is_over(1);
- return "$word is a word! $challenger wins!";
+ return "$word is a word! $challenger loses!";
}
else {
$self->is_over(1);
- return "$word is not a word. $challenger loses!";
+ return "$word is not a word. $challenger wins!";
}
}
else {
@@ -128,7 +128,8 @@ command valid_move => sub {
command valid_word_from_state => sub {
my $self = shift;
my ($word) = @_;
- return uc($word) eq $self->state;
+ my $word_prefix = substr($word, 0, length($self->state));
+ return uc($word_prefix) eq $self->state;
};
command give_up => sub {
diff --git a/lib/Bot/Games/Game/Superghost.pm b/lib/Bot/Games/Game/Superghost.pm
index 0784698..d25bdf4 100644
--- a/lib/Bot/Games/Game/Superghost.pm
+++ b/lib/Bot/Games/Game/Superghost.pm
@@ -14,6 +14,13 @@ command valid_move => sub {
|| uc(substr($move, 1)) eq $self->state;
};
+command valid_word_from_state => sub {
+ my $self = shift;
+ my ($word) = @_;
+ my $state = $self->state;
+ return uc($word) =~ /\Q$state\E/;
+};
+
__PACKAGE__->meta->make_immutable;
no Bot::Games::OO;
diff --git a/lib/Bot/Games/Game/Xghost.pm b/lib/Bot/Games/Game/Xghost.pm
index 20dc19a..fcdc9a3 100644
--- a/lib/Bot/Games/Game/Xghost.pm
+++ b/lib/Bot/Games/Game/Xghost.pm
@@ -15,6 +15,12 @@ command valid_move => sub {
&& length($self->state) + 1 == length($move);
};
+command valid_word_from_state => sub {
+ my $self = shift;
+ my ($word) = @_;
+ return is_substring($self->state, uc($move));
+};
+
__PACKAGE__->meta->make_immutable;
no Bot::Games::OO;