| 1 | ### A subclass for using an Attacking/DefendingFunctor with a | ||
| 2 | ### Metropolis-Hastings algorithm. | ||
| 3 | |||
| 4 | sub new { | ||
| 5 | my ($class) = @_; | ||
| 6 | |||
| 7 | $self = { lowerbound => 0.25, upperbound => 0.4 }; | ||
| 8 | |||
| 9 | bless $self, $class; | ||
| 10 | }; | ||
| 11 | |||
| 12 | sub setLower { | ||
| 13 | my ($self, $lb) = @_; | ||
| 14 | |||
| 15 | $self->{lowerbound} = $lb; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub setUpper { | ||
| 19 | my ($self, $ub) = @_; | ||
| 20 | |||
| 21 | $self->{upperbound} = $ub; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub do { | ||
| 25 | my ($self, $entity1, $entity2) = @_; | ||
| 26 | |||
| 27 | if (my $random = 1 / rand >= $self->{lowerbound} or $random <= $self->{upperbound}) { | ||
| 28 | |||
| 29 | return 1; | ||
| 30 | } else { | ||
| 31 | return 0; | ||
| 32 | } | ||
| 33 | |||
| 34 | }; | ||
| 35 | 1; |