summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games/Game/24.pm
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2008-12-20 04:04:07 -0500
committerdoy <doy@tozt.net>2008-12-20 04:04:07 -0500
commit9be8b1d664ac58188793f5acf4beac3f268b815a (patch)
tree3f43aef53a2addfe5d12b88f972e421120ebe135 /lib/Bot/Games/Game/24.pm
parent950c53245c02d9c015b008e277abba8c524dc502 (diff)
downloadbot-games-9be8b1d664ac58188793f5acf4beac3f268b815a.tar.gz
bot-games-9be8b1d664ac58188793f5acf4beac3f268b815a.zip
make sure the numbers used in the proposed solution for 24 are the same as the ones given in the problem
Diffstat (limited to 'lib/Bot/Games/Game/24.pm')
-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!");