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

filter: Statementstmt 100% 45 / 45 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 5 / 5 totaltotal 98.5% 67 / 68 CC 3 SCAR 2.2
CC
3
Cov
98%
__ANON__
2.0
_s
2.0
as_string
1.0
CRAP 1.3
« blib/lib/Games/ABC_Path/MicrosoftRand.pm ↑ Summary blib/lib/Games/ABC_Path/Generator/Base.pm »
1 package Games::ABC_Path::Generator::FinalLayoutObj;
2  
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use base 'Games::ABC_Path::Generator::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use Games::ABC_Path::Solver::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 Games::ABC_Path::Generator::FinalLayoutObj - represents a final layout.
17  
18 =head1 VERSION
19  
20 Version 0.1.0
21  
22 =cut
23  
24 6 our $VERSION = '0.1.0';
25  
26 =head1 SYNOPSIS
27  
28 use Games::ABC_Path::Generator;
29  
30 my $gen = Games::ABC_Path::Generator->new({seed => 1});
31  
32 # Returns a Games::ABC_Path::Generator::RiddleObj object.
33 my $riddle = $gen->calc_riddle();
34  
35 print $riddle->get_riddle_v1_string();
36 print $riddle->get_riddle_string_with_header();
37  
38  
39 =head1 SUBROUTINES/METHODS
40  
41 =head2 my $riddle = Games::ABC_Path::Generator::RiddleObj->new({%args});
42  
43 Initialised a new riddle. Arguments are:
44  
45 =over 4
46  
47 =item * solution
48  
49 The solution layout.
50  
51 =item * clues
52  
53 An array of the clues.
54  
55 =item * A_pos
56  
57 The position of the A cell.
58  
59 =back
60  
61 =cut
62  
63 sub _s
64 {
65 159 ▶ my $self = shift;
Subroutine _s: called CC=2 SCAR=6.9
66  
67 159 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 155 159
68 {
69 4 $self->{_s} = shift;
70 }
71  
72 159 return $self->{_s};
73 }
74  
75 sub _init
76 {
77 4 ▶ my $self = shift;
Subroutine _init: called CC=1 SCAR=0.0
78 4 my $args = shift;
79  
80 4 $self->_s($args->{layout_string});
81  
82 4 return;
83 }
84  
85 =head2 $layout->get_A_pos()
86  
87 Returns the position of the letter 'A'.
88  
89 =cut
90  
91 sub get_A_pos
92 {
93 5 ▶ my ($self) = @_;
Subroutine get_A_pos: called CC=1 SCAR=0.0
Pod documented
94  
95 5 return index($self->_s, chr(1));
96 }
97  
98 =head2 $layout->get_A_xy()
99  
100 Returns the (X,Y) coordinates of the letter A as a C<< {x => $x, y => $y} >>
101 hash reference.
102  
103 =cut
104  
105 sub get_A_xy
106 {
107 1 ▶ my ($self) = @_;
Subroutine get_A_xy: called CC=1 SCAR=0.0
Pod documented
108  
109 1 my ($y, $x) = $self->_to_xy($self->get_A_pos());
110  
111 1 return {y => $y, x => $x,};
112 }
113  
114 =head2 $layout->get_cell_contents($index)
115  
116 Returns the cell at index L<$index> (where index is C< $Y*5 + $X>).
117  
118 =cut
119  
120 sub get_cell_contents
121 {
122 150 ▶ my ($self, $index) = @_;
Subroutine get_cell_contents: called CC=1 SCAR=0.0
Pod documented
123  
124 150 return vec($self->_s, $index, 8) ;
125 }
126  
127 =head2 my $letter = $layout->get_letter_at_pos({y => $y, x => $x});
128  
129 Returns the letter at $y and $x .
130  
131 =cut
132  
133 sub get_letter_at_pos
134 {
135 3 ▶ my ($self, $pos) = @_;
Subroutine get_letter_at_pos: called CC=1 SCAR=0.0
Pod documented
136  
137 return $letters[
138 $self->get_cell_contents(
139 $self->_xy_to_int(
140 3 [$pos->{'y'},$pos->{'x'}],
141 )
142 )-1,
143 ];
144 }
145  
146 =head2 $layout->as_string($args);
147  
148 Represents the layout as string.
149  
150 =cut
151  
152 =head2 $layout->as_string($args);
153  
154 Represents the layout as string.
155  
156 =cut
157  
158 sub as_string
159 {
160 3 ▶ my ($l, $args) = @_;
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
161  
162 my $render_row = sub {
163 15 ▶ my $y = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
164  
165 return join(" | ",
166 map {
167 15 my $x = $_;
168 75 my $v = $l->get_cell_contents($l->_xy_to_int([$y,$x]));
169 75 ▶ $v ? $letters[$v-1] : '*' } (0 .. $LEN - 1));
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 75 0 75
170 3 };
171  
172 3 return join('', map { $render_row->($_) . "\n" } (0 .. $LEN-1));
173 }
174 =head1 AUTHOR
175  
176 Shlomi Fish, L<http://www.shlomifish.org/> .
177  
178 =head1 BUGS
179  
180 Please report any bugs or feature requests to C<bug-games-abc_path-generator at rt.cpan.org>, or through
181 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-ABC_Path-Generator>. I will be notified, and then you'll
182 automatically be notified of progress on your bug as I make changes.
183  
184  
185  
186  
187 =head1 SUPPORT
188  
189 You can find documentation for this module with the perldoc command.
190  
191 perldoc Games::ABC_Path::Generator
192  
193  
194 You can also look for information at:
195  
196 =over 4
197  
198 =item * RT: CPAN's request tracker (report bugs here)
199  
200 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-ABC_Path-Generator>
201  
202 =item * AnnoCPAN: Annotated CPAN documentation
203  
204 L<http://annocpan.org/dist/Games-ABC_Path-Generator>
205  
206 =item * CPAN Ratings
207  
208 L<http://cpanratings.perl.org/d/Games-ABC_Path-Generator>
209  
210 =item * Search CPAN
211  
212 L<http://search.cpan.org/dist/Games-ABC_Path-Generator/>
213  
214 =back
215  
216  
217 =head1 ACKNOWLEDGEMENTS
218  
219  
220 =head1 LICENSE AND COPYRIGHT
221  
222 Copyright 2011 Shlomi Fish.
223  
224 This program is distributed under the MIT (X11) License:
225 L<http://www.opensource.org/licenses/mit-license.php>
226  
227 Permission is hereby granted, free of charge, to any person
228 obtaining a copy of this software and associated documentation
229 files (the "Software"), to deal in the Software without
230 restriction, including without limitation the rights to use,
231 copy, modify, merge, publish, distribute, sublicense, and/or sell
232 copies of the Software, and to permit persons to whom the
233 Software is furnished to do so, subject to the following
234 conditions:
235  
236 The above copyright notice and this permission notice shall be
237 included in all copies or substantial portions of the Software.
238  
239 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
240 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
241 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
242 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
243 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
244 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
245 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
246 OTHER DEALINGS IN THE SOFTWARE.
247  
248  
249 =cut
250  
251 6 1; # End of Games::ABC_Path::Generator
« blib/lib/Games/ABC_Path/MicrosoftRand.pm ↑ Summary blib/lib/Games/ABC_Path/Generator/Base.pm »