line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
63579
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
66
|
|
2
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
130
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Games::Board::Grid; |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$Games::Board::Grid::VERSION = '1.013'; |
7
|
|
|
|
|
|
|
} |
8
|
2
|
|
|
2
|
|
1660
|
use parent qw(Games::Board); |
|
2
|
|
|
|
|
634
|
|
|
2
|
|
|
|
|
11
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: a grid-shaped gameboard |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
85
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
862
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
2
|
|
|
2
|
1
|
49
|
my ($class, %args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
2
|
50
|
|
|
|
8
|
croak "no size given to construct grid" unless $args{size}; |
19
|
|
|
|
|
|
|
|
20
|
2
|
50
|
|
|
|
15
|
$args{size} = [ ($args{size}) x 2 ] unless ref $args{size}; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
6
|
my $board = { size => $args{size} }; |
23
|
2
|
|
|
|
|
7
|
bless $board => $class; |
24
|
2
|
|
|
|
|
11
|
$board->init; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init { |
29
|
2
|
|
|
2
|
1
|
4
|
my $board = shift; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
16
|
$board->{spaces} = {}; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
9
|
for my $x (0 .. ($board->{size}[0] - 1)) { |
34
|
16
|
|
|
|
|
38
|
for my $y (0 .. ($board->{size}[1] - 1)) { |
35
|
128
|
|
|
|
|
337
|
my $id = $board->index2id([$x,$y]); |
36
|
128
|
|
|
|
|
1279
|
$board->{spaces}{$id} = Games::Board::Grid::Space->new(id => $id, board => $board); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
8
|
$board; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
68
|
|
|
68
|
1
|
270
|
sub size { (shift)->{size} } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
21
|
|
|
21
|
1
|
75
|
sub id2index { [ split(/ /,$_[1]) ] } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
79
|
|
|
79
|
1
|
75
|
sub index2id { join(q{ }, @{$_[1]}) } |
|
79
|
|
|
|
|
254
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub space { |
54
|
48
|
|
|
48
|
1
|
8020
|
my $board = shift; |
55
|
48
|
|
|
|
|
69
|
my $id = shift; |
56
|
|
|
|
|
|
|
|
57
|
48
|
|
|
|
|
252
|
return $board->{spaces}{$id}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
0
|
1
|
0
|
sub add_space { croak "spaces can't be added to grid board" } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
package Games::Board::Grid::Space; |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
$Games::Board::Grid::Space::VERSION = '1.013'; |
67
|
|
|
|
|
|
|
} |
68
|
2
|
|
|
2
|
|
11
|
use parent qw(Games::Board::Space); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
10
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub dir_id { |
71
|
42
|
|
|
42
|
|
59
|
my ($self, $dir) = @_; |
72
|
42
|
50
|
|
|
|
108
|
return unless ref $dir eq 'ARRAY'; |
73
|
|
|
|
|
|
|
|
74
|
42
|
|
|
|
|
110
|
my $pos = $self->board->id2index($self->id); |
75
|
|
|
|
|
|
|
|
76
|
42
|
|
|
|
|
320
|
my $newpos = [ |
77
|
|
|
|
|
|
|
$pos->[0] + $dir->[0], |
78
|
|
|
|
|
|
|
$pos->[1] + $dir->[1] |
79
|
|
|
|
|
|
|
]; |
80
|
|
|
|
|
|
|
|
81
|
42
|
100
|
100
|
|
|
205
|
return if $newpos->[0] < 0 or $newpos->[1] < 0; |
82
|
|
|
|
|
|
|
return |
83
|
36
|
100
|
100
|
|
|
105
|
if $newpos->[0] >= $self->board->size->[0] |
84
|
|
|
|
|
|
|
or $newpos->[1] >= $self->board->size->[1]; |
85
|
30
|
|
|
|
|
72
|
return $self->board->index2id($newpos); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
"Family fun night!"; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |