File Coverage

blib/lib/Games/ABC_Path/Generator/FinalLayoutObj.pm
Criterion Covered Total %
statement 43 43 100.0
branch 3 4 75.0
condition n/a
subroutine 14 14 100.0
pod 5 5 100.0
total 65 66 98.4


line stmt bran cond sub pod time code
1             package Games::ABC_Path::Generator::FinalLayoutObj;
2             $Games::ABC_Path::Generator::FinalLayoutObj::VERSION = '0.6.1';
3 9     9   369304 use 5.006;
  9         43  
4              
5 9     9   53 use strict;
  9         15  
  9         226  
6 9     9   60 use warnings;
  9         17  
  9         465  
7              
8 9     9   619 use integer;
  9         33  
  9         47  
9              
10 9     9   382 use parent 'Games::ABC_Path::Generator::Base';
  9         19  
  9         53  
11              
12 9     9   664 use Games::ABC_Path::Solver::Constants;
  9         45  
  9         5789  
13              
14              
15             sub _s
16             {
17 109     109   143 my $self = shift;
18              
19 109 100       197 if (@_)
20             {
21 4         35 $self->{_s} = shift;
22             }
23              
24 109         289 return $self->{_s};
25             }
26              
27             sub _init
28             {
29 4     4   45 my $self = shift;
30 4         11 my $args = shift;
31              
32 4         20 $self->_s( $args->{layout_string} );
33              
34 4         9 return;
35             }
36              
37              
38             sub get_A_pos
39             {
40 5     5 1 444 my ($self) = @_;
41              
42 5         20 return index( $self->_s, chr(1) );
43             }
44              
45              
46             sub get_A_xy
47             {
48 1     1 1 5 my ($self) = @_;
49              
50 1         4 my ( $y, $x ) = $self->_to_xy( $self->get_A_pos() );
51              
52 1         16 return { y => $y, x => $x, };
53             }
54              
55              
56             sub get_cell_contents
57             {
58 100     100 1 213 my ( $self, $index ) = @_;
59              
60 100         163 return vec( $self->_s, $index, 8 );
61             }
62              
63              
64             sub get_letter_at_pos
65             {
66 3     3 1 11 my ( $self, $pos ) = @_;
67              
68             return $letters[
69             $self->get_cell_contents(
70 3         24 $self->_xy_to_int( [ $pos->{'y'}, $pos->{'x'} ], )
71             ) - 1,
72             ];
73             }
74              
75              
76             sub as_string
77             {
78 1     1 1 15 my ( $l, $args ) = @_;
79              
80             my $render_row = sub {
81 5     5   5 my $y = shift;
82              
83             return join(
84             " | ",
85             map {
86 5         6 my $x = $_;
  25         55  
87 25         49 my $v = $l->get_cell_contents( $l->_xy_to_int( [ $y, $x ] ) );
88 25 50       95 $v ? $letters[ $v - 1 ] : '*'
89             } ( 0 .. $LEN - 1 )
90             );
91 1         4 };
92              
93 1         4 return join( '', map { $render_row->($_) . "\n" } ( 0 .. $LEN - 1 ) );
  5         7  
94             }
95              
96              
97             1; # End of Games::ABC_Path::Generator
98              
99             __END__