| 1 | package Games::Bingo; | ||||||||||||
| 2 | |||||||||||||
| 3 | 38 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 38 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 38 | ▶ | use integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 38 | ▶ | use POSIX qw(floor); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 38 | ▶ | use vars qw($VERSION); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 38 | ▶ | use Games::Bingo::Constants qw(NUMBER_OF_NUMBERS); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 38 | $VERSION = '0.18'; | |||||||||||
| 11 | |||||||||||||
| 12 | 160 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 13 | 160 | my $class = shift; | |||||||||||
| 14 | 160 | ▶ | my $ceiling = shift || NUMBER_OF_NUMBERS; | ||||||||||
|
Condition100%2/2
shift() || 90
MC/DC100%1/1
shift() || 90
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 15 | |||||||||||||
| 16 | 160 | my $self = bless { | |||||||||||
| 17 | _numbers => [], | ||||||||||||
| 18 | _pulled => [[],[],[],[],[],[],[],[],[],], | ||||||||||||
| 19 | game => 1, | ||||||||||||
| 20 | }, $class; | ||||||||||||
| 21 | |||||||||||||
| 22 | 160 | my @ary; | |||||||||||
| 23 | 160 | $self->init(\@ary, $ceiling); | |||||||||||
| 24 | 160 | push @{$self->{'_numbers'}}, @ary; | |||||||||||
| 25 | |||||||||||||
| 26 | 160 | return $self; | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | 309 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 30 | 309 | my ($self, $numbers, $ceiling) = @_; | |||||||||||
| 31 | |||||||||||||
| 32 | 309 | ▶ | for(my $i = 1; $i < ($ceiling + 1); $i++) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 27650 | push @{$numbers}, $i; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 309 | return 1; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 113 | ▶ | sub play { | ||||||||||
|
Subroutine
play: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 40 | 113 | my ($self, $numbers) = @_; | |||||||||||
| 41 | |||||||||||||
| 42 | 113 | my $number; | |||||||||||
| 43 | 113 | ▶ | if ($numbers) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 10 | my $index = $self->random(scalar @{$numbers}); | |||||||||||
| 45 | 10 | $number = $numbers->[$index]; | |||||||||||
| 46 | 10 | splice(@{$numbers}, $index, 1); | |||||||||||
| 47 | } else { | ||||||||||||
| 48 | 103 | my $index = $self->random(scalar @{$self->{'_numbers'}}); | |||||||||||
| 49 | 103 | $number = $self->{'_numbers'}->[$index]; | |||||||||||
| 50 | 103 | splice(@{$self->{'_numbers'}}, $index, 1); | |||||||||||
| 51 | } | ||||||||||||
| 52 | 113 | $self->pull($number); | |||||||||||
| 53 | |||||||||||||
| 54 | 113 | return $number; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 32 | ▶ | sub pulled { | ||||||||||
|
Subroutine
pulled: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 58 | 32 | my ($self, $number) = @_; | |||||||||||
| 59 | |||||||||||||
| 60 | 32 | my $found = 0; | |||||||||||
| 61 | 32 | foreach my $n ($self->_all_pulled()) { | |||||||||||
| 62 | 714 | ▶ | if ($n == $number) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | 16 | $found++; | |||||||||||
| 64 | 16 | last; | |||||||||||
| 65 | }; | ||||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 32 | ▶ | if ($found) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 16 | return 1; | |||||||||||
| 70 | } else { | ||||||||||||
| 71 | 16 | return 0; | |||||||||||
| 72 | } | ||||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 37 | ▶ | sub _all_pulled { | ||||||||||
|
Subroutine
_all_pulled: called CC=4 SCAR=13.9
| |||||||||||||
| 76 | 37 | my $self = shift; | |||||||||||
| 77 | |||||||||||||
| 78 | 37 | my @pulled = (); | |||||||||||
| 79 | 37 | foreach my $row (@{$self->{'_pulled'}}) { | |||||||||||
| 80 | 348 | foreach my $number (@{$row}) { | |||||||||||
| 81 | 1384 | ▶ | push(@pulled, $number) if $number; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | } | ||||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 37 | return @pulled; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 116 | ▶ | sub pull { | ||||||||||
|
Subroutine
pull: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 89 | 116 | my ($self, $number) = @_; | |||||||||||
| 90 | |||||||||||||
| 91 | 116 | return $self->take($self->{'_pulled'}, $number); | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | 117 | ▶ | sub take { | ||||||||||
|
Subroutine
take: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 95 | 117 | my ($self, $taken, $take) = @_; | |||||||||||
| 96 | |||||||||||||
| 97 | 117 | my ($x, $y, $take_modified) = $self->splitnumber($take); | |||||||||||
| 98 | |||||||||||||
| 99 | 117 | return $taken->[$x][$y] = $take_modified; | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 5364 | ▶ | sub random { | ||||||||||
|
Subroutine
random: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 103 | 5364 | my ($self, $number) = @_; | |||||||||||
| 104 | |||||||||||||
| 105 | 5364 | return POSIX::floor(rand($number)); | |||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | 119 | ▶ | sub splitnumber { | ||||||||||
|
Subroutine
splitnumber: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 109 | 119 | my ($self, $number) = @_; | |||||||||||
| 110 | |||||||||||||
| 111 | 119 | my $modified = sprintf("%02d", $number); | |||||||||||
| 112 | 119 | my ($x, $y) = $modified =~ m/^(\d{1})(\d{1})$/o; | |||||||||||
| 113 | |||||||||||||
| 114 | 119 | return ($x, $y, $modified); | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | 38 | 1; | |||||||||||
| 118 | |||||||||||||
| 119 | __END__ | ||||||||||||