### Copyright (C) The Holy Ghost 2017
###This program is released under the GPL 3.0 and artistic license 2.0
+.
package HollyGameAI::AIInterface;
our @ISA = "Interface";
sub AIInterface {
my $class = shift;
$self = $class->SUPER::Interface(qw(@_)); ### e.g. qw(swim fly
+)
bless $self, $class;
}
### Copyright (C) The Holy Ghost 2017
###This program is released under the GPL 3.0 and artistic license 2.0
+.
package HollyGameAI::Factory;
our @ISA = "HollyGameAI::Interface";
sub Factory {
my $class = shift;
my $self = $class->SUPER::Interface(@_);
### include abstract method names
return bless $self, $class;
}
### Copyright (C) The Holy Ghost 2017
###This program is released under the GPL 3.0 and artistic license 2.0
+.
### with thanks to gregorovius from perlmonks
package HollyGameAI::Interface;
use Carp;
sub Interface {
my $class = shift;
my $self = {inheritors => (),
abstract_methods => shift, ### e.g. qw(swim fl
+y)
};
bless $self, $class;
}
sub import {
my $method = caller;
push (@{ $self->{inheritors}}, $method);
}
sub INIT {
my $bad = 0;
for my $class ($self->{inheritors}) {
for my $meth ($self->{abstract_methods}) {
no strict 'refs';
unless (defined &{"${class}::$meth"}) {
$bad = 1;
warn "HolyGameAI : Class $class should
+ implement
HolyGameAI Interface
but does not define $meth.\n";
}
}
}
croak "HollyGameAI : Source compilation aborted at interface b
+inding time\n" if $bad;
}
### Copyright (C) The Holy Ghost 2017
###This program is released under the GPL 3.0 and artistic license 2.0
+.
package HollyGameAI::MutualExclusiveAI;
use lib "../HollyGameAI";
use Factory;
sub MutualExclusiveAI {
my $class = shift;
my $self = { aiclass => HollyGameAI::Factory->Factory(@_) };
bless $self, $class;
}
### Copyright (C) The Holy Ghost 2017
###This program is released under the GPL 3.0 and artistic license 2.0
+.
package HollyGameAI::MutualExclusiveDeityAI;
our @ISA = "MutualExclusiveAI";
sub MutualExclusiveDeityAI {
my $class = shift;
my $self = $self->SUPER::MutualExclusiveAI(qw(cast donate swim
+ fly empower));
bless $self, $class;
}
### Copyright (C) The Holy Ghost 2017
###This program is released under the GPL 3.0 and artistic license 2.0
+.
package HollyGameAI::RNG;
### Random Number God, dice class
sub RNG {
my $class = shift;
my $self = { dx => 0 };
return bless $self, $class;
}
sub set {
my ($self, $dxx) = @_;
$self->{dx} = $dxx;
}
sub rollDX {
my $self = shift;
return rand($dx);
}
sub rollD1 {
my $self = shift;
return rand(1);
}
sub rollD3 {
my $self = shift;
return rand(3);
}
sub rollD6 {
my $self = shift;
return rand(6);
}
sub rollD10 {
my $self = shift;
return rand(10);
}
sub rollD20 {
my $self = shift;
return rand(20);
}
sub rollPreviousDX {
my $self = shift;
return rand($self->{dx});
}
sub roll {
my ($self, $dxx) = shift;
$self->set($dxx);
given ($self->{dx}) {
when ($_ = 0) {
return 0;
}
when ($_ == 1) {
return rollD1;
}
when ($_ == 3) {
return rollD3;
}
when ($_ == 6) {
return rollD6;
}
when ($_ == 10) {
return rollD10;
}
when ($_ == 20) {
return rollD20;
}
}
return 0;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|