diff options
author | doy <doy@tozt.net> | 2008-12-20 04:04:07 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2008-12-20 04:04:07 -0500 |
commit | 9be8b1d664ac58188793f5acf4beac3f268b815a (patch) | |
tree | 3f43aef53a2addfe5d12b88f972e421120ebe135 /lib/Bot/Games/Game/24.pm | |
parent | 950c53245c02d9c015b008e277abba8c524dc502 (diff) | |
download | bot-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.pm | 5 |
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!"); |