summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games/Game/24.pm
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-01-14 22:11:50 -0500
committerdoy <doy@tozt.net>2009-01-14 22:11:50 -0500
commit114a22263299efccafbb7e62081171f5d497f7fe (patch)
treea729be94b0628985ac7944612e09aa25d7248812 /lib/Bot/Games/Game/24.pm
parent7c535a1574c5f1a28d7fdd0ff66186385c5d12db (diff)
downloadbot-games-114a22263299efccafbb7e62081171f5d497f7fe.tar.gz
bot-games-114a22263299efccafbb7e62081171f5d497f7fe.zip
convert the plugins over to using the command syntax
Diffstat (limited to 'lib/Bot/Games/Game/24.pm')
-rw-r--r--lib/Bot/Games/Game/24.pm21
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/Bot/Games/Game/24.pm b/lib/Bot/Games/Game/24.pm
index 8580d7b..039b551 100644
--- a/lib/Bot/Games/Game/24.pm
+++ b/lib/Bot/Games/Game/24.pm
@@ -10,16 +10,17 @@ has '+help' => (
has state => (
is => 'rw',
isa => 'Str',
+ command => 1,
);
-has _solution => (
+has solution => (
is => 'rw',
isa => 'Str',
);
-sub _init {
+sub init {
my $self = shift;
- return $self->_generate_24;
+ return $self->generate_24;
}
sub turn {
@@ -30,7 +31,7 @@ sub turn {
my $solution = join ',', sort split(' ', $self->state);
return "invalid numbers" unless $numbers eq $solution;
- my $eval = $self->_evaluate($expr);
+ my $eval = $self->evaluate($expr);
if ($eval == 24) {
$self->is_over("$player wins!");
return;
@@ -40,15 +41,15 @@ sub turn {
}
}
-sub give_up {
+command give_up => {
my $self = shift;
- $self->is_over($self->_solution);
+ $self->is_over($self->solution);
return;
-}
+};
my @ops = ('+', '-', '*', '/');
-sub _generate_24 {
+sub generate_24 {
my $self = shift;
my @nums = (24);
for (1..3) {
@@ -81,12 +82,12 @@ sub _generate_24 {
}
pop @nums;
shift @nums;
- $self->_solution(join '', @nums);
+ $self->solution(join '', @nums);
$self->state(join ' ', (grep { /\d/ } @nums));
return $self->state;
}
-sub _evaluate {
+sub evaluate {
my $self = shift;
my ($expr) = @_;
return 0 unless $expr =~ /^[-\d\+\*\/\(\)]+$/;