blib/lib/Games/ABC_Path/Generator/RiddleObj.pm

filter: Statementstmt 94.2% 66 / 70 Branchbran 90.9% 20 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.7% 15 / 16 Podpod 100% 4 / 4 totaltotal 93.7% 105 / 112 CC 14 SCAR 11.2
CC
14
Cov
93%
get_riddle_v1_string
6.0
get_letters_of_clue
5.1
__ANON__
2.1
CRAP 3.1
« blib/lib/Games/ABC_Path/Generator/App.pm ↑ Summary blib/script/abc-path-gen--multi.pl »
1 package Games::ABC_Path::Generator::RiddleObj;
2 9 $Games::ABC_Path::Generator::RiddleObj::VERSION = '0.6.0';
3 9 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶use parent 'Games::ABC_Path::Solver::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 9 ▶use Games::ABC_Path::Solver::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 sub _solution
18 {
19 4 ▶ my $self = shift;
Subroutine _solution: called CC=2 SCAR=6.9
20  
21 4 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 1 4
22 {
23 3 $self->{_solution} = shift;
24 }
25  
26 4 return $self->{_solution};
27 }
28  
29 sub _clues
30 {
31 13 ▶ my $self = shift;
Subroutine _clues: called CC=2 SCAR=6.9
32  
33 13 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 10 13
34 {
35 3 $self->{_clues} = shift;
36 }
37  
38 13 return $self->{_clues};
39 }
40  
41 sub _A_pos
42 {
43 15 ▶ my $self = shift;
Subroutine _A_pos: called CC=2 SCAR=6.9
44  
45 15 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 12 15
46 {
47 3 $self->{_A_pos} = shift;
48 }
49  
50 15 return $self->{_A_pos};
51 }
52  
53 sub _init
54 {
55 3 ▶ my $self = shift;
Subroutine _init: called CC=1 SCAR=0.0
56 3 my $args = shift;
57  
58 3 $self->_solution( $args->{solution} );
59 3 $self->_clues( $args->{clues} );
60 3 $self->_A_pos( $args->{A_pos} );
61  
62 3 return;
63 }
64  
65  
66 sub get_letters_of_clue
67 {
68 4 ▶ my ( $self, $args ) = @_;
Subroutine get_letters_of_clue: called CC=5 SCAR=16.3
Pod documented
69  
70 my $get_index = sub {
71 2 ▶ my $i = $args->{index};
Subroutine __ANON__: called CC=2 SCAR=7.6
72  
73 2 ▶ if ( $i !~ m{\A[01234]\z} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($i =~ /\A[01234]\z/) 0 2 2
74 {
75 0 Carp::confess('index must be in the range 0-4');
76 }
77  
78 2 return $i;
79 4 };
80  
81 4 my $clue_idx;
82 4 my $type = $args->{type};
83  
84 4 ▶ if ( $type eq 'col' )
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'col') { } 1 3 4
elsif ($type eq 'row') { } 1 2 3
elsif ($type eq 'diag') { } 1 1 2
elsif ($type eq 'antidiag') { } 1 0 1
85 {
86 1 $clue_idx = 2 + $LEN + $get_index->();
87 }
88 elsif ( $type eq 'row' )
89 {
90 1 $clue_idx = 2 + $get_index->();
91 }
92 elsif ( $type eq 'diag' )
93 {
94 1 $clue_idx = 0;
95 }
96 elsif ( $type eq 'antidiag' )
97 {
98 1 $clue_idx = 1;
99 }
100 else
101 {
102 0 Carp::confess("Unknown type $type.");
103 }
104  
105 4 return [ map { $letters[ $_ - 1 ] } @{ $self->_clues->[$clue_idx] } ];
106 }
107  
108  
109 sub get_riddle_v1_string
110 {
111 6 ▶ my ($self) = @_;
Subroutine get_riddle_v1_string: called CC=6 SCAR=17.9
Pod documented
112  
113 6 my $s = ( ( ' ' x 7 ) . "\n" ) x 7;
114  
115 6 substr( $s, ( $self->_A_pos->y + 1 ) * 8 + $self->_A_pos->x + 1, 1 ) = 'A';
116  
117 6 my $clues = $self->_clues();
118 6 foreach my $clue_idx ( 0 .. $NUM_CLUES - 1 )
119 {
120 72 ▶ my @pos =
Branch: 3 branches
BranchTrueFalseTotal
$clue_idx == 0 ? : 6 66 72
$clue_idx == 1 ? : 6 60 66
$clue_idx < 7 ? : 30 30 60
121 ( $clue_idx == 0 ) ? ( [ 0, 0 ], [ 6, 6 ] )
122 : ( $clue_idx == 1 ) ? ( [ 0, 6 ], [ 6, 0 ] )
123 : ( $clue_idx < ( 2 + 5 ) )
124 ? ( [ 1 + $clue_idx - (2), 0 ], [ 1 + $clue_idx - (2), 6 ] )
125 : (
126 [ 0, 1 + $clue_idx - ( 2 + 5 ) ],
127 [ 6, 1 + $clue_idx - ( 2 + 5 ) ]
128 );
129  
130 72 foreach my $i ( 0 .. 1 )
131 {
132 144 substr( $s, $pos[$i][0] * 8 + $pos[$i][1], 1 ) =
133 $letters[ $clues->[$clue_idx]->[$i] - 1 ];
134 }
135 }
136  
137 6 return $s;
138 }
139  
140  
141 sub get_final_layout
142 {
143 1 ▶ my ($self) = @_;
Subroutine get_final_layout: called CC=1 SCAR=0.0
Pod documented
144  
145 1 return $self->_solution;
146 }
147  
148  
149 sub get_final_layout_as_string
150 {
151 0 ▶ my ( $self, $args ) = @_;
Subroutine get_final_layout_as_string: not called CC=1 SCAR=6.9
Pod documented
152  
153 0 return $self->_solution->as_string($args);
154 }
155  
156  
157 9 1; # End of Games::ABC_Path::Generator
158  
159 __END__
« blib/lib/Games/ABC_Path/Generator/App.pm ↑ Summary blib/script/abc-path-gen--multi.pl »