line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Bingo; |
2
|
|
|
|
|
|
|
|
3
|
34
|
|
|
34
|
|
29632
|
use strict; |
|
34
|
|
|
|
|
51
|
|
|
34
|
|
|
|
|
1019
|
|
4
|
34
|
|
|
34
|
|
341
|
use warnings; |
|
34
|
|
|
|
|
53
|
|
|
34
|
|
|
|
|
1117
|
|
5
|
34
|
|
|
34
|
|
6564
|
use integer; |
|
34
|
|
|
|
|
168
|
|
|
34
|
|
|
|
|
177
|
|
6
|
34
|
|
|
34
|
|
20107
|
use POSIX qw(floor); |
|
34
|
|
|
|
|
210057
|
|
|
34
|
|
|
|
|
240
|
|
7
|
34
|
|
|
34
|
|
42133
|
use vars qw($VERSION); |
|
34
|
|
|
|
|
62
|
|
|
34
|
|
|
|
|
1852
|
|
8
|
34
|
|
|
34
|
|
14570
|
use Games::Bingo::Constants qw(NUMBER_OF_NUMBERS); |
|
34
|
|
|
|
|
66
|
|
|
34
|
|
|
|
|
22283
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.18'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
214
|
|
|
214
|
1
|
8208
|
my $class = shift; |
14
|
214
|
|
100
|
|
|
1223
|
my $ceiling = shift || NUMBER_OF_NUMBERS; |
15
|
|
|
|
|
|
|
|
16
|
214
|
|
|
|
|
1441
|
my $self = bless { |
17
|
|
|
|
|
|
|
_numbers => [], |
18
|
|
|
|
|
|
|
_pulled => [[],[],[],[],[],[],[],[],[],], |
19
|
|
|
|
|
|
|
game => 1, |
20
|
|
|
|
|
|
|
}, $class; |
21
|
|
|
|
|
|
|
|
22
|
214
|
|
|
|
|
299
|
my @ary; |
23
|
214
|
|
|
|
|
648
|
$self->init(\@ary, $ceiling); |
24
|
214
|
|
|
|
|
211
|
push @{$self->{'_numbers'}}, @ary; |
|
214
|
|
|
|
|
2203
|
|
25
|
|
|
|
|
|
|
|
26
|
214
|
|
|
|
|
930
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub init { |
30
|
417
|
|
|
417
|
1
|
507
|
my ($self, $numbers, $ceiling) = @_; |
31
|
|
|
|
|
|
|
|
32
|
417
|
|
|
|
|
1051
|
for(my $i = 1; $i < ($ceiling + 1); $i++) { |
33
|
37370
|
|
|
|
|
27074
|
push @{$numbers}, $i; |
|
37370
|
|
|
|
|
67392
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
417
|
|
|
|
|
852
|
return 1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub play { |
40
|
113
|
|
|
113
|
1
|
6222
|
my ($self, $numbers) = @_; |
41
|
|
|
|
|
|
|
|
42
|
113
|
|
|
|
|
97
|
my $number; |
43
|
113
|
100
|
|
|
|
158
|
if ($numbers) { |
44
|
10
|
|
|
|
|
9
|
my $index = $self->random(scalar @{$numbers}); |
|
10
|
|
|
|
|
17
|
|
45
|
10
|
|
|
|
|
17
|
$number = $numbers->[$index]; |
46
|
10
|
|
|
|
|
7
|
splice(@{$numbers}, $index, 1); |
|
10
|
|
|
|
|
16
|
|
47
|
|
|
|
|
|
|
} else { |
48
|
103
|
|
|
|
|
83
|
my $index = $self->random(scalar @{$self->{'_numbers'}}); |
|
103
|
|
|
|
|
217
|
|
49
|
103
|
|
|
|
|
170
|
$number = $self->{'_numbers'}->[$index]; |
50
|
103
|
|
|
|
|
76
|
splice(@{$self->{'_numbers'}}, $index, 1); |
|
103
|
|
|
|
|
177
|
|
51
|
|
|
|
|
|
|
} |
52
|
113
|
|
|
|
|
181
|
$self->pull($number); |
53
|
|
|
|
|
|
|
|
54
|
113
|
|
|
|
|
181
|
return $number; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub pulled { |
58
|
32
|
|
|
32
|
1
|
39
|
my ($self, $number) = @_; |
59
|
|
|
|
|
|
|
|
60
|
32
|
|
|
|
|
22
|
my $found = 0; |
61
|
32
|
|
|
|
|
47
|
foreach my $n ($self->_all_pulled()) { |
62
|
602
|
100
|
|
|
|
812
|
if ($n == $number) { |
63
|
16
|
|
|
|
|
14
|
$found++; |
64
|
16
|
|
|
|
|
17
|
last; |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
32
|
100
|
|
|
|
109
|
if ($found) { |
69
|
16
|
|
|
|
|
56
|
return 1; |
70
|
|
|
|
|
|
|
} else { |
71
|
16
|
|
|
|
|
39
|
return 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _all_pulled { |
76
|
37
|
|
|
37
|
|
39
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
37
|
|
|
|
|
34
|
my @pulled = (); |
79
|
37
|
|
|
|
|
30
|
foreach my $row (@{$self->{'_pulled'}}) { |
|
37
|
|
|
|
|
61
|
|
80
|
348
|
|
|
|
|
228
|
foreach my $number (@{$row}) { |
|
348
|
|
|
|
|
372
|
|
81
|
1394
|
100
|
|
|
|
2010
|
push(@pulled, $number) if $number; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
37
|
|
|
|
|
182
|
return @pulled; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub pull { |
89
|
116
|
|
|
116
|
1
|
119
|
my ($self, $number) = @_; |
90
|
|
|
|
|
|
|
|
91
|
116
|
|
|
|
|
179
|
return $self->take($self->{'_pulled'}, $number); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub take { |
95
|
117
|
|
|
117
|
1
|
112
|
my ($self, $taken, $take) = @_; |
96
|
|
|
|
|
|
|
|
97
|
117
|
|
|
|
|
163
|
my ($x, $y, $take_modified) = $self->splitnumber($take); |
98
|
|
|
|
|
|
|
|
99
|
117
|
|
|
|
|
285
|
return $taken->[$x][$y] = $take_modified; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub random { |
103
|
7308
|
|
|
7308
|
1
|
6447
|
my ($self, $number) = @_; |
104
|
|
|
|
|
|
|
|
105
|
7308
|
|
|
|
|
29845
|
return POSIX::floor(rand($number)); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub splitnumber { |
109
|
119
|
|
|
119
|
1
|
108
|
my ($self, $number) = @_; |
110
|
|
|
|
|
|
|
|
111
|
119
|
|
|
|
|
381
|
my $modified = sprintf("%02d", $number); |
112
|
119
|
|
|
|
|
447
|
my ($x, $y) = $modified =~ m/^(\d{1})(\d{1})$/o; |
113
|
|
|
|
|
|
|
|
114
|
119
|
|
|
|
|
270
|
return ($x, $y, $modified); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |