line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::2048::Grid; |
2
|
4
|
|
|
4
|
|
92
|
use 5.012; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
140
|
|
3
|
4
|
|
|
4
|
|
23
|
use Moo; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
22
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has size => is => 'ro', default => 4; |
6
|
|
|
|
|
|
|
has _tiles => is => 'lazy'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _build__tiles { |
9
|
55
|
|
|
55
|
|
1074
|
my $self = shift; |
10
|
55
|
|
|
|
|
908
|
[ map [ (undef) x $self->size ], 1..$self->size ]; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub each_cell { |
14
|
226
|
|
|
226
|
0
|
25791
|
my $self = shift; |
15
|
869
|
|
|
|
|
878
|
map { |
16
|
226
|
|
|
|
|
854
|
my $y = $_; |
17
|
869
|
|
|
|
|
5608
|
map [$_, $y], 0..$self->size-1; |
18
|
|
|
|
|
|
|
} 0..$self->size-1; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub each_tile { |
22
|
92
|
|
|
92
|
0
|
1702
|
my $self = shift; |
23
|
92
|
|
|
|
|
200
|
map $self->tile($_), $self->tile_cells; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub tile_cells { |
27
|
130
|
|
|
130
|
0
|
8760
|
my $self = shift; |
28
|
130
|
|
|
|
|
269
|
grep $self->tile($_), $self->each_cell; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub available_cells { |
32
|
41
|
|
|
41
|
0
|
805
|
my $self = shift; |
33
|
41
|
|
|
|
|
157
|
grep !$self->tile($_), $self->each_cell; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub has_available_cells { |
37
|
7
|
|
|
7
|
0
|
32
|
my $self = shift; |
38
|
7
|
|
|
|
|
24
|
!!scalar $self->available_cells; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub within_bounds { |
42
|
6033
|
|
|
6033
|
0
|
8229
|
my ($self, $cell) = @_; |
43
|
6033
|
100
|
100
|
|
|
66349
|
$cell->[0] >= 0 and $cell->[0] < $self->size and |
|
|
|
100
|
|
|
|
|
44
|
|
|
|
|
|
|
$cell->[1] >= 0 and $cell->[1] < $self->size; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub tile { |
48
|
5462
|
|
|
5462
|
0
|
29302
|
my ($self, $cell) = @_; |
49
|
5462
|
100
|
|
|
|
9101
|
return if !$self->within_bounds($cell); |
50
|
5311
|
|
|
|
|
146879
|
$self->_tiles->[$cell->[1]][$cell->[0]]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub clear_tile { |
54
|
162
|
|
|
162
|
0
|
220
|
my ($self, $cell) = @_; |
55
|
162
|
|
|
|
|
3562
|
$self->_tiles->[$cell->[1]][$cell->[0]] = undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub set_tile { |
59
|
636
|
|
|
636
|
0
|
926
|
my ($self, $cell, $tile) = @_; |
60
|
636
|
|
|
|
|
14698
|
$self->_tiles->[$cell->[1]][$cell->[0]] = $tile; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |