summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games/Game
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Bot/Games/Game')
-rw-r--r--lib/Bot/Games/Game/24.pm5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/Bot/Games/Game/24.pm b/lib/Bot/Games/Game/24.pm
index df317c6..ef87734 100644
--- a/lib/Bot/Games/Game/24.pm
+++ b/lib/Bot/Games/Game/24.pm
@@ -25,6 +25,11 @@ sub _init {
sub turn {
my $self = shift;
my ($player, $expr) = @_;
+
+ my $numbers = join ',', sort split(/[-\+\*\/\(\)]+/, $expr);
+ my $solution = join ',', sort split(' ', $self->state);
+ return "invalid numbers" unless $numbers eq $solution;
+
my $eval = $self->_evaluate($expr);
if ($eval == 24) {
$self->is_over("$player wins!");