line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Games::Boggle::Board; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Games::Boggle::Board - create a boggle board |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Games::Boggle::Board; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $board = Games::Boggle::Board->new(); |
13
|
|
|
|
|
|
|
print $board->as_formatted_string; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This module creates a random boggle board for play. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 new |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $board = Games::Boggle::Board->new(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 as_string |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Returns a single string, suitable to pass to Games::Boggle |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $b = Games::Boggle->new( $board->as_string ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 as_formatted_string |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Returns a string formatted in a 4x4 block |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
print $board->as_formatted_string; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 as_array |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns a one-dimensional array of letters |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
foreach ($board->as_array) { |
42
|
|
|
|
|
|
|
# do something |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 AUTHOR |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Anthony DeLorenzo Eajdelore@cpan.orgE. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$VERSION = '1.03'; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
571
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
386
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
1
|
|
my $self = {}; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my @cubes = ( |
60
|
|
|
|
|
|
|
# cubes taken from my boggle set, YMMV |
61
|
|
|
|
|
|
|
[ qw(S O A C P H) ], |
62
|
|
|
|
|
|
|
[ qw(T Y Y D S I) ], |
63
|
|
|
|
|
|
|
[ qw(M U O C T I) ], |
64
|
|
|
|
|
|
|
[ qw(Y R L T T E) ], |
65
|
|
|
|
|
|
|
[ qw(T T A O W O) ], |
66
|
|
|
|
|
|
|
[ qw(D R X I L E) ], |
67
|
|
|
|
|
|
|
[ qw(S E O T I S) ], |
68
|
|
|
|
|
|
|
[ qw(N S I E E U) ], |
69
|
|
|
|
|
|
|
[ qw(J O O B A B) ], |
70
|
|
|
|
|
|
|
[ qw(W R E T V H) ], |
71
|
|
|
|
|
|
|
[ qw(Y L E D R V) ], |
72
|
|
|
|
|
|
|
[ qw(E A N A G E) ], |
73
|
|
|
|
|
|
|
[ qw(H Z L R N N) ], |
74
|
|
|
|
|
|
|
[ qw(S F F K A P) ], |
75
|
|
|
|
|
|
|
[ qw(W H G E E N) ], |
76
|
|
|
|
|
|
|
[ qw(Q I M N U H) ], |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my @board = map { $_->[int rand(6)] } @cubes; |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# uses fisher-yates shuffle |
82
|
|
|
|
|
|
|
# taken from perlfaq4, ++ to the perl community |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
for (my $i = scalar(@board); --$i; ) { |
85
|
0
|
|
|
|
|
|
my $j = int rand ($i+1); |
86
|
0
|
|
|
|
|
|
@board[$i,$j] = @board[$j,$i]; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->{BOARD} = \@board; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
bless ($self); |
92
|
0
|
|
|
|
|
|
return $self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub as_formatted_string { |
96
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
my @board = @{$self->{BOARD}}; |
|
0
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
s/Q/Qu/ foreach (@board); |
99
|
0
|
|
|
|
|
|
return sprintf ( |
100
|
|
|
|
|
|
|
( "%-3s%-3s%-3s%-3s\n" . |
101
|
|
|
|
|
|
|
"%-3s%-3s%-3s%-3s\n" . |
102
|
|
|
|
|
|
|
"%-3s%-3s%-3s%-3s\n" . |
103
|
|
|
|
|
|
|
"%-3s%-3s%-3s%-3s\n" |
104
|
|
|
|
|
|
|
) |
105
|
|
|
|
|
|
|
, @board); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub as_array { |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
110
|
0
|
|
|
|
|
|
return @{$self->{BOARD}}; |
|
0
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub as_string { |
114
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
return join ('',@{$self->{BOARD}}); |
|
0
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|