blib/lib/Game/TextMapper/Gridmapper.pm

filter: Statementstmt 55.9% 369 / 660 Branchbran 37.9% 107 / 282 Conditioncond 23.1% 41 / 177 MC/DCmcdc 14.1% 12 / 85 Subroutinesub 73.0% 38 / 52 Podpod 2.6% 1 / 38 totaltotal 43.8% 568 / 1294 CC 248 SCAR 56.5
CC
248
Cov
46%
to_gridmapper_link
1000.2
shape_reconnect
462.0
fix_corners
273.9
CRAP 283.9
« blib/lib/Game/TextMapper.pm ↑ Summary blib/lib/Game/TextMapper/Solo.pm »
1 # Copyright (C) 2009-2021 Alex Schroeder <alex@gnu.org>
2 #
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the GNU Affero General Public License as published by the Free
5 # Software Foundation, either version 3 of the License, or (at your option) any
6 # later version.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Affero General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Game::TextMapper::Gridmapper - generate dungeon maps
21  
22 =head1 DESCRIPTION
23  
24 This generates dungeon maps. At its core, this uses a 3×3 layout, 9 sections
25 total. 5 or 7 of these 9 sections get a room. The connections for the rooms (the
26 "shape") is picked at random from a fixed list of configurations (plus flipped
27 and rotated variants). The first room contains the stairs.
28  
29 To generate bigger dungeons, more of these 3×3 layouts are added to the first.
30 As the number of rooms is dynamic, the algorithm figures out how to best use a
31 number of layouts containing 5 or 7 rooms to get to that number, and then simply
32 drops the extra rooms.
33  
34 =head1 METHODS
35  
36 =cut
37  
38 package Game::TextMapper::Gridmapper;
39 11 ▶use Game::TextMapper::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 11 ▶use Game::TextMapper::Constants qw($dx $dy);
Subroutine BEGIN: called CC=1 SCAR=0.0
41 11 ▶use Modern::Perl '2018';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 11 ▶use List::Util qw'shuffle none any min max all';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 11 ▶use List::MoreUtils qw'pairwise';
Subroutine BEGIN: called CC=1 SCAR=0.0
44 11 ▶use Mojo::Util qw(url_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 11 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 11 my $log = Game::TextMapper::Log->get;
48  
49 # This is the meta grid for the geomorphs. Normally this is (3,3) for simple
50 # dungeons. We need to recompute these when smashing geomorphs together.
51 11 has 'dungeon_dimensions';
52 11 has 'dungeon_geomorph_size';
53  
54 # This is the grid for a particular geomorph. This is space for actual tiles.
55 11 has 'room_dimensions';
56  
57 # Rows and columns, for the tiles. Add two tiles for the edges, so the first
58 # two rows and the last two rows, and the first two columns and the last two
59 # columns should be empty. This is the empty space where stairs can be added.
60 # (0,0) starts at the top left and goes rows before columns, like text. Max
61 # tiles is the maximum number of tiles. We need to recompute these values when
62 # smashing two geomorphs together.
63 11 has 'row';
64 11 has 'col';
65 11 has 'max_tiles';
66  
67 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
68 1 my $self = shift;
69 1 $self->dungeon_geomorph_size(3); # this stays the same
70 1 $self->dungeon_dimensions([3, 3]); # this will change
71 1 $self->room_dimensions([5, 5]);
72 1 $self->recompute();
73 }
74  
75 2 ▶sub recompute {
Subroutine recompute: called CC=1 SCAR=0.0
Pod undocumented
76 2 my $self = shift;
77 2 $self->row($self->dungeon_dimensions->[0]
78 * $self->room_dimensions->[0]
79 + 4);
80 2 $self->col($self->dungeon_dimensions->[1]
81 * $self->room_dimensions->[1]
82 + 4);
83 2 $self->max_tiles($self->row * $self->col - 1);
84 }
85  
86 =head2 generate_map($pillars, $n, $caves)
87  
88 If C<$pillars> is true, then rooms with pillars are generated. This is usually a
89 good idea. It's harder to pull off from I<Hex Describe> because the description
90 of the dungeon should mention the pillars but there's now way to do that.
91 Perhaps, if C<$pillars> were to be a reference of room numbers with pillars, it
92 might work; right now, however, it's simply a boolean value.
93  
94 C<$n> is number of rooms.
95  
96 If C<$caves> is true, then the entire map uses cave walls instead of regular
97 walls.
98  
99 =cut
100  
101 1 ▶sub generate_map {
Subroutine generate_map: called CC=6 SCAR=18.3
Pod documented
102 1 my $self = shift;
103 1 my $pillars = shift;
104 1 my $n = shift;
105 1 my $caves = shift;
106 1 $self->init;
107 1 my $rooms = [map { $self->generate_room($_, $pillars, $caves) } (1 .. $n)];
108 1 my ($shape, $stairs) = $self->shape(scalar(@$rooms));
109 1 my $tiles = $self->add_rooms($rooms, $shape);
110 1 $tiles = $self->add_corridors($tiles, $shape);
111 1 ▶ $tiles = $self->add_doors($tiles) unless $caves;
Branch: 1 branch
BranchTrueFalseTotal
unless $caves 1 0 1
112 1 ▶ $tiles = $self->add_stair($tiles, $stairs) unless $caves;
Branch: 1 branch
BranchTrueFalseTotal
unless $caves 1 0 1
113 1 ▶ $tiles = $self->add_small_stair($tiles, $stairs) if $caves;
Branch: 1 branch
BranchTrueFalseTotal
if $caves 0 1 1
114 1 $tiles = $self->fix_corners($tiles);
115 1 ▶ $tiles = $self->fix_pillars($tiles) if $pillars;
Branch: 1 branch
BranchTrueFalseTotal
if $pillars 1 0 1
116 1 ▶ $tiles = $self->to_rocks($tiles) if $caves;
Branch: 1 branch
BranchTrueFalseTotal
if $caves 0 1 1
117 1 return $self->to_text($tiles);
118 }
119  
120 5 ▶sub generate_room {
Subroutine generate_room: called CC=5 SCAR=22.9
Pod undocumented
121 5 my $self = shift;
122 5 my $num = shift;
123 5 my $pillars = shift;
124 5 my $caves = shift;
125 5 my $r = rand();
126 5 ▶ if ($r < 0.9) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r < 0.9) { } 5 0 5
elsif ($r < 0.95 and $pillars or $caves) { } 0 0 0
127 5 return $self->generate_random_room($num);
128 ▶ } elsif ($r < 0.95 and $pillars or $caves) {
Condition0%0/6
$r < "0.95" and $pillars or $caves
l!l&&r!l&&!r
000
$r < "0.95" and $pillars
!ll&&!rl&&r
000
MC/DC0%0/3
$r < "0.95" and $pillars or $caves
$r < "0.95" $pillars $caves
Truth table0%0/5
A and B or C
A= $r < "0.95"B= $pillarsC= $caves
ABCresult
11X1
0X11
1011
0X00
1000
129 0 return $self->generate_pillar_room($num);
130 } else {
131 0 return $self->generate_fancy_corner_room($num);
132 }
133 }
134  
135 5 ▶sub generate_random_room {
Subroutine generate_random_room: called CC=3 SCAR=11.0
Pod undocumented
136 5 my $self = shift;
137 5 my $num = shift;
138 # generate the tiles necessary for a single geomorph
139 5 my @tiles;
140 5 my @dimensions = (2 + int(rand(3)), 2 + int(rand(3)));
141 5 ▶ my @start = pairwise { int(rand($b - $a)) } @dimensions, @{$self->room_dimensions};
Subroutine __ANON__: called CC=1 SCAR=0.0
142 # $log->debug("New room starting at (@start) for dimensions (@dimensions)");
143 5 for my $x ($start[0] .. $start[0] + $dimensions[0] - 1) {
144 14 for my $y ($start[1] .. $start[1] + $dimensions[1] - 1) {
145 47 $tiles[$x + $y * $self->room_dimensions->[0]] = ["empty"];
146 }
147 }
148 5 my $x = $start[0] + int($dimensions[0]/2);
149 5 my $y = $start[1] + int($dimensions[1]/2);
150 5 push(@{$tiles[$x + $y * $self->room_dimensions->[0]]}, "\"$num\"");
151 5 return \@tiles;
152 }
153  
154 0 ▶sub generate_fancy_corner_room {
Subroutine generate_fancy_corner_room: not called CC=4 SCAR=30.0
Pod undocumented
155 0 my $self = shift;
156 0 my $num = shift;
157 0 my @tiles;
158 0 my @dimensions = (3 + int(rand(2)), 3 + int(rand(2)));
159 0 ▶ my @start = pairwise { int(rand($b - $a)) } @dimensions, @{$self->room_dimensions};
Subroutine __ANON__: not called CC=1 SCAR=6.9
160 # $log->debug("New room starting at (@start) for dimensions (@dimensions)");
161 0 for my $x ($start[0] .. $start[0] + $dimensions[0] - 1) {
162 0 for my $y ($start[1] .. $start[1] + $dimensions[1] - 1) {
163 0 push(@{$tiles[$x + $y * $self->room_dimensions->[0]]}, "empty");
164 # $log->debug("$x $y @{$tiles[$x + $y * $self->room_dimensions->[0]]}");
165 }
166 }
167 0 ▶ my $type = rand() < 0.5 ? "arc" : "diagonal";
Branch: 1 branch
BranchTrueFalseTotal
rand() < 0.5 ? : 0 0 0
168 0 $tiles[$start[0] + $start[1] * $self->room_dimensions->[0]] = ["$type-se"];
169 0 $tiles[$start[0] + $dimensions[0] + $start[1] * $self->room_dimensions->[0] -1] = ["$type-sw"];
170 0 $tiles[$start[0] + ($start[1] + $dimensions[1] - 1) * $self->room_dimensions->[0]] = ["$type-ne"];
171 0 $tiles[$start[0] + $dimensions[0] + ($start[1] + $dimensions[1] - 1) * $self->room_dimensions->[0] - 1] = ["$type-nw"];
172 0 my $x = $start[0] + int($dimensions[0]/2);
173 0 my $y = $start[1] + int($dimensions[1]/2);
174 0 push(@{$tiles[$x + $y * $self->room_dimensions->[0]]}, "\"$num\"");
175 0 return \@tiles;
176 }
177  
178 0 ▶sub generate_pillar_room {
Subroutine generate_pillar_room: not called CC=9 SCAR=45.0
Pod undocumented
179 0 my $self = shift;
180 0 my $num = shift;
181 0 my @tiles;
182 0 my @dimensions = (3 + int(rand(2)), 3 + int(rand(2)));
183 0 ▶ my @start = pairwise { int(rand($b - $a)) } @dimensions, @{$self->room_dimensions};
Subroutine __ANON__: not called CC=1 SCAR=6.9
184 # $log->debug("New room starting at (@start) for dimensions (@dimensions)");
185 0 my $type = "|";
186 0 for my $x ($start[0] .. $start[0] + $dimensions[0] - 1) {
187 0 for my $y ($start[1] .. $start[1] + $dimensions[1] - 1) {
188 0 ▶ if ($type eq "|" and ($x == $start[0] or $x == $start[0] + $dimensions[0] - 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq '|' and $x == $start[0] || $x == $start[0] + $dimensions[0] - 1 or $type eq '-' and $y == $start[1] || $y == $start[1] + $dimensions[1] - 1) { } 0 0 0
Condition0%0/15
$type eq "|" and $x == $start[0] || $x == $start[0] + $dimensions[0] - 1 or $type eq "-" and $y == $start[1] || $y == $start[1] + $dimensions[1] - 1
l!l&&r!l&&!r
000
$type eq "|" and $x == $start[0] || $x == $start[0] + $dimensions[0] - 1
!ll&&!rl&&r
000
$x == $start[0] or $x == $start[0] + $dimensions[0] - 1
l!l&&r!l&&!r
000
$type eq "-" and $y == $start[1] || $y == $start[1] + $dimensions[1] - 1
!ll&&!rl&&r
000
$y == $start[1] or $y == $start[1] + $dimensions[1] - 1
l!l&&r!l&&!r
000
MC/DC0%0/6
$type eq "|" and $x == $start[0] || $x == $start[0] + $dimensions[0] - 1 or $type eq "-" and $y == $start[1] || $y == $start[1] + $dimensions[1] - 1
$type eq "|" $x == $start[0] $x == $start[0] + $dimensions[0] - 1 $type eq "-" $y == $start[1] $y == $start[1] + $dimensions[1] - 1
Truth table0%0/10
A and B or C or D and E or F
A= $type eq "|"B= $x == $start[0]C= $x == $start[0] + $dimensions[0] - 1D= $type eq "-"E= $y == $start[1]F= $y == $start[1] + $dimensions[1] - 1
ABCDEFresult
11XXXX1
101XXX1
0XX11X1
0XX1011
10011X1
1001011
0XX0XX0
0XX1000
1000XX0
1001000
189 or $type eq "-" and ($y == $start[1] or $y == $start[1] + $dimensions[1] - 1)) {
190 0 push(@{$tiles[$x + $y * $self->room_dimensions->[0]]}, "pillar");
191 } else {
192 0 push(@{$tiles[$x + $y * $self->room_dimensions->[0]]}, "empty");
193 # $log->debug("$x $y @{$tiles[$x + $y * $self->room_dimensions->[0]]}");
194 }
195 }
196 }
197 0 my $x = $start[0] + int($dimensions[0]/2);
198 0 my $y = $start[1] + int($dimensions[1]/2);
199 0 push(@{$tiles[$x + $y * $self->room_dimensions->[0]]}, "\"$num\"");
200 0 return \@tiles;
201 }
202  
203 5 ▶sub one {
Subroutine one: called CC=1 SCAR=0.0
Pod undocumented
204 5 return $_[int(rand(scalar @_))];
205 }
206  
207 =head1 LAYOUT
208  
209 One of the shapes is picked, and then flipped and rotated to generate more
210 shapes. This is why we can skip any shape that is a flipped and/or rotated
211 version of an existing shape.
212  
213 =head2 5 Room Dungeons
214  
215 These are inspired by L<The Nine Forms of the Five Room
216 Dungeon|https://gnomestew.com/the-nine-forms-of-the-five-room-dungeon/> by
217 Matthew J. Neagley, for Gnome Stew.
218  
219 =cut
220  
221 1 ▶sub five_room_shape {
Subroutine five_room_shape: called CC=1 SCAR=0.0
Pod undocumented
222 1 my $self = shift;
223 1 my $n = shift;
224 1 my @shapes;
225  
226 =head3 The Railroad
227  
228 5 5 4--5 5--4
229 | | | |
230 4 3--4 3 5--4 3
231 | | | | |
232 1--2--3 1--2 1--2 1--2--3 1--2
233  
234 =cut
235  
236 1 push(@shapes,
237 [[0, 2], [1, 2], [2, 2], [2, 1], [2, 0]],
238 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 0]],
239 [[0, 2], [1, 2], [1, 1], [1, 0], [2, 0]],
240 [[0, 2], [1, 2], [2, 2], [2, 1], [1, 1]],
241 [[0, 2], [1, 2], [1, 1], [1, 0], [0, 0]]);
242  
243 =head3 Foglio's Snail
244  
245 5 4
246 | |
247 1--2--3
248  
249 =cut
250  
251 # Note how whenever there is a non-linear connection, there is a an extra
252 # element pointing to the "parent". This is necessary for all but the
253 # railroads.
254 1 push(@shapes,
255 [[0, 2], [1, 2], [2, 2], [2, 1], [1, 1, 1]]);
256  
257 =head3 The Fauchard Fork
258  
259 5 5
260 | |
261 3--4 4--3 5--3--4
262 | | |
263 1--2 1--2 1--2
264  
265 =cut
266  
267 1 push(@shapes,
268 [[0, 2], [1, 2], [1, 1], [2, 1], [1, 0, 2]],
269 [[0, 2], [1, 2], [1, 1], [0, 1], [1, 0, 2]],
270 [[0, 2], [1, 2], [1, 1], [2, 1], [0, 1, 2]]);
271  
272 =head3 The Moose
273  
274 4
275 |
276 5 4 5 3
277 | | | |
278 1--2--3 1--2
279  
280 =cut
281  
282 1 push(@shapes,
283 [[0, 2], [1, 2], [2, 2], [2, 1], [0, 1, 0]],
284 [[0, 2], [1, 2], [1, 1], [1, 0], [0, 1, 0]]);
285  
286 =head3 The Paw
287  
288 5
289 |
290 3--2--4
291 |
292 1
293  
294 =cut
295  
296 1 push(@shapes,
297 [[1, 2], [1, 1], [0, 1], [2, 1, 1], [1, 0, 1]]);
298  
299 =head3 The Arrow
300  
301 3
302 |
303 2
304 |
305 5--1--4
306  
307 =cut
308  
309 1 push(@shapes,
310 [[1, 2], [1, 1], [1, 0], [2, 2, 0], [0, 2, 0]]);
311  
312 =head3 The Cross
313  
314 5
315 |
316 3--1--4
317 |
318 2
319  
320 =cut
321  
322 1 push(@shapes,
323 [[1, 1], [1, 2], [0, 1, 0], [2, 1, 0], [1, 0, 0]]);
324  
325 =head3 The Nose Ring
326  
327 5--4 2--3--4
328 | | | |
329 1--2--3 1--5
330  
331 =cut
332  
333 1 push(@shapes,
334 [[0, 2], [1, 2], [2, 2], [2, 1], [1, 1, 1, 3]],
335 [[0, 2], [0, 1], [1, 1], [2, 1], [1, 2, 0, 2]]);
336  
337 1 return $self->shape_trim($self->shape_flip(one(@shapes)), $n);
338 }
339  
340 =head2 7 Room Dungeons
341  
342 High room density is a desirable property, so we can fill the 9 sections of the
343 3×3 base layout with more than just five rooms. The algorithm uses 7 room
344 shapes in addition to the five room shapes.
345  
346 =cut
347  
348 0 ▶sub seven_room_shape {
Subroutine seven_room_shape: not called CC=1 SCAR=6.9
Pod undocumented
349 0 my $self = shift;
350 0 my $n = shift;
351 0 my @shapes;
352  
353 =head3 The Snake
354  
355 7--6--5 7--6--5 4--5 7
356 | | | | |
357 4 3--4 3 6 6--5--4
358 | | | | |
359 1--2--3 1--2 1--2 7 1--2--3
360  
361 =cut
362  
363 0 push(@shapes,
364 [[0, 2], [1, 2], [2, 2], [2, 1], [2, 0], [1, 0], [0, 0]],
365 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 0], [1, 0], [0, 0]],
366 [[0, 2], [1, 2], [1, 1], [1, 0], [2, 0], [2, 1], [2, 2]],
367 [[0, 2], [1, 2], [2, 2], [2, 1], [1, 1] ,[0, 1], [0, 0]]);
368  
369 =head3 The Fork
370  
371 7 5 7 5 7-----5
372 | | | | | |
373 6 4 6 4 6 4
374 | | | | | |
375 1--2--3 1--2--3 1--2--3
376  
377 =cut
378  
379 # Note how whenever there is a non-linear connection, there is a an extra
380 # element pointing to the "parent". This is necessary for all but the
381 # railroads.
382  
383 0 push(@shapes,
384 [[0, 2], [1, 2], [2, 2], [2, 1], [2, 0], [1, 1, 1], [1, 0]],
385 [[0, 2], [1, 2], [2, 2], [2, 1], [2, 0], [0, 1, 0], [0, 0]],
386 [[0, 2], [1, 2], [2, 2], [2, 1], [2, 0], [0, 1, 0], [0, 0, 5, 4]]);
387  
388 =head3 The Sidequest
389  
390 6--5 5--6 7 5 6--5 5--6 7 5
391 | | | | | | | | | | | |
392 7 3--4 4--3 7 6--3--4 7 3--4 4--3 7 6--3--4
393 | | | | | | | | |
394 1--2 1--2 1--2 1--2 1--2 1--2
395  
396 =cut
397  
398 0 push(@shapes,
399 [[0, 2], [1, 2], [1, 1], [2, 1], [1, 0, 2], [0, 0], [0, 1]],
400 [[0, 2], [1, 2], [1, 1], [0, 1], [1, 0, 2], [2, 0], [2, 1]],
401 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 0], [0, 1, 2], [0, 0]],
402 [[0, 2], [1, 2], [1, 1], [2, 1], [1, 0, 2], [0, 0], [0, 1, 5, 0]],
403 [[0, 2], [1, 2], [1, 1], [0, 1, 2, 0], [1, 0, 2], [2, 0], [2, 1]],
404 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 0], [0, 1, 2, 0], [0, 0]]);
405  
406 =head3 The Unbalanced Fork
407  
408 7 5 7 4--5 7 5 7 7 4--5 7 5 7
409 | | | | | | | | | | | |
410 6 4 6 3 6 3--4 6 3--4 6--3 6--3--4 6--3--4
411 | | | | | | | | | | | | | | | |
412 1--2--3 1--2 1--2 1--2 5 1--2 1--2 1--2 5
413  
414 =cut
415  
416 0 push(@shapes,
417 [[0, 2], [1, 2], [2, 2], [2, 1], [2, 0], [0, 1, 0], [0, 0]],
418 [[0, 2], [1, 2], [1, 1], [1, 0], [2, 0], [0, 1, 0], [0, 0]],
419 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 0], [0, 1, 0], [0, 0]],
420 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 2], [0, 1, 0], [0, 0]],
421 [[0, 2], [1, 2], [1, 1], [1, 0], [2, 0], [0, 1, 2, 0], [0, 0]],
422 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 0], [0, 1, 2, 0], [0, 0]],
423 [[0, 2], [1, 2], [1, 1], [2, 1], [2, 2], [0, 1, 2, 0], [0, 0]]);
424  
425 =head3 The Triplet
426  
427 4 5 7 5 7 5 4--5 7 5 7 5
428 | | | | | | | | | | | |
429 3--2--6 3--2--6 3--2--6 3--2--6 3--2--6 3--2--6
430 | | | | | | | | | | | |
431 1 4 1 4 1 7 1 4--1 4--1 7
432  
433 =cut
434  
435 0 push(@shapes,
436 [[1, 2], [1, 1], [0, 1], [0, 0], [1, 0, 1], [2, 1, 1], [2, 0]],
437 [[1, 2], [1, 1], [0, 1], [0, 2], [1, 0, 1], [2, 1, 1], [2, 0]],
438 [[1, 2], [1, 1], [0, 1], [0, 2], [1, 0, 1], [2, 1, 1], [2, 2]],
439 [[1, 2], [1, 1], [0, 1], [0, 0], [1, 0, 1, 3], [2, 1, 1], [2, 0]],
440 [[1, 2], [1, 1], [0, 1], [0, 2, 2, 0], [1, 0, 1], [2, 1, 1], [2, 0]],
441 [[1, 2], [1, 1], [0, 1], [0, 2, 2, 0], [1, 0, 1], [2, 1, 1], [2, 2]]);
442  
443 =head3 The Fake Fork
444  
445 7 3 7 7 3 7
446 | | | | | |
447 6 2 6 2--3 6--2 6--2--3
448 | | | | | | | |
449 5--1--4 5--1--4 5--1--4 5--1--4
450  
451 =cut
452  
453 0 push(@shapes,
454 [[1, 2], [1, 1], [1, 0], [2, 2, 0], [0, 2, 0], [0, 1], [0, 0]],
455 [[1, 2], [1, 1], [2, 1], [2, 2, 0], [0, 2, 0], [0, 1], [0, 0]],
456 [[1, 2], [1, 1], [1, 0], [2, 2, 0], [0, 2, 0], [0, 1, 4, 1], [0, 0]],
457 [[1, 2], [1, 1], [2, 1], [2, 2, 0], [0, 2, 0], [0, 1, 4, 1], [0, 0]]);
458  
459 =head3 The Shuriken
460  
461 5 6--7 5 6--7 5--6 5--6--7 5--6--7 5--6
462 | | | | | | | | | |
463 4--1 4--1 4--1--7 4--1 4--1 4--1--7
464 | | | | | | |
465 3--2 2--3 3--2 3--2 2--3 3--2
466  
467 =cut
468  
469 0 push(@shapes,
470 [[1, 1], [1, 2], [0, 2], [0, 1, 0], [0, 0], [1, 0, 0], [2, 0]],
471 [[1, 1], [1, 2], [2, 2], [0, 1, 0], [0, 0], [1, 0, 0], [2, 0]],
472 [[1, 1], [1, 2], [0, 2], [0, 1, 0], [0, 0], [1, 0], [2, 1, 0]],
473 [[1, 1], [1, 2], [0, 2], [0, 1, 0], [0, 0], [1, 0, 4, 0], [2, 0]],
474 [[1, 1], [1, 2], [2, 2], [0, 1, 0], [0, 0], [1, 0, 4, 0], [2, 0]],
475 [[1, 1], [1, 2], [0, 2], [0, 1, 2, 0], [0, 0], [1, 0], [2, 1, 0]]);
476  
477 =head3 The Noose
478  
479 6--5 3--4 3--4
480 | | | | | |
481 7 4 2 5 2 5--7
482 | | | | | |
483 1--2--3 1--6--7 1--6
484  
485 =cut
486  
487 0 push(@shapes,
488 [[0, 2], [1, 2], [2, 2], [2, 1], [2, 0], [1, 0], [1, 1, 1, 5]],
489 [[0, 2], [0, 1], [0, 0], [1, 0], [1, 1], [1, 2, 0, 4], [2, 2, 5]],
490 [[0, 2], [0, 1], [0, 0], [1, 0], [1, 1], [1, 2, 0, 4], [2, 1, 4]]);
491  
492 0 return $self->shape_trim($self->shape_flip(one(@shapes)), $n);
493 }
494  
495 1 ▶sub shape_flip {
Subroutine shape_flip: called CC=5 SCAR=21.8
Pod undocumented
496 1 my $self = shift;
497 1 my $shape = shift;
498 1 my $r = rand;
499 # in case we are debugging
500 # $r = 1;
501 1 ▶ if ($r < 0.20) {
Branch: 4 branches
BranchTrueFalseTotal
if ($r < 0.2) { } 0 1 1
elsif ($r < 0.4) { } 0 1 1
elsif ($r < 0.6) { } 1 0 1
elsif ($r < 0.8) { } 0 0 0
502 # flip vertically
503 0 $shape = [map{ $_->[1] = $self->dungeon_dimensions->[1] - 1 - $_->[1]; $_ } @$shape];
504 # $log->debug("flip vertically: " . join(", ", map { "[@$_]"} @$shape));
505 } elsif ($r < 0.4) {
506 # flip horizontally
507 0 $shape = [map{ $_->[0] = $self->dungeon_dimensions->[0] - 1 - $_->[0]; $_ } @$shape];
508 # $log->debug("flip horizontally: " . join(", ", map { "[@$_]"} @$shape));
509 } elsif ($r < 0.6) {
510 # flip diagonally
511 1 $shape = [map{ my $t = $_->[1]; $_->[1] = $_->[0]; $_->[0] = $t; $_ } @$shape];
512 # $log->debug("flip diagonally: " . join(", ", map { "[@$_]"} @$shape));
513 } elsif ($r < 0.8) {
514 # flip diagonally
515 0 $shape = [map{ $_->[0] = $self->dungeon_dimensions->[0] - 1 - $_->[0];
516 0 $_->[1] = $self->dungeon_dimensions->[1] - 1 - $_->[1];
517 0 $_ } @$shape];
518 # $log->debug("flip both: " . join(", ", map { "[@$_]"} @$shape));
519 }
520 1 return $shape;
521 }
522  
523 1 ▶sub shape_trim {
Subroutine shape_trim: called CC=1 SCAR=0.0
Pod undocumented
524 1 my $self = shift;
525 1 my $shape = shift;
526 1 my $n = shift;
527 1 splice(@$shape, $n);
528 1 return $shape;
529 }
530  
531 1 ▶sub shape_merge {
Subroutine shape_merge: called CC=7 SCAR=19.5
Pod undocumented
532 1 my $self = shift;
533 1 my @shapes = @_;
534 1 my $result = [];
535 1 my $cols = POSIX::ceil(sqrt(@shapes));
536 1 my $shift = [0, 0];
537 1 my $rooms = 0;
538 1 for my $shape (@shapes) {
539 # $log->debug(join(" ", "Shape", map { "[@$_]" } @$shape));
540 1 my $n = @$shape;
541 # $log->debug("Number of rooms for this shape is $n");
542 # $log->debug("Increasing coordinates by ($shift->[0], $shift->[1])");
543 1 for my $room (@$shape) {
544 5 $room->[0] += $shift->[0] * $self->dungeon_geomorph_size;
545 5 $room->[1] += $shift->[1] * $self->dungeon_geomorph_size;
546 5 for my $i (2 .. $#$room) {
547 # $log->debug("Increasing room reference $i ($room->[$i]) by $rooms");
548 2 $room->[$i] += $rooms;
549 }
550 5 push(@$result, $room);
551 }
552 1 ▶ $self->shape_reconnect($result, $n) if $n < @$result;
Branch: 1 branch
BranchTrueFalseTotal
if $n < @$result 0 1 1
553 1 ▶ if ($shift->[0] == $cols -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shift->[0] == $cols - 1) { } 1 0 1
554 1 $shift = [0, $shift->[1] + 1];
555 } else {
556 0 $shift = [$shift->[0] + 1, $shift->[1]];
557 }
558 1 $rooms += $n;
559 }
560 # Update globals
561 1 for my $dim (0, 1) {
562 2 $self->dungeon_dimensions->[$dim] = max(map { $_->[$dim] } @$result) + 1;
563 }
564 # $log->debug("Dimensions of the dungeon are (" . join(", ", map { $self->dungeon_dimensions->[$_] } 0, 1) . ")");
565 1 $self->recompute();
566 1 return $result;
567 }
568  
569 0 ▶sub shape_reconnect {
Subroutine shape_reconnect: not called CC=21 SCAR=61.4
Pod undocumented
570 0 my ($self, $result, $n) = @_;
571 0 my $rooms = @$result;
572 0 my $first = $rooms - $n;
573 # Disconnect the old room by adding an invalid self-reference to the first
574 # room of the last shape added; if there are just two numbers there, it would
575 # otherwise mean that the first room of the new shape connects to the last
576 # room of the previous shape and that is wrong.
577 # $log->debug("First of the shape is @{$result->[$first]}");
578 0 ▶ push(@{$result->[$first]}, $first) if @{$result->[$first]} == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @{$result->[$first];} == 2 0 0 0
579 # New connections can be either up or left, therefore only the rooms within
580 # this shape that are at the left or the upper edge need to be considered.
581 0 my @up_candidates;
582 my @left_candidates;
583 0 my $min_up;
584 0 my $min_left;
585 0 for my $start ($first .. $rooms - 1) {
586 0 my $x = $result->[$start]->[0];
587 0 my $y = $result->[$start]->[1];
588 # Check up: if we find a room in our set, this room is disqualified; if we
589 # find another room, record the distance, and the destination.
590 0 for my $end (0 .. $first - 1) {
591 0 ▶ next if $start == $end;
Branch: 1 branch
BranchTrueFalseTotal
if $start == $end 0 0 0
592 0 ▶ next if $result->[$end]->[0] != $x;
Branch: 1 branch
BranchTrueFalseTotal
if $result->[$end][0] != $x 0 0 0
593 0 my $d = $y - $result->[$end]->[1];
594 0 ▶ next if $min_up and $d > $min_up;
Branch: 1 branch
BranchTrueFalseTotal
if $min_up and $d > $min_up 0 0 0
Condition0%0/3
$min_up and $d > $min_up
!ll&&!rl&&r
000
MC/DC0%0/2
$min_up and $d > $min_up
$min_up $d > $min_up
Truth table0%0/3
A and B
A= $min_upB= $d > $min_up
ABresult
0X0
100
111
595 0 ▶ if (not $min_up or $d < $min_up) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $min_up or $d < $min_up) { } 0 0 0
Condition0%0/3
not $min_up or $d < $min_up
l!l&&r!l&&!r
000
MC/DC0%0/2
not $min_up or $d < $min_up
not $min_up $d < $min_up
Truth table0%0/3
not(A) or B
A= not $min_upB= $d < $min_up
ABresult
1X1
011
000
596 # $log->debug("$d for $start → $end is smaller than $min_up: ") if defined $min_up;
597 0 $min_up = $d;
598 0 @up_candidates = ([$start, $end]);
599 } else {
600 # $log->debug("$d for $start → $end is the same as $min_up");
601 0 push(@up_candidates, [$start, $end]);
602 }
603 }
604 # Check left: if we find a room in our set, this room is disqualified; if we
605 # find another room, record the distance, and the destination.
606 0 for my $end (0 .. $first - 1) {
607 0 ▶ next if $start == $end;
Branch: 1 branch
BranchTrueFalseTotal
if $start == $end 0 0 0
608 0 ▶ next if $result->[$end]->[1] != $y;
Branch: 1 branch
BranchTrueFalseTotal
if $result->[$end][1] != $y 0 0 0
609 0 my $d = $x - $result->[$end]->[0];
610 0 ▶ next if $min_left and $d > $min_left;
Branch: 1 branch
BranchTrueFalseTotal
if $min_left and $d > $min_left 0 0 0
Condition0%0/3
$min_left and $d > $min_left
!ll&&!rl&&r
000
MC/DC0%0/2
$min_left and $d > $min_left
$min_left $d > $min_left
Truth table0%0/3
A and B
A= $min_leftB= $d > $min_left
ABresult
0X0
100
111
611 0 ▶ if (not $min_left or $d < $min_left) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $min_left or $d < $min_left) { } 0 0 0
Condition0%0/3
not $min_left or $d < $min_left
l!l&&r!l&&!r
000
MC/DC0%0/2
not $min_left or $d < $min_left
not $min_left $d < $min_left
Truth table0%0/3
not(A) or B
A= not $min_leftB= $d < $min_left
ABresult
1X1
011
000
612 0 $min_left = $d;
613 0 @left_candidates = ([$start, $end]);
614 } else {
615 0 push(@left_candidates, [$start, $end]);
616 }
617 }
618 }
619 # $log->debug("up candidates: " . join(", ", map { join(" → ", map { $_ < 10 ? $_ : chr(55 + $_) } @$_) } @up_candidates));
620 # $log->debug("left candidates: " . join(", ", map { join(" → ", map { $_ < 10 ? $_ : chr(55 + $_) } @$_) } @left_candidates));
621 0 for (one(@up_candidates), one(@left_candidates)) {
622 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
623 0 $log->debug("Connecting " . join(" → ", map { sprintf("%2x", $_) } @$_));
624 0 my ($start, $end) = @$_;
625 0 ▶ if (@{$result->[$start]} == 3 and $result->[$start]->[2] == $start) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$result->[$start];} == 3 and $result->[$start][2] == $start) { } 0 0 0
Condition0%0/3
@{$result->[$start];} == 3 and $result->[$start][2] == $start
!ll&&!rl&&r
000
MC/DC0%0/2
@{$result->[$start];} == 3 and $result->[$start][2] == $start
@{$result->[$start];} == 3 $result->[$start][2] == $start
Truth table0%0/3
A and B
A= @{$result->[$start];} == 3B= $result->[$start][2] == $start
ABresult
0X0
100
111
626 # remove the fake connection if there is one
627 0 pop(@{$result->[$start]});
628 } else {
629 # connecting to the previous room (otherwise the new connection replaces
630 # the implicit connection to the previous room)
631 0 push(@{$result->[$start]}, $start - 1);
632 }
633 # connect to the new one
634 0 push(@{$result->[$start]}, $end);
635 }
636 }
637  
638 0 ▶sub debug_shapes {
Subroutine debug_shapes: not called CC=3 SCAR=24.8
Pod undocumented
639 0 my $self = shift;
640 0 my $shapes = shift;
641 0 my $map = [map { [ map { " " } 0 .. $self->dungeon_dimensions->[0] - 1] } 0 .. $self->dungeon_dimensions->[1] - 1];
642 0 $log->debug(join(" ", " ", map { sprintf("%2x", $_) } 0 .. $self->dungeon_dimensions->[0] - 1));
643 0 for my $n (0 .. $#$shapes) {
644 0 my $shape = $shapes->[$n];
645 0 $map->[ $shape->[1] ]->[ $shape->[0] ] = sprintf("%2x", $n);
646 }
647 0 for my $y (0 .. $self->dungeon_dimensions->[1] - 1) {
648 0 $log->debug(join(" ", sprintf("%2x", $y), @{$map->[$y]}));
649 }
650 }
651  
652 1 ▶sub shape {
Subroutine shape: called CC=9 SCAR=23.9
Pod undocumented
653 1 my $self = shift;
654 # note which rooms get stairs (identified by label!)
655 1 my $stairs;
656 # return an array of deltas to shift rooms around
657 1 my $num = shift;
658 1 my $shape = [];
659 # attempt to factor into 5 and 7 rooms
660 1 my $sevens = int($num/7);
661 1 my $rest = $num - 7 * $sevens; # $num % 7
662 1 ▶ while ($sevens > 0 and $rest % 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sevens > 0 and $rest % 5) 0 1 1
Condition33%1/3
$sevens > 0 and $rest % 5
!ll&&!rl&&r
100
MC/DC0%0/2
$sevens > 0 and $rest % 5
$sevens > 0 $rest % 5
Truth table33%1/3
A and B
A= $sevens > 0B= $rest % 5
ABresult
0X0
100
111
663 0 $sevens--;
664 0 $rest = $num - 7 * $sevens;
665 }
666 1 my $fives = POSIX::floor($rest/5);
667 1 my @sequence = shuffle((5) x $fives, (7) x $sevens);
668 1 $rest = $num - 7 * $sevens - 5 * $fives;
669 1 ▶ push(@sequence, $rest) if $rest;
Branch: 1 branch
BranchTrueFalseTotal
if $rest 0 1 1
670 1 $log->debug("Sequence for $num rooms: " . join(" ", @sequence));
671 1 ▶ $shape = $self->shape_merge(map { $_ == 7 ? $self->seven_room_shape($_) : $self->five_room_shape($_) } @sequence);
Branch: 1 branch
BranchTrueFalseTotal
$_ == 7 ? : 0 1 1
672 1 ▶ for (my $n = 0; @sequence; $n += shift(@sequence)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sequence) 1 1 2
673 1 push(@$stairs, $n + 1);
674 }
675 1 $log->debug(join(" ", "Stairs", @$stairs));
676 1 ▶ if (@$stairs > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stairs > 2) 0 1 1
677 0 @$stairs = shuffle(@$stairs);
678 0 my $n = POSIX::floor(log($#$stairs));
679 0 @$stairs = @$stairs[0 .. $n];
680 }
681 1 ▶ $self->debug_shapes($shape) if $log->level eq 'debug';
Branch: 1 branch
BranchTrueFalseTotal
if $log->level eq "debug" 0 1 1
682 1 $log->debug(join(", ", map { "[@$_]"} @$shape));
683 1 ▶ die("No appropriate dungeon shape found for $num rooms") unless @$shape;
Branch: 1 branch
BranchTrueFalseTotal
unless @$shape 0 1 1
684 1 return $shape, $stairs;
685 }
686  
687 0 ▶sub debug_tiles {
Subroutine debug_tiles: not called CC=3 SCAR=24.8
Pod undocumented
688 0 my $self = shift;
689 0 my $tiles = shift;
690 0 my $i = 0;
691 $log->debug(
692 join('', " " x 5,
693 map {
694 0 sprintf("% " . $self->room_dimensions->[0] . "d", $_ * $self->room_dimensions->[0])
695 } 1 .. $self->dungeon_dimensions->[0]));
696 0 ▶ while ($i < @$tiles) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$tiles) 0 0 0
697 $log->debug(
698 sprintf("%4d ", $i)
699 0 ▶ . join('', map { $_ ? "X" : " " } @$tiles[$i .. $i + $self->row - 1]));
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
700 0 $i += $self->row;
701 }
702 }
703  
704 1 ▶sub add_rooms {
Subroutine add_rooms: called CC=1 SCAR=0.0
Pod undocumented
705 1 my $self = shift;
706 # Get the rooms and the deltas, draw it all on a big grid. Don't forget the
707 # two-tile border around it all.
708 1 my $rooms = shift;
709 1 my $deltas = shift;
710 1 my @tiles;
711 5 ▶ pairwise {
Subroutine __ANON__: called CC=3 SCAR=11.0
712 5 my $room = $a;
713 5 my $delta = $b;
714 # $log->debug("Draw room shifted by delta (@$delta)");
715 # copy the room, shifted appropriately
716 5 for my $x (0 .. $self->room_dimensions->[0] - 1) {
717 25 for my $y (0 .. $self->room_dimensions->[0] - 1) {
718 # my $v =
719 125 $tiles[$x + $delta->[0] * $self->room_dimensions->[0] + 2
720 + ($y + $delta->[1] * $self->room_dimensions->[1] + 2)
721 * $self->row]
722 = $room->[$x + $y * $self->room_dimensions->[0]];
723 }
724 }
725 1 } @$rooms, @$deltas;
726 # $self->debug_tiles(\@tiles) if $log->level eq 'debug';
727 1 return \@tiles;
728 }
729  
730 1 ▶sub add_corridors {
Subroutine add_corridors: called CC=8 SCAR=21.0
Pod undocumented
731 1 my $self = shift;
732 1 my $tiles = shift;
733 1 my $shapes = shift; # reference to the original
734 1 my @shapes = @$shapes; # a copy that gets shorter
735 1 my $from = shift(@shapes);
736 1 my $delta;
737 1 for my $to (@shapes) {
738 4 ▶ if (@$to == 3
Branch: 2 branches
BranchTrueFalseTotal
if (@$to == 3 and $to->[0] == $$shapes[$to->[2]][0] and $to->[1] == $$shapes[$to->[2]][1]) { } 0 4 4
elsif (@$to == 2) { } 2 2 4
Condition83%5/6
@$to == 3 and $to->[0] == $$shapes[$to->[2]][0] and $to->[1] == $$shapes[$to->[2]][1]
!ll&&!rl&&r
310
@$to == 3 and $to->[0] == $$shapes[$to->[2]][0]
!ll&&!rl&&r
211
MC/DC0%0/3
@$to == 3 and $to->[0] == $$shapes[$to->[2]][0] and $to->[1] == $$shapes[$to->[2]][1]
@$to == 3 $to->[0] == $$shapes[$to->[2]][0] $to->[1] == $$shapes[$to->[2]][1]
Truth table75%3/4
A and B and C
A= @$to == 3B= $to->[0] == $$shapes[$to->[2]][0]C= $to->[1] == $$shapes[$to->[2]][1]
ABCresult
0XX0
10X0
1100
1111
739 and $to->[0] == $shapes->[$to->[2]]->[0]
740 and $to->[1] == $shapes->[$to->[2]]->[1]) {
741 # If the preceding shape is pointing to ourselves, then this room is
742 # disconnected: don't add a corridor.
743 # $log->debug("No corridor from @$from to @$to");
744 0 $from = $to;
745 } elsif (@$to == 2) {
746 # The default case is that the preceding shape is our parent. A simple
747 # railroad!
748 # $log->debug("Regular from @$from to @$to");
749 2 $tiles = $self->add_corridor($tiles, $from, $to, $self->get_delta($from, $to));
750 2 $from = $to;
751 } else {
752 # In case the shapes are not connected in order, the parent shapes are
753 # available as extra elements.
754 2 for my $from (map { $shapes->[$_] } @$to[2 .. $#$to]) {
755 # $log->debug("Branch from @$from to @$to");
756 2 $tiles = $self->add_corridor($tiles, $from, $to, $self->get_delta($from, $to));
757 }
758 2 $from = $to;
759 }
760 }
761 1 ▶ $self->debug_tiles($tiles) if $log->level eq 'debug';
Branch: 1 branch
BranchTrueFalseTotal
if $log->level eq "debug" 0 1 1
762 1 return $tiles;
763 }
764  
765 4 ▶sub get_delta {
Subroutine get_delta: called CC=5 SCAR=16.7
Pod undocumented
766 4 my $self = shift;
767 4 my $from = shift;
768 4 my $to = shift;
769 # Direction: north is minus an entire row, south is plus an entire row, east
770 # is plus one, west is minus one. Return an array reference with three
771 # elements: how to get the next element and how to get the two elements to the
772 # left and right.
773 4 ▶ if ($to->[0] < $from->[0]) {
Branch: 4 branches
BranchTrueFalseTotal
if ($to->[0] < $from->[0]) { } 2 2 4
elsif ($to->[0] > $from->[0]) { } 0 2 2
elsif ($to->[1] < $from->[1]) { } 1 1 2
elsif ($to->[1] > $from->[1]) { } 1 0 1
774 # $log->debug("west");
775 2 return [-1, - $self->row, $self->row];
776 } elsif ($to->[0] > $from->[0]) {
777 # $log->debug("east");
778 0 return [1, - $self->row, $self->row];
779 } elsif ($to->[1] < $from->[1]) {
780 # $log->debug("north");
781 1 return [- $self->row, 1, -1];
782 } elsif ($to->[1] > $from->[1]) {
783 # $log->debug("south");
784 1 return [$self->row, 1, -1];
785 } else {
786 0 $log->warn("unclear direction: bogus shape?");
787 }
788 }
789  
790 8 ▶sub position_in {
Subroutine position_in: called CC=1 SCAR=0.0
Pod undocumented
791 8 my $self = shift;
792 # Return a position in the big array corresponding to the midpoint in a room.
793 # Don't forget the two-tile border.
794 8 my $delta = shift;
795 8 my $x = int($self->room_dimensions->[0]/2) + 2;
796 8 my $y = int($self->room_dimensions->[1]/2) + 2;
797 8 return $x + $delta->[0] * $self->room_dimensions->[0]
798 + ($y + $delta->[1] * $self->room_dimensions->[1]) * $self->row;
799 }
800  
801 4 ▶sub add_corridor {
Subroutine add_corridor: called CC=7 SCAR=19.5
Pod undocumented
802 4 my $self = shift;
803 # In the example below, we're going east from F to T. In order to make sure
804 # that we also connect rooms in (0,0)-(1,1), we start one step earlier (1,2)
805 # and end one step later (8,2).
806 #
807 # 0123456789
808 # 0
809 # 1
810 # 2 F T
811 # 3
812 # 4
813 4 my $tiles = shift;
814 4 my $from = shift;
815 4 my $to = shift;
816 # $log->debug("Drawing a corridor [@$from]-[@$to]");
817 # Delta has three elements: forward, left and right indexes.
818 4 my $delta = shift;
819 # Convert $from and $to to indexes into the tiles array.
820 4 $from = $self->position_in($from) - 2 * $delta->[0];
821 4 $to = $self->position_in($to) + 2 * $delta->[0];
822 4 my $n = 0;
823 4 my $contact = 0;
824 4 my $started = 0;
825 4 my @undo;
826 # $log->debug("Drawing a corridor $from-$to");
827 4 ▶ while (not grep { $to == ($from + $_) } @$delta) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$to == $from + $_;} @$delta) 32 4 36
828 32 $from += $delta->[0];
829 # contact is if we're on a room, or to the left or right of a room (but not in front of a room)
830 32 ▶ $contact = any { $self->something($tiles, $from, $_) } 0, $delta->[1], $delta->[2];
Subroutine __ANON__: called CC=1 SCAR=0.0
831 32 ▶ if ($contact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contact) { } 24 8 32
832 24 $started = 1;
833 24 @undo = ();
834 } else {
835 8 push(@undo, $from);
836 }
837 32 ▶ $tiles->[$from] = ["empty"] if $started and not $tiles->[$from];
Branch: 1 branch
BranchTrueFalseTotal
if $started and not $tiles->[$from] 7 25 32
Condition100%3/3
$started and not $tiles->[$from]
!ll&&!rl&&r
1247
MC/DC100%2/2
$started and not $tiles->[$from]
$started not $tiles->[$from]
Truth table100%3/3
A and not(B)
A= $startedB= not $tiles->[$from]
ABresult
0X0
100
111
838 32 ▶ last if $n++ > 20; # safety!
Branch: 1 branch
BranchTrueFalseTotal
if $n++ > 20 0 32 32
839 }
840 4 for (@undo) {
841 1 $tiles->[$_] = undef;
842 }
843 4 return $tiles;
844 }
845  
846 1 ▶sub add_doors {
Subroutine add_doors: called CC=14 SCAR=26.6
Pod undocumented
847 1 my $self = shift;
848 1 my $tiles = shift;
849 # Doors can be any tile that has three or four neighbours, including
850 # diagonally:
851 #
852 # ▓▓ ▓▓
853 # ▓▓▒▓ ▓▓▒▓
854 # ▓▓
855 1 my @types = qw(door door door door door door secret secret archway concealed);
856 # first two neighbours must be clear, the next two must be set, and one of the others must be set as well
857 1 my %test = (n => [-1, 1, -$self->row, $self->row, -$self->row + 1, -$self->row - 1],
858 e => [-$self->row, $self->row, -1, 1, $self->row + 1, -$self->row + 1],
859 s => [-1, 1, -$self->row, $self->row, $self->row + 1, $self->row - 1],
860 w => [-$self->row, $self->row, -1, 1, $self->row - 1, -$self->row - 1]);
861 1 my @doors;
862 1 for my $here (shuffle 1 .. scalar(@$tiles) - 1) {
863 315 for my $dir (shuffle qw(n e s w)) {
864 1260 ▶ if ($tiles->[$here]
Branch: 1 branch
BranchTrueFalseTotal
if ($tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and $self->something($tiles, $here, $test{$dir}[2]) and $self->something($tiles, $here, $test{$dir}[3]) and $self->something($tiles, $here, $test{$dir}[4]) || $self->something($tiles, $here, $test{$dir}[5]) and not $self->doors_nearby($here, \@doors)) 4 1256 1260
Condition90%19/21
$tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and $self->something($tiles, $here, $test{$dir}[2]) and $self->something($tiles, $here, $test{$dir}[3]) and $self->something($tiles, $here, $test{$dir}[4]) || $self->something($tiles, $here, $test{$dir}[5]) and not $self->doors_nearby($here, \@doors)
!ll&&!rl&&r
125244
$tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and $self->something($tiles, $here, $test{$dir}[2]) and $self->something($tiles, $here, $test{$dir}[3]) and $self->something($tiles, $here, $test{$dir}[4]) || $self->something($tiles, $here, $test{$dir}[5])
!ll&&!rl&&r
124848
$tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and $self->something($tiles, $here, $test{$dir}[2]) and $self->something($tiles, $here, $test{$dir}[3])
!ll&&!rl&&r
1248012
$tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and $self->something($tiles, $here, $test{$dir}[2])
!ll&&!rl&&r
1248012
$tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1])
!ll&&!rl&&r
11945412
$tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0])
!ll&&!rl&&r
104814666
$self->something($tiles, $here, $test{$dir}[4]) or $self->something($tiles, $here, $test{$dir}[5])
l!l&&r!l&&!r
624
MC/DC75%6/8
$tiles->[$here] and not $self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and $self->something($tiles, $here, $test{$dir}[2]) and $self->something($tiles, $here, $test{$dir}[3]) and $self->something($tiles, $here, $test{$dir}[4]) || $self->something($tiles, $here, $test{$dir}[5]) and not $self->doors_nearby($here, \@doors)
$tiles->[$here] not $self->something($tiles, $here, $test{$dir}[0]) not $self->something($tiles, $here, $test{$dir}[1]) $self->something($tiles, $here, $test{$dir}[2]) $self->something($tiles, $here, $test{$dir}[3]) $self->something($tiles, $here, $test{$dir}[4]) $self->something($tiles, $here, $test{$dir}[5]) not $self->doors_nearby($here, \@doors)
Truth table80%8/10
A and not(B) and not(C) and D and E and F or G and not(H)
A= $tiles->[$here]B= not $self->something($tiles, $here, $test{$dir}[0])C= not $self->something($tiles, $here, $test{$dir}[1])D= $self->something($tiles, $here, $test{$dir}[2])E= $self->something($tiles, $here, $test{$dir}[3])F= $self->something($tiles, $here, $test{$dir}[4])G= $self->something($tiles, $here, $test{$dir}[5])H= not $self->doors_nearby($here, \@doors)
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
1111100X0
111111X00
111110100
111111X11
111110111
865 and not $self->something($tiles, $here, $test{$dir}->[0])
866 and not $self->something($tiles, $here, $test{$dir}->[1])
867 and $self->something($tiles, $here, $test{$dir}->[2])
868 and $self->something($tiles, $here, $test{$dir}->[3])
869 and ($self->something($tiles, $here, $test{$dir}->[4])
870 or $self->something($tiles, $here, $test{$dir}->[5]))
871 and not $self->doors_nearby($here, \@doors)) {
872 4 ▶ $log->warn("$here content isn't 'empty'") unless $tiles->[$here]->[0] eq "empty";
Branch: 1 branch
BranchTrueFalseTotal
unless $tiles->[$here][0] eq "empty" 0 4 4
873 4 my $type = one(@types);
874 4 my $variant = $dir;
875 4 my $target = $here;
876 # this makes sure doors are on top
877 0 ▶ if ($dir eq "s") { $target += $self->row; $variant = "n"; }
Branch: 2 branches
BranchTrueFalseTotal
if ($dir eq 's') { } 0 4 4
elsif ($dir eq 'e') { } 1 3 4
878 1 elsif ($dir eq "e") { $target += 1; $variant = "w"; }
879 4 push(@{$tiles->[$target]}, "$type-$variant");
880 4 push(@doors, $here);
881 }
882 }
883 }
884 1 return $tiles;
885 }
886  
887 8 ▶sub doors_nearby {
Subroutine doors_nearby: called CC=3 SCAR=11.0
Pod undocumented
888 8 my $self = shift;
889 8 my $here = shift;
890 8 my $doors = shift;
891 8 for my $door (@$doors) {
892 16 ▶ return 1 if $self->distance($door, $here) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->distance($door, $here) < 2 4 12 16
893 }
894 4 return 0;
895 }
896  
897 289 ▶sub distance {
Subroutine distance: called CC=1 SCAR=0.0
Pod undocumented
898 289 my $self = shift;
899 289 my $from = shift;
900 289 my $to = shift;
901 289 my $dx = $to % $self->row - $from % $self->row;
902 289 my $dy = int($to/$self->row) - int($from/$self->row);
903 289 return sqrt($dx * $dx + $dy * $dy);
904 }
905  
906 1 ▶sub add_stair {
Subroutine add_stair: called CC=21 SCAR=36.3
Pod undocumented
907 1 my $self = shift;
908 1 my $tiles = shift;
909 1 my $stairs = shift;
910 STAIR:
911 1 for my $room (@$stairs) {
912 # find the middle using the label
913 1 my $start;
914 1 for my $i (0 .. scalar(@$tiles) - 1) {
915 185 ▶ next unless $tiles->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $tiles->[$i] 154 31 185
916 31 $start = $i;
917 31 ▶ last if grep { $_ eq qq{"$room"} } @{$tiles->[$i]};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq qq["$room"];} @{$$tiles[$i];} 1 30 31
918 }
919 # The first test refers to a tile that must be set to "empty" (where the stair
920 # will end), all others must be undefined. Note that stairs are anchored at
921 # the top end, and we're placing a stair that goes *down*. So what we're
922 # looking for is the point (4,1) in the image below:
923 #
924 # 12345
925 # 1 EE<<
926 # 2 EE
927 #
928 # Remember, +1 is east, -1 is west, -$row is north, +$row is south. The anchor
929 # point we're testing is already known to be undefined.
930 1 my %test = (n => [-2 * $self->row,
931 -$self->row - 1, -$self->row, -$self->row + 1,
932 -1, +1,
933 +$self->row - 1, +$self->row, +$self->row + 1],
934 e => [+2,
935 -$self->row + 1, +1, +$self->row + 1,
936 -$self->row, +$self->row,
937 -$self->row - 1, -1, +$self->row - 1]);
938 1 $test{s} = [map { -$_ } @{$test{n}}];
939 1 $test{w} = [map { -$_ } @{$test{e}}];
940 # First round: limit ourselves to stair positions close to the start.
941 1 my %candidates;
942 1 for my $here (shuffle 0 .. scalar(@$tiles) - 1) {
943 316 ▶ next if $tiles->[$here];
Branch: 1 branch
BranchTrueFalseTotal
if $tiles->[$here] 53 263 316
944 263 my $distance = $self->distance($here, $start);
945 263 ▶ $candidates{$here} = $distance if $distance <= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $distance <= 4 37 226 263
946 }
947 # Second round: for each candidate, test stair placement and record the
948 # distance of the landing to the start and the direction of every successful
949 # stair.
950 1 my $stair;
951 my $stair_dir;
952 1 my $stair_distance = $self->max_tiles;
953 1 for my $here (sort {$a cmp $b} keys %candidates) {
954 # push(@{$tiles->[$here]}, "red");
955 37 for my $dir (shuffle qw(n e w s)) {
956 148 my @test = @{$test{$dir}};
957 148 my $first = shift(@test);
958 148 ▶ if (# the first test is an empty tile: this the stair's landing
Branch: 1 branch
BranchTrueFalseTotal
if ($self->empty($tiles, $here, $first) and &none(sub { $self->something($tiles, $here, $_); } , @test)) 10 138 148
Condition100%3/3
$self->empty($tiles, $here, $first) and &none(sub { $self->something($tiles, $here, $_); } , @test)
!ll&&!rl&&r
1092910
MC/DC100%2/2
$self->empty($tiles, $here, $first) and &none(sub { $self->something($tiles, $here, $_); } , @test)
$self->empty($tiles, $here, $first) &none(sub { $self->something($tiles, $here, $_); } , @test)
Truth table100%3/3
A and B
A= $self->empty($tiles, $here, $first)B= &none(sub { $self->something($tiles, $here, $_); } , @test)
ABresult
0X0
100
111
959 $self->empty($tiles, $here, $first)
960 # and the stair is surrounded by empty space
961 131 ▶ and none { $self->something($tiles, $here, $_) } @test) {
Subroutine __ANON__: called CC=1 SCAR=0.0
962 10 my $distance = $self->distance($here + $first, $start);
963 10 ▶ if ($distance < $stair_distance) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distance < $stair_distance) 2 8 10
964 # $log->debug("Considering stair-$dir for $here ($distance)");
965 2 $stair = $here;
966 2 $stair_dir = $dir;
967 2 $stair_distance = $distance;
968 }
969 }
970 }
971 }
972 1 ▶ if (defined $stair) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stair) 1 0 1
973 1 push(@{$tiles->[$stair]}, "stair-$stair_dir");
974 1 next STAIR;
975 }
976 # $log->debug("Unable to place a regular stair, trying to place a spiral staircase");
977 0 for my $here (shuffle 0 .. scalar(@$tiles) - 1) {
978 0 ▶ next unless $tiles->[$here];
Branch: 1 branch
BranchTrueFalseTotal
unless $tiles->[$here] 0 0 0
979 0 ▶ if (# close by
Branch: 1 branch
BranchTrueFalseTotal
if ($self->distance($here, $start) < 3 and @{$tiles->[$here];} == 1 and $tiles->[$here][0] eq "empty" and not grep({/-n$/u;} @{$$tiles[$here + $self->row];}) and not grep({/-w$/u;} @{$$tiles[$here + 1];})) 0 0 0
Condition0%0/12
$self->distance($here, $start) < 3 and @{$tiles->[$here];} == 1 and $tiles->[$here][0] eq "empty" and not grep({/-n$/u;} @{$$tiles[$here + $self->row];}) and not grep({/-w$/u;} @{$$tiles[$here + 1];})
!ll&&!rl&&r
000
$self->distance($here, $start) < 3 and @{$tiles->[$here];} == 1 and $tiles->[$here][0] eq "empty" and not grep({/-n$/u;} @{$$tiles[$here + $self->row];})
!ll&&!rl&&r
000
$self->distance($here, $start) < 3 and @{$tiles->[$here];} == 1 and $tiles->[$here][0] eq "empty"
!ll&&!rl&&r
000
$self->distance($here, $start) < 3 and @{$tiles->[$here];} == 1
!ll&&!rl&&r
000
MC/DC0%0/5
$self->distance($here, $start) < 3 and @{$tiles->[$here];} == 1 and $tiles->[$here][0] eq "empty" and not grep({/-n$/u;} @{$$tiles[$here + $self->row];}) and not grep({/-w$/u;} @{$$tiles[$here + 1];})
$self->distance($here, $start) < 3 @{$tiles->[$here];} == 1 $tiles->[$here][0] eq "empty" not grep({/-n$/u;} @{$$tiles[$here + $self->row];}) not grep({/-w$/u;} @{$$tiles[$here + 1];})
Truth table0%0/6
A and B and C and not(D) and not(E)
A= $self->distance($here, $start) < 3B= @{$tiles->[$here];} == 1C= $tiles->[$here][0] eq "empty"D= not grep({/-n$/u;} @{$$tiles[$here + $self->row];})E= not grep({/-w$/u;} @{$$tiles[$here + 1];})
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
980 $self->distance($here, $start) < 3
981 # and the landing is empty (no statue, doors n or w)
982 0 and @{$tiles->[$here]} == 1
983 and $tiles->[$here]->[0] eq "empty"
984 # and the landing to the south has no door n
985 0 and not grep { /-n$/ } @{$tiles->[$here+$self->row]}
986 # and the landing to the east has no door w
987 0 and not grep { /-w$/ } @{$tiles->[$here+1]}) {
988 0 $log->debug("Placed spiral stair at $here");
989 0 $tiles->[$here]->[0] = "stair-spiral";
990 0 next STAIR;
991 }
992 }
993 0 $log->warn("Unable to place a stair!");
994 0 next STAIR;
995 }
996 1 return $tiles;
997 }
998  
999 0 ▶sub add_small_stair {
Subroutine add_small_stair: not called CC=7 SCAR=40.3
Pod undocumented
1000 0 my $self = shift;
1001 0 my $tiles = shift;
1002 0 my $stairs = shift;
1003 0 my %delta = (n => -$self->row, e => 1, s => $self->row, w => -1);
1004 STAIR:
1005 0 for my $room (@$stairs) {
1006 # find the middle using the label
1007 0 my $start;
1008 0 for my $i (0 .. scalar(@$tiles) - 1) {
1009 0 ▶ next unless $tiles->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $tiles->[$i] 0 0 0
1010 0 $start = $i;
1011 0 ▶ last if grep { $_ eq qq{"$room"} } @{$tiles->[$i]};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq qq["$room"];} @{$$tiles[$i];} 0 0 0
1012 }
1013 0 for (shuffle qw(n e w s)) {
1014 0 ▶ if (grep { $_ eq "empty" } @{$tiles->[$start + $delta{$_}]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "empty";} @{$$tiles[$start + $delta{$_}];}) 0 0 0
1015 0 push(@{$tiles->[$start + $delta{$_}]}, "stair-spiral");
1016 0 next STAIR;
1017 }
1018 }
1019 }
1020 0 return $tiles;
1021 }
1022  
1023 1 ▶sub fix_corners {
Subroutine fix_corners: called CC=20 SCAR=56.1
Pod undocumented
1024 1 my $self = shift;
1025 1 my $tiles = shift;
1026 1 my %look = (n => -$self->row, e => 1, s => $self->row, w => -1);
1027 1 for my $here (0 .. scalar(@$tiles) - 1) {
1028 316 for (@{$tiles->[$here]}) {
1029 63 ▶ if (/^(arc|diagonal)-(ne|nw|se|sw)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(arc|diagonal)-(ne|nw|se|sw)$/u) 0 63 63
1030 0 my $dir = $2;
1031 # debug_neighbours($tiles, $here);
1032 0 ▶ if (substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $tiles->[$here + $self->row] and @{$tiles->[$here + $self->row]}
Branch: 1 branch
BranchTrueFalseTotal
if (substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];} or substr($dir, 0, 1) eq "s" and $here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];} or substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];} or substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}) 0 0 0
Condition0%0/27
substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];} or substr($dir, 0, 1) eq "s" and $here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];} or substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];} or substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
l!l&&r!l&&!r
000
substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];} or substr($dir, 0, 1) eq "s" and $here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];} or substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];}
l!l&&r!l&&!r
000
substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];} or substr($dir, 0, 1) eq "s" and $here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];}
l!l&&r!l&&!r
000
substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];}
!ll&&!rl&&r
000
substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $$tiles[$here + $self->row]
!ll&&!rl&&r
000
substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles
!ll&&!rl&&r
000
substr($dir, 0, 1) eq "s" and $here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];}
!ll&&!rl&&r
000
substr($dir, 0, 1) eq "s" and $here > $self->row and $$tiles[$here - $self->row]
!ll&&!rl&&r
000
substr($dir, 0, 1) eq "s" and $here > $self->row
!ll&&!rl&&r
000
MC/DC0%0/10
substr($dir, 0, 1) eq "n" and $here + $self->row < $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];} or substr($dir, 0, 1) eq "s" and $here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];} or substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];} or substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
substr($dir, 0, 1) eq "n" $here + $self->row < $self->max_tiles $$tiles[$here + $self->row] @{$$tiles[$here + $self->row];} substr($dir, 0, 1) eq "s" $here > $self->row $$tiles[$here - $self->row] @{$$tiles[$here - $self->row];} substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];} substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
Truth table0%0/53
A and B and C and D or E and F and G and H or I or J
A= substr($dir, 0, 1) eq "n"B= $here + $self->row < $self->max_tilesC= $$tiles[$here + $self->row]D= @{$$tiles[$here + $self->row];}E= substr($dir, 0, 1) eq "s"F= $here > $self->rowG= $$tiles[$here - $self->row]H= @{$$tiles[$here - $self->row];}I= substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];}J= substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
ABCDEFGHIJresult
1111XXXXXX1
0XXX1111XX1
10XX1111XX1
110X1111XX1
11101111XX1
0XXX0XXX1X1
0XXX10XX1X1
0XXX110X1X1
0XXX11101X1
10XX0XXX1X1
10XX10XX1X1
10XX110X1X1
10XX11101X1
110X0XXX1X1
110X10XX1X1
110X110X1X1
110X11101X1
11100XXX1X1
111010XX1X1
1110110X1X1
111011101X1
0XXX0XXX011
0XXX10XX011
0XXX110X011
0XXX1110011
10XX0XXX011
10XX10XX011
10XX110X011
10XX1110011
110X0XXX011
110X10XX011
110X110X011
110X1110011
11100XXX011
111010XX011
1110110X011
11101110011
0XXX0XXX000
0XXX10XX000
0XXX110X000
0XXX1110000
10XX0XXX000
10XX10XX000
10XX110X000
10XX1110000
110X0XXX000
110X10XX000
110X110X000
110X1110000
11100XXX000
111010XX000
1110110X000
11101110000
1033 0 ▶ or substr($dir, 0, 1) eq "s" and $here > $self->row and $tiles->[$here - $self->row] and @{$tiles->[$here - $self->row]}
Condition0%0/9
substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];}
!ll&&!rl&&r
000
substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1]
!ll&&!rl&&r
000
substr($dir, 1) eq "e" and $here > 0
!ll&&!rl&&r
000
MC/DC0%0/4
substr($dir, 1) eq "e" and $here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];}
substr($dir, 1) eq "e" $here > 0 $$tiles[$here - 1] @{$$tiles[$here - 1];}
Truth table0%0/5
A and B and C and D
A= substr($dir, 1) eq "e"B= $here > 0C= $$tiles[$here - 1]D= @{$$tiles[$here - 1];}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1034 0 ▶ or substr($dir, 1) eq "e" and $here > 0 and $tiles->[$here - 1] and @{$tiles->[$here - 1]}
Condition0%0/9
substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
!ll&&!rl&&r
000
substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1]
!ll&&!rl&&r
000
substr($dir, 1) eq "w" and $here < $self->max_tiles
!ll&&!rl&&r
000
MC/DC0%0/4
substr($dir, 1) eq "w" and $here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
substr($dir, 1) eq "w" $here < $self->max_tiles $$tiles[$here + 1] @{$$tiles[$here + 1];}
Truth table0%0/5
A and B and C and D
A= substr($dir, 1) eq "w"B= $here < $self->max_tilesC= $$tiles[$here + 1]D= @{$$tiles[$here + 1];}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1035 0 or substr($dir, 1) eq "w" and $here < $self->max_tiles and $tiles->[$here + 1] and @{$tiles->[$here + 1]}) {
1036 0 $_ = "empty";
1037 }
1038 }
1039 }
1040 }
1041 1 return $tiles;
1042 }
1043  
1044 1 ▶sub fix_pillars {
Subroutine fix_pillars: called CC=8 SCAR=30.5
Pod undocumented
1045 1 my $self = shift;
1046 1 my $tiles = shift;
1047 # This is: $test{n}->[0] is straight ahead (e.g. looking north), $test{n}->[1]
1048 # is to the left (e.g. looking north-west), $test{n}->[2] is to the right
1049 # (e.g. looking north-east).
1050 1 my %test = (n => [-$self->row, -$self->row - 1, -$self->row + 1],
1051 e => [1, 1 - $self->row, 1 + $self->row],
1052 s => [$self->row, $self->row - 1, $self->row + 1],
1053 w => [-1, -1 - $self->row, -1 + $self->row]);
1054 1 for my $here (0 .. scalar(@$tiles) - 1) {
1055 TILE:
1056 316 for (@{$tiles->[$here]}) {
1057 63 ▶ if ($_ eq "pillar") {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "pillar") 0 63 63
1058 # $log->debug("$here: $_");
1059 # debug_neighbours($tiles, $here);
1060 0 for my $dir (qw(n e w s)) {
1061 0 ▶ if ($self->something($tiles, $here, $test{$dir}->[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and not $self->something($tiles, $here, $test{$dir}[2])) 0 0 0
Condition0%0/6
$self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and not $self->something($tiles, $here, $test{$dir}[2])
!ll&&!rl&&r
000
$self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1])
!ll&&!rl&&r
000
MC/DC0%0/3
$self->something($tiles, $here, $test{$dir}[0]) and not $self->something($tiles, $here, $test{$dir}[1]) and not $self->something($tiles, $here, $test{$dir}[2])
$self->something($tiles, $here, $test{$dir}[0]) not $self->something($tiles, $here, $test{$dir}[1]) not $self->something($tiles, $here, $test{$dir}[2])
Truth table0%0/4
A and not(B) and not(C)
A= $self->something($tiles, $here, $test{$dir}[0])B= not $self->something($tiles, $here, $test{$dir}[1])C= not $self->something($tiles, $here, $test{$dir}[2])
ABCresult
0XX0
10X0
1100
1111
1062 and not $self->something($tiles, $here, $test{$dir}->[1])
1063 and not $self->something($tiles, $here, $test{$dir}->[2])) {
1064 # $log->debug("Removing pillar $here");
1065 0 $_ = "empty";
1066 0 next TILE;
1067 }
1068 }
1069 }
1070 }
1071 }
1072 1 return $tiles;
1073 }
1074  
1075 0 ▶sub to_rocks {
Subroutine to_rocks: not called CC=8 SCAR=42.8
Pod undocumented
1076 0 my $self = shift;
1077 0 my $tiles = shift;
1078 # These are the directions we know (where m is the center). Order is important
1079 # so that list comparison is made easy.
1080 0 my @dirs = qw(n e w s);
1081 0 my %delta = (n => -$self->row, e => 1, s => $self->row, w => -1);
1082 # these are all the various rock configurations we know about; listed are the
1083 # fields that must be "empty" for this to work
1084 0 my %rocks = ("rock-n" => [qw(e w s)],
1085 "rock-ne" => [qw(w s)],
1086 "rock-ne-alternative" => [qw(w s)],
1087 "rock-e" => [qw(n w s)],
1088 "rock-se" => [qw(n w)],
1089 "rock-se-alternative" => [qw(n w)],
1090 "rock-s" => [qw(n e w)],
1091 "rock-sw" => [qw(n e)],
1092 "rock-sw-alternative" => [qw(n e)],
1093 "rock-w" => [qw(n e s)],
1094 "rock-nw" => [qw(e s)],
1095 "rock-nw-alternative" => [qw(e s)],
1096 "rock-dead-end-n" => [qw(s)],
1097 "rock-dead-end-e" => [qw(w)],
1098 "rock-dead-end-s" => [qw(n)],
1099 "rock-dead-end-w" => [qw(e)],
1100 "rock-corridor-n" => [qw(n s)],
1101 "rock-corridor-s" => [qw(n s)],
1102 "rock-corridor-e" => [qw(e w)],
1103 "rock-corridor-w" => [qw(e w)], );
1104 # my $first = 1;
1105 0 for my $here (0 .. scalar(@$tiles) - 1) {
1106 TILE:
1107 0 for (@{$tiles->[$here]}) {
1108 0 ▶ next unless grep { $_ eq "empty" } @{$tiles->[$here]};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "empty";} @{$$tiles[$here];} 0 0 0
1109 0 ▶ if (not $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $_) { } 0 0 0
1110 0 ▶ $_ = "rock" if all { grep { $_ } $self->something($tiles, $here, $_) } qw(n e w s);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &all(sub { grep {$_;} $self->something($tiles, $here, $_); } , "n", "e", "w", "s") 0 0 0
1111 } else {
1112 # loop through all the rock tiles and compare the patterns
1113 ROCK:
1114 0 for my $rock (keys %rocks) {
1115 0 my $expected = $rocks{$rock};
1116 my @actual = grep {
1117 0 my $dir = $_;
1118 0 $self->something($tiles, $here, $delta{$dir});
1119 } @dirs;
1120 0 ▶ if (list_equal($expected, \@actual)) {
Branch: 1 branch
BranchTrueFalseTotal
if (list_equal($expected, \@actual)) 0 0 0
1121 0 $_ = $rock;
1122 0 next TILE;
1123 }
1124 }
1125 }
1126 }
1127 }
1128 0 return $tiles;
1129 }
1130  
1131 0 ▶sub list_equal {
Subroutine list_equal: not called CC=4 SCAR=30.0
Pod undocumented
1132 0 my $a1 = shift;
1133 0 my $a2 = shift;
1134 0 ▶ return 0 if @$a1 ne @$a2;
Branch: 1 branch
BranchTrueFalseTotal
if @$a1 ne @$a2 0 0 0
1135 0 ▶ for (my $i = 0; $i <= $#$a1; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $a1->$#*) 0 0 0
1136 0 ▶ return unless $a1->[$i] eq $a2->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $a1->[$i] eq $a2->[$i] 0 0 0
1137 }
1138 0 return 1;
1139 }
1140  
1141 0 ▶sub coordinates {
Subroutine coordinates: not called CC=1 SCAR=6.9
Pod undocumented
1142 0 my $self = shift;
1143 0 my $here = shift;
1144 0 return sprintf("%d,%d", int($here/$self->row), $here % $self->row);
1145 }
1146  
1147 647 ▶sub legal {
Subroutine legal: called CC=7 SCAR=23.4
Pod undocumented
1148 647 my $self = shift;
1149 # is this position on the map?
1150 647 my $here = shift;
1151 647 my $delta = shift;
1152 647 ▶ return if $here + $delta < 0 or $here + $delta > $self->max_tiles;
Branch: 1 branch
BranchTrueFalseTotal
if $here + $delta < 0 or $here + $delta > $self->max_tiles 0 647 647
Condition33%1/3
$here + $delta < 0 or $here + $delta > $self->max_tiles
l!l&&r!l&&!r
00647
MC/DC0%0/2
$here + $delta < 0 or $here + $delta > $self->max_tiles
$here + $delta < 0 $here + $delta > $self->max_tiles
Truth table33%1/3
A or B
A= $here + $delta < 0B= $here + $delta > $self->max_tiles
ABresult
1X1
011
000
1153 647 ▶ return if $here % $self->row == 0 and $delta == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $here % $self->row == 0 and $delta == -1 0 647 647
Condition33%1/3
$here % $self->row == 0 and $delta == -1
!ll&&!rl&&r
64700
MC/DC0%0/2
$here % $self->row == 0 and $delta == -1
$here % $self->row == 0 $delta == -1
Truth table33%1/3
A and B
A= $here % $self->row == 0B= $delta == -1
ABresult
0X0
100
111
1154 647 ▶ return if $here % $self->row == $self->row and $delta == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $here % $self->row == $self->row and $delta == 1 0 647 647
Condition33%1/3
$here % $self->row == $self->row and $delta == 1
!ll&&!rl&&r
64700
MC/DC0%0/2
$here % $self->row == $self->row and $delta == 1
$here % $self->row == $self->row $delta == 1
Truth table33%1/3
A and B
A= $here % $self->row == $self->rowB= $delta == 1
ABresult
0X0
100
111
1155 647 return 1;
1156 }
1157  
1158 499 ▶sub something {
Subroutine something: called CC=3 SCAR=11.0
Pod undocumented
1159 499 my $self = shift;
1160 # Is there something at this legal position? Off the map means there is
1161 # nothing at the position.
1162 499 my $tiles = shift;
1163 499 my $here = shift;
1164 499 my $delta = shift;
1165 499 ▶ return if not $self->legal($here, $delta);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->legal($here, $delta) 0 499 499
1166 499 ▶ return @{$tiles->[$here + $delta]} if $tiles->[$here + $delta];
Branch: 1 branch
BranchTrueFalseTotal
if $$tiles[$here + $delta] 359 140 499
1167 }
1168  
1169 148 ▶sub empty {
Subroutine empty: called CC=2 SCAR=7.0
Pod undocumented
1170 148 my $self = shift;
1171 # Is this position legal and empty? We're looking for the "empty" tile!
1172 148 my $tiles = shift;
1173 148 my $here = shift;
1174 148 my $delta = shift;
1175 148 ▶ return if not $self->legal($here, $delta);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->legal($here, $delta) 0 148 148
1176 148 return grep { $_ eq "empty" } @{$tiles->[$here + $delta]};
1177 }
1178  
1179 0 ▶sub debug_neighbours {
Subroutine debug_neighbours: not called CC=14 SCAR=53.5
Pod undocumented
1180 0 my $self = shift;
1181 0 my $tiles = shift;
1182 0 my $here = shift;
1183 0 my @n;
1184 0 ▶ if ($here > $self->row and $tiles->[$here - $self->row] and @{$tiles->[$here - $self->row]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];}) 0 0 0
Condition0%0/6
$here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];}
!ll&&!rl&&r
000
$here > $self->row and $$tiles[$here - $self->row]
!ll&&!rl&&r
000
MC/DC0%0/3
$here > $self->row and $$tiles[$here - $self->row] and @{$$tiles[$here - $self->row];}
$here > $self->row $$tiles[$here - $self->row] @{$$tiles[$here - $self->row];}
Truth table0%0/4
A and B and C
A= $here > $self->rowB= $$tiles[$here - $self->row]C= @{$$tiles[$here - $self->row];}
ABCresult
0XX0
10X0
1100
1111
1185 0 push(@n, "n: @{$tiles->[$here - $self->row]}");
1186 }
1187 0 ▶ if ($here + $self->row <= $self->max_tiles and $tiles->[$here + $self->row] and @{$tiles->[$here + $self->row]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here + $self->row <= $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];}) 0 0 0
Condition0%0/6
$here + $self->row <= $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];}
!ll&&!rl&&r
000
$here + $self->row <= $self->max_tiles and $$tiles[$here + $self->row]
!ll&&!rl&&r
000
MC/DC0%0/3
$here + $self->row <= $self->max_tiles and $$tiles[$here + $self->row] and @{$$tiles[$here + $self->row];}
$here + $self->row <= $self->max_tiles $$tiles[$here + $self->row] @{$$tiles[$here + $self->row];}
Truth table0%0/4
A and B and C
A= $here + $self->row <= $self->max_tilesB= $$tiles[$here + $self->row]C= @{$$tiles[$here + $self->row];}
ABCresult
0XX0
10X0
1100
1111
1188 0 push(@n, "s: @{$tiles->[$here + $self->row]}");
1189 }
1190 0 ▶ if ($here > 0 and $tiles->[$here - 1] and @{$tiles->[$here - 1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];}) 0 0 0
Condition0%0/6
$here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];}
!ll&&!rl&&r
000
$here > 0 and $$tiles[$here - 1]
!ll&&!rl&&r
000
MC/DC0%0/3
$here > 0 and $$tiles[$here - 1] and @{$$tiles[$here - 1];}
$here > 0 $$tiles[$here - 1] @{$$tiles[$here - 1];}
Truth table0%0/4
A and B and C
A= $here > 0B= $$tiles[$here - 1]C= @{$$tiles[$here - 1];}
ABCresult
0XX0
10X0
1100
1111
1191 0 push(@n, "w: @{$tiles->[$here - 1]}");
1192 }
1193 0 ▶ if ($here < $self->max_tiles and $tiles->[$here + 1] and @{$tiles->[$here + 1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}) 0 0 0
Condition0%0/6
$here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
!ll&&!rl&&r
000
$here < $self->max_tiles and $$tiles[$here + 1]
!ll&&!rl&&r
000
MC/DC0%0/3
$here < $self->max_tiles and $$tiles[$here + 1] and @{$$tiles[$here + 1];}
$here < $self->max_tiles $$tiles[$here + 1] @{$$tiles[$here + 1];}
Truth table0%0/4
A and B and C
A= $here < $self->max_tilesB= $$tiles[$here + 1]C= @{$$tiles[$here + 1];}
ABCresult
0XX0
10X0
1100
1111
1194 0 push(@n, "e: @{$tiles->[$here + 1]}");
1195 }
1196 0 $log->debug("Neighbours of $here: @n");
1197 0 for (-$self->row-1, -$self->row, -$self->row+1, -1, +1, $self->row-1, $self->row, $self->row+1) {
1198 0 eval { $log->debug("Neighbours of $here+$_: @{$tiles->[$here + $_]}") };
1199 }
1200 }
1201  
1202 1 ▶sub to_text {
Subroutine to_text: called CC=4 SCAR=13.9
Pod undocumented
1203 1 my $self = shift;
1204 # Don't forget the border of two tiles.
1205 1 my $tiles = shift;
1206 1 my $text = "include gridmapper.txt\n";
1207 1 for my $x (0 .. $self->row - 1) {
1208 19 for my $y (0 .. $self->col - 1) {
1209 361 my $tile = $tiles->[$x + $y * $self->row];
1210 361 ▶ if ($tile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tile) 316 45 361
1211 316 $text .= sprintf("%02d%02d @$tile\n", $x + 1, $y + 1);
1212 }
1213 }
1214 }
1215 # The following is matched in /gridmapper/random!
1216 1 my $url = $self->to_gridmapper_link($tiles);
1217 1 $text .= qq{other <text x="-20em" y="0" font-size="40pt" transform="rotate(-90)" style="stroke:blue">}
1218 . qq{<a xlink:href="$url">Edit in Gridmapper</a></text>\n};
1219 1 $text .= "# Gridmapper link: $url\n";
1220 1 return $text;
1221 }
1222  
1223 1 ▶sub to_gridmapper_link {
Subroutine to_gridmapper_link: called CC=63 SCAR=69.1
Pod undocumented
1224 1 my $self = shift;
1225 1 my $tiles = shift;
1226 1 my $code;
1227 1 my $pen = 'up';
1228 1 for my $y (0 .. $self->col - 1) {
1229 19 for my $x (0 .. $self->row - 1) {
1230 361 my $tile = $tiles->[$x + $y * $self->row];
1231 361 ▶ if (not $tile or @$tile == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tile or @$tile == 0) 307 54 361
Condition100%3/3
not $tile or @$tile == 0
l!l&&r!l&&!r
4526254
MC/DC100%2/2
not $tile or @$tile == 0
not $tile @$tile == 0
Truth table100%3/3
not(A) or B
A= not $tileB= @$tile == 0
ABresult
1X1
011
000
1232 307 my $next = $tiles->[$x + $y * $self->row + 1];
1233 307 ▶ if ($pen eq 'down' and $next and @$next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pen eq 'down' and $next and @$next) { } 0 307 307
Condition66%4/6
$pen eq "down" and $next and @$next
!ll&&!rl&&r
289180
$pen eq "down" and $next
!ll&&!rl&&r
289018
MC/DC0%0/3
$pen eq "down" and $next and @$next
$pen eq "down" $next @$next
Truth table50%2/4
A and B and C
A= $pen eq "down"B= $nextC= @$next
ABCresult
0XX0
10X0
1100
1111
1234 0 $code .= ' ';
1235 } else {
1236 307 $pen = 'up';
1237 }
1238 307 next;
1239 }
1240 54 ▶ if ($pen eq 'up') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pen eq "up") 18 36 54
1241 18 $code .= "($x,$y)";
1242 18 $pen = 'down';
1243 }
1244 54 my $finally = " ";
1245 # $log->debug("[$x,$y] @$tile");
1246 54 for (@$tile) {
1247 63 ▶ if ($_ eq "empty") { $finally = "f" }
Branch: 53 branches
BranchTrueFalseTotal
if ($_ eq 'empty') { } 53 10 63
elsif ($_ eq 'pillar') { } 0 10 10
elsif (/^"(\d+)"$/u) { } 5 5 10
elsif ($_ eq 'arc-se') { } 0 5 5
elsif ($_ eq 'arc-sw') { } 0 5 5
elsif ($_ eq 'arc-nw') { } 0 5 5
elsif ($_ eq 'arc-ne') { } 0 5 5
elsif ($_ eq 'diagonal-se') { } 0 5 5
elsif ($_ eq 'diagonal-sw') { } 0 5 5
elsif ($_ eq 'diagonal-nw') { } 0 5 5
elsif ($_ eq 'diagonal-ne') { } 0 5 5
elsif ($_ eq 'door-w') { } 1 4 5
elsif ($_ eq 'door-n') { } 1 3 4
elsif ($_ eq 'door-e') { } 0 3 3
elsif ($_ eq 'door-s') { } 0 3 3
elsif ($_ eq 'secret-w') { } 0 3 3
elsif ($_ eq 'secret-n') { } 1 2 3
elsif ($_ eq 'secret-e') { } 0 2 2
elsif ($_ eq 'secret-s') { } 0 2 2
elsif ($_ eq 'concealed-w') { } 1 1 2
elsif ($_ eq 'concealed-n') { } 0 1 1
elsif ($_ eq 'concealed-e') { } 0 1 1
elsif ($_ eq 'concealed-s') { } 0 1 1
elsif ($_ eq 'archway-w') { } 0 1 1
elsif ($_ eq 'archway-n') { } 0 1 1
elsif ($_ eq 'archway-e') { } 0 1 1
elsif ($_ eq 'archway-s') { } 0 1 1
elsif ($_ eq 'stair-s') { } 1 0 1
elsif ($_ eq 'stair-w') { } 0 0 0
elsif ($_ eq 'stair-n') { } 0 0 0
elsif ($_ eq 'stair-e') { } 0 0 0
elsif ($_ eq 'stair-spiral') { } 0 0 0
elsif ($_ eq 'rock') { } 0 0 0
elsif ($_ eq 'rock-n') { } 0 0 0
elsif ($_ eq 'rock-ne') { } 0 0 0
elsif ($_ eq 'rock-ne-alternative') { } 0 0 0
elsif ($_ eq 'rock-e') { } 0 0 0
elsif ($_ eq 'rock-se') { } 0 0 0
elsif ($_ eq 'rock-se-alternative') { } 0 0 0
elsif ($_ eq 'rock-s') { } 0 0 0
elsif ($_ eq 'rock-sw') { } 0 0 0
elsif ($_ eq 'rock-sw-alternative') { } 0 0 0
elsif ($_ eq 'rock-w') { } 0 0 0
elsif ($_ eq 'rock-nw') { } 0 0 0
elsif ($_ eq 'rock-nw-alternative') { } 0 0 0
elsif ($_ eq 'rock-dead-end-n') { } 0 0 0
elsif ($_ eq 'rock-dead-end-e') { } 0 0 0
elsif ($_ eq 'rock-dead-end-s') { } 0 0 0
elsif ($_ eq 'rock-dead-end-w') { } 0 0 0
elsif ($_ eq 'rock-corridor-n') { } 0 0 0
elsif ($_ eq 'rock-corridor-s') { } 0 0 0
elsif ($_ eq 'rock-corridor-e') { } 0 0 0
elsif ($_ eq 'rock-corridor-w') { } 0 0 0
1248 0 elsif ($_ eq "pillar") { $code .= "p" }
1249 5 elsif (/^"(\d+)"$/) { $code .= $1 }
1250 0 elsif ($_ eq "arc-se") { $code .= "a" }
1251 0 elsif ($_ eq "arc-sw") { $code .= "aa" }
1252 0 elsif ($_ eq "arc-nw") { $code .= "aaa" }
1253 0 elsif ($_ eq "arc-ne") { $code .= "aaaa" }
1254 0 elsif ($_ eq "diagonal-se") { $code .= "n" }
1255 0 elsif ($_ eq "diagonal-sw") { $code .= "nn" }
1256 0 elsif ($_ eq "diagonal-nw") { $code .= "nnn" }
1257 0 elsif ($_ eq "diagonal-ne") { $code .= "nnnn" }
1258 1 elsif ($_ eq "door-w") { $code .= "d" }
1259 1 elsif ($_ eq "door-n") { $code .= "dd" }
1260 0 elsif ($_ eq "door-e") { $code .= "ddd" }
1261 0 elsif ($_ eq "door-s") { $code .= "dddd" }
1262 0 elsif ($_ eq "secret-w") { $code .= "dv" }
1263 1 elsif ($_ eq "secret-n") { $code .= "ddv" }
1264 0 elsif ($_ eq "secret-e") { $code .= "dddv" }
1265 0 elsif ($_ eq "secret-s") { $code .= "ddddv" }
1266 1 elsif ($_ eq "concealed-w") { $code .= "dvv" }
1267 0 elsif ($_ eq "concealed-n") { $code .= "ddvv" }
1268 0 elsif ($_ eq "concealed-e") { $code .= "dddvv" }
1269 0 elsif ($_ eq "concealed-s") { $code .= "ddddvv" }
1270 0 elsif ($_ eq "archway-w") { $code .= "dvvvv" }
1271 0 elsif ($_ eq "archway-n") { $code .= "ddvvvv" }
1272 0 elsif ($_ eq "archway-e") { $code .= "dddvvvv" }
1273 0 elsif ($_ eq "archway-s") { $code .= "ddddvvvv" }
1274 1 elsif ($_ eq "stair-s") { $code .= "s" }
1275 0 elsif ($_ eq "stair-w") { $code .= "ss" }
1276 0 elsif ($_ eq "stair-n") { $code .= "sss" }
1277 0 elsif ($_ eq "stair-e") { $code .= "ssss" }
1278 0 elsif ($_ eq "stair-spiral") { $code .= "svv" }
1279 0 elsif ($_ eq "rock") { $finally = "g" }
1280 0 elsif ($_ eq "rock-n") { $finally = "g" }
1281 0 elsif ($_ eq "rock-ne") { $finally = "g" }
1282 0 elsif ($_ eq "rock-ne-alternative") { $finally = "g" }
1283 0 elsif ($_ eq "rock-e") { $finally = "g" }
1284 0 elsif ($_ eq "rock-se") { $finally = "g" }
1285 0 elsif ($_ eq "rock-se-alternative") { $finally = "g" }
1286 0 elsif ($_ eq "rock-s") { $finally = "g" }
1287 0 elsif ($_ eq "rock-sw") { $finally = "g" }
1288 0 elsif ($_ eq "rock-sw-alternative") { $finally = "g" }
1289 0 elsif ($_ eq "rock-w") { $finally = "g" }
1290 0 elsif ($_ eq "rock-nw") { $finally = "g" }
1291 0 elsif ($_ eq "rock-nw-alternative") { $finally = "g" }
1292 0 elsif ($_ eq "rock-dead-end-n") { $finally = "g" }
1293 0 elsif ($_ eq "rock-dead-end-e") { $finally = "g" }
1294 0 elsif ($_ eq "rock-dead-end-s") { $finally = "g" }
1295 0 elsif ($_ eq "rock-dead-end-w") { $finally = "g" }
1296 0 elsif ($_ eq "rock-corridor-n") { $finally = "g" }
1297 0 elsif ($_ eq "rock-corridor-s") { $finally = "g" }
1298 0 elsif ($_ eq "rock-corridor-e") { $finally = "g" }
1299 0 elsif ($_ eq "rock-corridor-w") { $finally = "g" }
1300 else {
1301 0 $log->warn("Tile $_ not known for Gridmapper link");
1302 }
1303 }
1304 54 $code .= $finally;
1305 }
1306 19 $pen = 'up';
1307 }
1308 1 $log->debug("Gridmapper: $code");
1309 1 my $url = 'https://campaignwiki.org/gridmapper?' . url_escape($code);
1310 1 return $url;
1311 }
1312  
1313 =head1 SEE ALSO
1314  
1315 L<Gridmapper|https://alexschroeder.ch/cgit/gridmapper/about/> is a web
1316 application that lets you draw dungeons with strong focus on using the keyboard.
1317  
1318 =cut
1319  
1320 11 1;
« blib/lib/Game/TextMapper.pm ↑ Summary blib/lib/Game/TextMapper/Solo.pm »