blib/lib/Game/TextMapper/Traveller.pm

filter: Statementstmt 100% 245 / 245 Branchbran 92.5% 137 / 148 Conditioncond 91.8% 157 / 171 MC/DCmcdc 62.6% 52 / 83 Subroutinesub 100% 26 / 26 Podpod 6.6% 1 / 15 totaltotal 89.8% 618 / 688 CC 139 SCAR 39.8
CC
139
Cov
96%
system
89.2
comms
23.4
minimal_spanning_tree
16.2
CRAP 53.8
« blib/lib/auto/share/dist/Game-TextMapper/extract-svg.pl ↑ Summary blib/lib/Game/TextMapper/Mapper.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::Traveller - generate Traveller subsector maps
21  
22 =head1 DESCRIPTION
23  
24 This generates subsector maps suitable for the Traveller game in its various
25 editions. Trade and communication routes are based on starports, bases, and
26 trade codes and jump distance; the potential connections are then winnowed down
27 using a minimal spanning tree.
28  
29 =head1 METHODS
30  
31 =cut
32  
33 package Game::TextMapper::Traveller;
34 11 ▶use Game::TextMapper::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 11 ▶use Modern::Perl '2018';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 11 ▶use List::Util qw(shuffle max any);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 11 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 11 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 11 ▶use Game::TextMapper::Constants qw($dx $dy);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 11 with 'Game::TextMapper::Schroeder::Hex';
41  
42 11 my $log = Game::TextMapper::Log->get;
43  
44 11 has 'rows' => 10;
45 11 has 'cols' => 8;
46 11 has 'digraphs';
47  
48 =head2 generate_map
49  
50 This method takes no arguments. Subsectors are always 8×10.
51  
52 =cut
53  
54 sub generate_map {
55 2 ▶ my $self = shift;
Subroutine generate_map: called CC=2 SCAR=6.9
Pod documented
56 2 $self->digraphs($self->compute_digraphs);
57 # coordinates are an index into the system array
58 2 my @coordinates = (0 .. $self->rows * $self->cols - 1);
59 2 my @randomized = shuffle(@coordinates);
60 # %systems maps coordinates to arrays of tiles
61 2 my %systems = map { $_ => $self->system() } grep { roll1d6() > 3 } @randomized; # density
62 2 my $comms = $self->comms(\%systems);
63 2 ▶ my $tiles = [map { $systems{$_} || ["empty"] } (@coordinates)];
Branch: 1 branch
BranchTrueFalseTotal
$systems{$_} or ["empty"] 81 79 160
64 2 return $self->to_text($tiles, $comms);
65 }
66  
67 # Each system is an array of tiles, e.g. ["size-1", "population-3", ...]
68 sub system {
69 79 ▶ my $self = shift;
Subroutine system: called CC=89 SCAR=44.9
Pod undocumented
70 79 my $size = roll2d6() - 2;
71 79 my $atmosphere = max(0, roll2d6() - 7 + $size);
72 79 ▶ $atmosphere = 0 if $size == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 3 76 79
73 79 my $hydro = roll2d6() - 7 + $atmosphere;
74 79 ▶ $hydro -= 4 if $atmosphere < 2 or $atmosphere >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere < 2 or $atmosphere >= 10 17 62 79
Condition100%3/3
$atmosphere < 2 or $atmosphere >= 10
l!l&&r!l&&!r
13462
MC/DC100%2/2
$atmosphere < 2 or $atmosphere >= 10
$atmosphere < 2 $atmosphere >= 10
Truth table100%3/3
A or B
A= $atmosphere < 2B= $atmosphere >= 10
ABresult
1X1
011
000
75 79 ▶ $hydro = 0 if $hydro < 0 or $size < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro < 0 or $size < 2 16 63 79
Condition100%3/3
$hydro < 0 or $size < 2
l!l&&r!l&&!r
14263
MC/DC100%2/2
$hydro < 0 or $size < 2
$hydro < 0 $size < 2
Truth table100%3/3
A or B
A= $hydro < 0B= $size < 2
ABresult
1X1
011
000
76 79 ▶ $hydro = 10 if $hydro > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro > 10 3 76 79
77 79 my $population = roll2d6() - 2;
78 79 my $government = max(0, roll2d6() - 7 + $population);
79 79 my $law = max(0, roll2d6() - 7 + $government);
80 79 my $starport = roll2d6();
81 79 my $naval_base = 0;
82 79 my $scout_base = 0;
83 79 my $research_base = 0;
84 79 my $pirate_base = 0;
85 79 my $tech = roll1d6();
86 79 ▶ if ($starport <= 4) {
Branch: 5 branches
BranchTrueFalseTotal
if ($starport <= 4) { } 13 66 79
elsif ($starport <= 6) { } 19 47 66
elsif ($starport <= 8) { } 23 24 47
elsif ($starport <= 9) { } 9 15 24
elsif ($starport <= 11) { } 12 3 15
87 13 $starport = "A";
88 13 $tech += 6;
89 13 ▶ $scout_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 2 11 13
90 13 ▶ $naval_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 6 7 13
91 13 ▶ $research_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 6 7 13
92 } elsif ($starport <= 6) {
93 19 $starport = "B";
94 19 $tech += 4;
95 19 ▶ $scout_base = 1 if roll2d6() >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 9 6 13 19
96 19 ▶ $naval_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 5 14 19
97 19 ▶ $research_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 3 16 19
98 } elsif ($starport <= 8) {
99 23 $starport = "C";
100 23 $tech += 2;
101 23 ▶ $scout_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 11 12 23
102 23 ▶ $research_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 3 20 23
103 23 ▶ $pirate_base = 1 if roll2d6() >= 12;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 12 0 23 23
104 } elsif ($starport <= 9) {
105 9 $starport = "D";
106 9 ▶ $scout_base = 1 if roll2d6() >= 7;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 7 6 3 9
107 9 ▶ $pirate_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 1 8 9
108 } elsif ($starport <= 11) {
109 12 $starport = "E";
110 12 ▶ $pirate_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 1 11 12
111 } else {
112 3 $starport = "X";
113 3 $tech -= 4;
114 }
115 79 ▶ $tech += 1 if $size <= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 4 40 39 79
116 79 ▶ $tech += 1 if $size <= 1; # +2 total
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 1 8 71 79
117 79 ▶ $tech += 1 if $atmosphere <= 3 or $atmosphere >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere <= 3 or $atmosphere >= 10 29 50 79
Condition100%3/3
$atmosphere <= 3 or $atmosphere >= 10
l!l&&r!l&&!r
25450
MC/DC100%2/2
$atmosphere <= 3 or $atmosphere >= 10
$atmosphere <= 3 $atmosphere >= 10
Truth table100%3/3
A or B
A= $atmosphere <= 3B= $atmosphere >= 10
ABresult
1X1
011
000
118 79 ▶ $tech += 1 if $hydro >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 9 8 71 79
119 79 ▶ $tech += 1 if $hydro >= 10; # +2 total
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 10 5 74 79
120 79 ▶ $tech += 1 if $population >= 1 and $population <= 5;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 1 and $population <= 5 46 33 79
Condition100%3/3
$population >= 1 and $population <= 5
!ll&&!rl&&r
42946
MC/DC100%2/2
$population >= 1 and $population <= 5
$population >= 1 $population <= 5
Truth table100%3/3
A and B
A= $population >= 1B= $population <= 5
ABresult
0X0
100
111
121 79 ▶ $tech += 2 if $population >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 6 73 79
122 79 ▶ $tech += 2 if $population >= 10; # +4 total
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 10 2 77 79
123 79 ▶ $tech += 1 if $government == 0 or $government == 5;
Branch: 1 branch
BranchTrueFalseTotal
if $government == 0 or $government == 5 18 61 79
Condition100%3/3
$government == 0 or $government == 5
l!l&&r!l&&!r
81061
MC/DC100%2/2
$government == 0 or $government == 5
$government == 0 $government == 5
Truth table100%3/3
A or B
A= $government == 0B= $government == 5
ABresult
1X1
011
000
124 79 ▶ $tech -= 2 if $government == 13; # D
Branch: 1 branch
BranchTrueFalseTotal
if $government == 13 0 79 79
125 79 ▶ $tech = 0 if $tech < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $tech < 0 0 79 79
126 79 my $gas_giant = roll2d6() <= 9;
127 79 my $name = $self->compute_name();
128 79 ▶ $name = uc($name) if $population >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 6 73 79
129 79 my $uwp = join("", $starport, map { code($_) } $size, $atmosphere, $hydro, $population, $government, $law) . "-" . code($tech);
130 # these things determine the order in which text is generated by Hex Describe
131 79 my @tiles;
132 79 ▶ push(@tiles, "gas") if $gas_giant;
Branch: 1 branch
BranchTrueFalseTotal
if $gas_giant 70 9 79
133 79 push(@tiles, "size-" . code($size));
134 79 ▶ push(@tiles, "asteroid")
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 3 76 79
135 if $size == 0;
136 79 push(@tiles, "atmosphere-" . code($atmosphere));
137 79 ▶ push(@tiles, "vacuum")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere == 0 7 72 79
138 if $atmosphere == 0;
139 79 push(@tiles, "hydrosphere-" . code($hydro));
140 79 ▶ push(@tiles, "water")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro eq "A" 0 79 79
141 if $hydro eq "A";
142 79 ▶ push(@tiles, "desert")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere >= 2 and $hydro == 0 6 73 79
Condition100%3/3
$atmosphere >= 2 and $hydro == 0
!ll&&!rl&&r
13606
MC/DC100%2/2
$atmosphere >= 2 and $hydro == 0
$atmosphere >= 2 $hydro == 0
Truth table100%3/3
A and B
A= $atmosphere >= 2B= $hydro == 0
ABresult
0X0
100
111
143 if $atmosphere >= 2
144 and $hydro == 0;
145 79 ▶ push(@tiles, "ice")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 1 and $atmosphere <= 1 0 79 79
Condition66%2/3
$hydro >= 1 and $atmosphere <= 1
!ll&&!rl&&r
19600
MC/DC0%0/2
$hydro >= 1 and $atmosphere <= 1
$hydro >= 1 $atmosphere <= 1
Truth table66%2/3
A and B
A= $hydro >= 1B= $atmosphere <= 1
ABresult
0X0
100
111
146 if $hydro >= 1
147 and $atmosphere <= 1;
148 79 ▶ push(@tiles, "fluid")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 1 and $atmosphere >= 10 4 75 79
Condition100%3/3
$hydro >= 1 and $atmosphere >= 10
!ll&&!rl&&r
19564
MC/DC100%2/2
$hydro >= 1 and $atmosphere >= 10
$hydro >= 1 $atmosphere >= 10
Truth table100%3/3
A and B
A= $hydro >= 1B= $atmosphere >= 10
ABresult
0X0
100
111
149 if $hydro >= 1
150 and $atmosphere >= 10;
151 79 push(@tiles, "population-" . code($population));
152 79 ▶ push(@tiles, "barren")
Branch: 1 branch
BranchTrueFalseTotal
if $population eq 0 and $law eq 0 and $government eq 0 0 79 79
Condition83%5/6
$population eq 0 and $law eq 0 and $government eq 0
!ll&&!rl&&r
7810
$population eq 0 and $law eq 0
!ll&&!rl&&r
7531
MC/DC0%0/3
$population eq 0 and $law eq 0 and $government eq 0
$population eq 0 $law eq 0 $government eq 0
Truth table75%3/4
A and B and C
A= $population eq 0B= $law eq 0C= $government eq 0
ABCresult
0XX0
10X0
1100
1111
153 if $population eq 0
154 and $law eq 0
155 and $government eq 0;
156 79 ▶ push(@tiles, "low")
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 1 and $population <= 3 25 54 79
Condition100%3/3
$population >= 1 and $population <= 3
!ll&&!rl&&r
45025
MC/DC100%2/2
$population >= 1 and $population <= 3
$population >= 1 $population <= 3
Truth table100%3/3
A and B
A= $population >= 1B= $population <= 3
ABresult
0X0
100
111
157 if $population >= 1 and $population <= 3;
158 79 ▶ push(@tiles, "high")
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 6 73 79
159 if $population >= 9;
160 79 ▶ push(@tiles, "agriculture")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5 and $population <= 7 10 69 79
Condition100%15/15
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5 and $population <= 7
!ll&&!rl&&r
65410
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5
!ll&&!rl&&r
511414
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8
!ll&&!rl&&r
43828
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4
!ll&&!rl&&r
291436
$atmosphere >= 4 and $atmosphere <= 9
!ll&&!rl&&r
25450
MC/DC100%6/6
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5 and $population <= 7
$atmosphere >= 4 $atmosphere <= 9 $hydro >= 4 $hydro <= 8 $population >= 5 $population <= 7
Truth table100%7/7
A and B and C and D and E and F
A= $atmosphere >= 4B= $atmosphere <= 9C= $hydro >= 4D= $hydro <= 8E= $population >= 5F= $population <= 7
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
161 if $atmosphere >= 4 and $atmosphere <= 9
162 and $hydro >= 4 and $hydro <= 8
163 and $population >= 5 and $population <= 7;
164 79 ▶ push(@tiles, "non-agriculture")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere <= 3 and $hydro <= 3 and $population >= 6 9 70 79
Condition100%6/6
$atmosphere <= 3 and $hydro <= 3 and $population >= 6
!ll&&!rl&&r
59119
$atmosphere <= 3 and $hydro <= 3
!ll&&!rl&&r
54520
MC/DC100%3/3
$atmosphere <= 3 and $hydro <= 3 and $population >= 6
$atmosphere <= 3 $hydro <= 3 $population >= 6
Truth table100%4/4
A and B and C
A= $atmosphere <= 3B= $hydro <= 3C= $population >= 6
ABCresult
0XX0
10X0
1100
1111
165 if $atmosphere <= 3
166 and $hydro <= 3
167 and $population >= 6;
168 push(@tiles, "industrial")
169 79 ▶ if any { $atmosphere == $_ } 0, 1, 2, 4, 7, 9
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $atmosphere == $_; } , 0, 1, 2, 4, 7, 9) and $population >= 9 3 76 79
Condition100%3/3
&any(sub { $atmosphere == $_; } , 0, 1, 2, 4, 7, 9) and $population >= 9
!ll&&!rl&&r
36403
MC/DC100%2/2
&any(sub { $atmosphere == $_; } , 0, 1, 2, 4, 7, 9) and $population >= 9
&any(sub { $atmosphere == $_; } , 0, 1, 2, 4, 7, 9) $population >= 9
Truth table100%3/3
A and B
A= &any(sub { $atmosphere == $_; } , 0, 1, 2, 4, 7, 9)B= $population >= 9
ABresult
0X0
100
111
170 and $population >= 9;
171 79 ▶ push(@tiles, "non-industrial")
Branch: 1 branch
BranchTrueFalseTotal
if $population <= 6 62 17 79
172 if $population <= 6;
173 79 ▶ push(@tiles, "rich")
Branch: 1 branch
BranchTrueFalseTotal
if $government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6 and $population <= 8 3 76 79
Condition93%14/15
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6 and $population <= 8
!ll&&!rl&&r
7603
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6
!ll&&!rl&&r
7243
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8
!ll&&!rl&&r
33397
$government >= 4 and $government <= 9
!ll&&!rl&&r
221146
$atmosphere == 6 or $atmosphere == 8
l!l&&r!l&&!r
6139
MC/DC83%5/6
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6 and $population <= 8
$government >= 4 $government <= 9 $atmosphere == 6 $atmosphere == 8 $population >= 6 $population <= 8
Truth table66%6/9
A and B and C or D and E and F
A= $government >= 4B= $government <= 9C= $atmosphere == 6D= $atmosphere == 8E= $population >= 6F= $population <= 8
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X0X0
11010X0
111X100
1101100
111X111
1101111
174 if $government >= 4 and $government <= 9
175 and ($atmosphere == 6 or $atmosphere == 8)
176 and $population >= 6 and $population <= 8;
177 79 ▶ push(@tiles, "poor")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere >= 2 and $atmosphere <= 5 and $hydro <= 3 19 60 79
Condition100%6/6
$atmosphere >= 2 and $atmosphere <= 5 and $hydro <= 3
!ll&&!rl&&r
441619
$atmosphere >= 2 and $atmosphere <= 5
!ll&&!rl&&r
133135
MC/DC100%3/3
$atmosphere >= 2 and $atmosphere <= 5 and $hydro <= 3
$atmosphere >= 2 $atmosphere <= 5 $hydro <= 3
Truth table100%4/4
A and B and C
A= $atmosphere >= 2B= $atmosphere <= 5C= $hydro <= 3
ABCresult
0XX0
10X0
1100
1111
178 if $atmosphere >= 2 and $atmosphere <= 5
179 and $hydro <= 3;
180 79 push(@tiles, "tech-" . code($tech));
181 79 push(@tiles, "government-" . code($government));
182 79 push(@tiles, "starport-$starport");
183 79 push(@tiles, "law-" . code($law));
184 79 ▶ push(@tiles, "naval") if $naval_base;
Branch: 1 branch
BranchTrueFalseTotal
if $naval_base 11 68 79
185 79 ▶ push(@tiles, "scout") if $scout_base;
Branch: 1 branch
BranchTrueFalseTotal
if $scout_base 25 54 79
186 79 ▶ push(@tiles, "research") if $research_base;
Branch: 1 branch
BranchTrueFalseTotal
if $research_base 12 67 79
187 79 ▶ push(@tiles, "pirate", "red") if $pirate_base;
Branch: 1 branch
BranchTrueFalseTotal
if $pirate_base 2 77 79
188 79 ▶ push(@tiles, "amber")
Branch: 1 branch
BranchTrueFalseTotal
if not $pirate_base and $atmosphere >= 10 || $population && $government == 0 || $population && $law == 0 || $government == 7 || $government == 10 || $law >= 9 18 41 59
Condition100%24/24
not $pirate_base and $atmosphere >= 10 || $population && $government == 0 || $population && $law == 0 || $government == 7 || $government == 10 || $law >= 9
!ll&&!rl&&r
25720
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0 or $government == 7 or $government == 10 or $law >= 9
l!l&&r!l&&!r
251339
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0 or $government == 7 or $government == 10
l!l&&r!l&&!r
20552
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0 or $government == 7
l!l&&r!l&&!r
16457
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0
l!l&&r!l&&!r
8861
$atmosphere >= 10 or $population and $government == 0
l!l&&r!l&&!r
3569
$population and $government == 0
!ll&&!rl&&r
3665
$population and $law == 0
!ll&&!rl&&r
3588
MC/DC22%2/9
not $pirate_base and $atmosphere >= 10 || $population && $government == 0 || $population && $law == 0 || $government == 7 || $government == 10 || $law >= 9
not $pirate_base $atmosphere >= 10 $population $government == 0 $population $law == 0 $government == 7 $government == 10 $law >= 9
Truth table19%4/21
not(A) and B or C and D or E and F or G or H or I
A= not $pirate_baseB= $atmosphere >= 10C= $populationD= $government == 0E= $populationF= $law == 0G= $government == 7H= $government == 10I= $law >= 9
ABCDEFGHIresult
0XXXXXXXX0
100X0X0000
100X100000
10100X0000
1010100000
11XXXXXXX1
1011XXXXX1
100X11XXX1
101011XXX1
100X0X1XX1
100X101XX1
10100X1XX1
1010101XX1
100X0X01X1
100X1001X1
10100X01X1
10101001X1
100X0X0011
100X100011
10100X0011
1010100011
189 if not $pirate_base
190 and ($atmosphere >= 10
191 or $population and $government == 0
192 or $population and $law == 0
193 or $government == 7
194 or $government == 10
195 or $law >= 9);
196 # last is the name
197 79 push(@tiles, qq{name="$name"}, qq{uwp="$uwp"});
198 79 return \@tiles;
199 }
200  
201 sub code {
202 1106 ▶ my $code = shift;
Subroutine code: called CC=2 SCAR=6.9
Pod undocumented
203 1106 ▶ return $code if $code <= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $code <= 9 982 124 1106
204 124 return chr(55+$code); # 10 is A
205 }
206  
207 sub compute_digraphs {
208 2 ▶ my @first = qw(b c d f g h j k l m n p q r s t v w x y z
Subroutine compute_digraphs: called CC=2 SCAR=6.9
Pod undocumented
209 b c d f g h j k l m n p q r s t v w x y z .
210 sc ng ch gh ph rh sh th wh zh wr qu
211 st sp tr tw fl dr pr dr);
212 # make missing vowel rare
213 2 my @second = qw(a e i o u a e i o u a e i o u .);
214 2 my @d;
215 2 for (1 .. 10+rand(20)) {
216 39 push(@d, one(@first));
217 39 push(@d, one(@second));
218 }
219 2 return \@d;
220 }
221  
222 sub compute_name {
223 79 ▶ my $self = shift;
Subroutine compute_name: called CC=2 SCAR=6.9
Pod undocumented
224 79 my $max = scalar @{$self->digraphs};
225 79 my $length = 3 + rand(3); # length of name before adding one more
226 79 my $name = '';
227 79 ▶ while (length($name) < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $name < $length) 195 79 274
228 195 my $i = 2*int(rand($max/2));
229 195 $name .= $self->digraphs->[$i];
230 195 $name .= $self->digraphs->[$i+1];
231 }
232 79 $name =~ s/\.//g;
233 79 return ucfirst($name);
234 }
235  
236 sub one {
237 78 ▶ return $_[int(rand(scalar @_))];
Subroutine one: called CC=1 SCAR=0.0
Pod undocumented
238 }
239  
240 sub roll1d6 {
241 1893 ▶ return 1+int(rand(6));
Subroutine roll1d6: called CC=1 SCAR=0.0
Pod undocumented
242 }
243  
244 sub roll2d6 {
245 827 ▶ return roll1d6() + roll1d6();
Subroutine roll2d6: called CC=1 SCAR=0.0
Pod undocumented
246 }
247  
248 sub xy {
249 79 ▶ my $self = shift;
Subroutine xy: called CC=1 SCAR=0.0
Pod undocumented
250 79 my $i = shift;
251 79 my $y = int($i / $self->cols);
252 79 my $x = $i % $self->cols;
253 79 $log->debug("$i ($x, $y)");
254 79 return $x + 1, $y + 1;
255 }
256  
257 sub label {
258 91 ▶ my ($self, $from, $to, $d, $label) = @_;
Subroutine label: called CC=1 SCAR=0.0
Pod undocumented
259 91 return sprintf("%02d%02d-%02d%02d $label", @$from[0..1], @$to[0..1]);
260 }
261  
262 # Communication routes have distance 1–2 and connect navy bases and A-class
263 # starports.
264 sub comms {
265 2 ▶ my $self = shift;
Subroutine comms: called CC=23 SCAR=31.5
Pod undocumented
266 2 my %systems = %{shift()};
267 2 my @coordinates = map { [ $self->xy($_), $systems{$_} ] } keys(%systems);
268 2 my @comms;
269 my @trade;
270 2 my @rich_trade;
271 2 ▶ while (@coordinates) {
Branch: 1 branch
BranchTrueFalseTotal
if (@coordinates) 79 2 81
272 79 my $from = shift(@coordinates);
273 79 my ($x1, $y1, $system1) = @$from;
274 79 ▶ next if any { /^starport-X$/ } @$system1; # skip systems without starports
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /^starport-X$/u; } , @$system1) 3 76 79
275 76 for my $to (@coordinates) {
276 1448 my ($x2, $y2, $system2) = @$to;
277 1448 ▶ next if any { /^starport-X$/ } @$system2; # skip systems without starports
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /^starport-X$/u; } , @$system2) 33 1415 1448
278 1415 my $d = $self->distance($x1, $y1, $x2, $y2);
279 1415 ▶ if ($d <= 2 and match(qr/^(starport-[AB]|naval)$/, qr/^(starport-[AB]|naval)$/, $system1, $system2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d <= 2 and match(qr/^(starport-[AB]|naval)$/u, qr/^(starport-[AB]|naval)$/u, $system1, $system2)) 45 1370 1415
Condition100%3/3
$d <= 2 and match(qr/^(starport-[AB]|naval)$/u, qr/^(starport-[AB]|naval)$/u, $system1, $system2)
!ll&&!rl&&r
114922145
MC/DC100%2/2
$d <= 2 and match(qr/^(starport-[AB]|naval)$/u, qr/^(starport-[AB]|naval)$/u, $system1, $system2)
$d <= 2 match(qr/^(starport-[AB]|naval)$/u, qr/^(starport-[AB]|naval)$/u, $system1, $system2)
Truth table100%3/3
A and B
A= $d <= 2B= match(qr/^(starport-[AB]|naval)$/u, qr/^(starport-[AB]|naval)$/u, $system1, $system2)
ABresult
0X0
100
111
280 45 push(@comms, [$from, $to, $d]);
281 }
282 1415 ▶ if ($d <= 2
Branch: 1 branch
BranchTrueFalseTotal
if ($d <= 2 and match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) || match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) || match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) || match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) || match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) || match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) || match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) || match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) || match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) || match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2) || match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2) || match(qr/^vacuum$/u, qr/^(asteroid|industrial|vacuum)$/u, $system1, $system2) || match(qr/^water$/u, qr/^(industrial|rich|water)$/u, $system1, $system2)) 0 1333 1333
Condition82%32/39
$d <= 2 and match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) || match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) || match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) || match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) || match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) || match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) || match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) || match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) || match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) || match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2) || match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2) || match(qr/^vacuum$/u, qr/^(asteroid|industrial|vacuum)$/u, $system1, $system2) || match(qr/^water$/u, qr/^(industrial|rich|water)$/u, $system1, $system2)
!ll&&!rl&&r
11492660
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) or match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) or match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) or match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^vacuum$/u, qr/^(asteroid|industrial|vacuum)$/u, $system1, $system2) or match(qr/^water$/u, qr/^(industrial|rich|water)$/u, $system1, $system2)
l!l&&r!l&&!r
820184
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) or match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) or match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) or match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^vacuum$/u, qr/^(asteroid|industrial|vacuum)$/u, $system1, $system2)
l!l&&r!l&&!r
820184
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) or match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) or match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) or match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2)
l!l&&r!l&&!r
820184
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) or match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) or match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) or match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2)
l!l&&r!l&&!r
820184
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) or match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) or match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2)
l!l&&r!l&&!r
802184
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) or match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2)
l!l&&r!l&&!r
782186
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) or match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2)
l!l&&r!l&&!r
753188
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) or match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2)
l!l&&r!l&&!r
750191
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) or match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2)
l!l&&r!l&&!r
6114191
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) or match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2)
l!l&&r!l&&!r
610205
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) or match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2)
l!l&&r!l&&!r
538205
match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) or match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2)
l!l&&r!l&&!r
485213
MC/DC0%0/14
$d <= 2 and match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) || match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) || match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) || match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) || match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) || match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) || match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) || match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) || match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) || match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2) || match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2) || match(qr/^vacuum$/u, qr/^(asteroid|industrial|vacuum)$/u, $system1, $system2) || match(qr/^water$/u, qr/^(industrial|rich|water)$/u, $system1, $system2)
$d <= 2 match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2) match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2) match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2) match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2) match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2) match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2) match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2) match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2) match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2) match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2) match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2) match(qr/^vacuum$/u, qr/^(asteroid|industrial|vacuum)$/u, $system1, $system2) match(qr/^water$/u, qr/^(industrial|rich|water)$/u, $system1, $system2)
Truth table13%2/15
A and B or C or D or E or F or G or H or I or J or K or L or M or N
A= $d <= 2B= match(qr/^agriculture$/u, qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/u, $system1, $system2)C= match(qr/^asteroid$/u, qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/u, $system1, $system2)D= match(qr/^desert$/u, qr/^(desert|non-agriculture)$/u, $system1, $system2)E= match(qr/^fluid$/u, qr/^(fluid|industrial)$/u, $system1, $system2)F= match(qr/^high$/u, qr/^(high|low|rich)$/u, $system1, $system2)G= match(qr/^ice$/u, qr/^industrial$/u, $system1, $system2)H= match(qr/^industrial$/u, qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/u, $system1, $system2)I= match(qr/^low$/u, qr/^(industrial|rich)$/u, $system1, $system2)J= match(qr/^non-agriculture$/u, qr/^(asteroid|desert|vacuum)$/u, $system1, $system2)K= match(qr/^non-industrial$/u, qr/^industrial$/u, $system1, $system2)L= match(qr/^rich$/u, qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/u, $system1, $system2)M= match(qr/^vacuum$/u, qr/^(asteroid|industrial|vacuum)$/u, $system1, $system2)N= match(qr/^water$/u, qr/^(industrial|rich|water)$/u, $system1, $system2)
ABCDEFGHIJKLMNresult
0XXXXXXXXXXXXX0
100000000000000
11XXXXXXXXXXXX1
101XXXXXXXXXXX1
1001XXXXXXXXXX1
10001XXXXXXXXX1
100001XXXXXXXX1
1000001XXXXXXX1
10000001XXXXXX1
100000001XXXXX1
1000000001XXXX1
10000000001XXX1
100000000001XX1
1000000000001X1
100000000000011
283 # many of these can be eliminated, but who knows, perhaps one day
284 # directionality will make a difference
285 and (match(qr/^agriculture$/,
286 qr/^(agriculture|astroid|desert|high|industrial|low|non-agriculture|rich)$/,
287 $system1, $system2)
288 or match(qr/^asteroid$/,
289 qr/^(asteroid|industrial|non-agriculture|rich|vacuum)$/,
290 $system1, $system2)
291 or match(qr/^desert$/,
292 qr/^(desert|non-agriculture)$/,
293 $system1, $system2)
294 or match(qr/^fluid$/,
295 qr/^(fluid|industrial)$/,
296 $system1, $system2)
297 or match(qr/^high$/,
298 qr/^(high|low|rich)$/,
299 $system1, $system2)
300 or match(qr/^ice$/,
301 qr/^industrial$/,
302 $system1, $system2)
303 or match(qr/^industrial$/,
304 qr/^(agriculture|astroid|desert|fluid|high|industrial|non-industrial|poor|rich|vacuum|water)$/,
305 $system1, $system2)
306 or match(qr/^low$/,
307 qr/^(industrial|rich)$/,
308 $system1, $system2)
309 or match(qr/^non-agriculture$/,
310 qr/^(asteroid|desert|vacuum)$/,
311 $system1, $system2)
312 or match(qr/^non-industrial$/,
313 qr/^industrial$/,
314 $system1, $system2)
315 or match(qr/^rich$/,
316 qr/^(agriculture|desert|high|industrial|non-agriculture|rich)$/,
317 $system1, $system2)
318 or match(qr/^vacuum$/,
319 qr/^(asteroid|industrial|vacuum)$/,
320 $system1, $system2)
321 or match(qr/^water$/,
322 qr/^(industrial|rich|water)$/,
323 $system1, $system2))) {
324 82 push(@trade, [$from, $to, $d]);
325 }
326 1415 ▶ if ($d <= 3
Branch: 1 branch
BranchTrueFalseTotal
if ($d <= 3 and match(qr/^rich$/u, qr/^(asteroid|agriculture|desert|high|industrial|non-agriculture|water|rich|low)$/u, $system1, $system2)) 22 1393 1415
Condition100%3/3
$d <= 3 and match(qr/^rich$/u, qr/^(asteroid|agriculture|desert|high|industrial|non-agriculture|water|rich|low)$/u, $system1, $system2)
!ll&&!rl&&r
93046322
MC/DC100%2/2
$d <= 3 and match(qr/^rich$/u, qr/^(asteroid|agriculture|desert|high|industrial|non-agriculture|water|rich|low)$/u, $system1, $system2)
$d <= 3 match(qr/^rich$/u, qr/^(asteroid|agriculture|desert|high|industrial|non-agriculture|water|rich|low)$/u, $system1, $system2)
Truth table100%3/3
A and B
A= $d <= 3B= match(qr/^rich$/u, qr/^(asteroid|agriculture|desert|high|industrial|non-agriculture|water|rich|low)$/u, $system1, $system2)
ABresult
0X0
100
111
327 # subsidized liners only
328 and match(qr/^rich$/,
329 qr/^(asteroid|agriculture|desert|high|industrial|non-agriculture|water|rich|low)$/,
330 $system1, $system2)) {
331 22 push(@rich_trade, [$from, $to, $d]);
332 }
333 }
334 }
335 2 @comms = sort map { $self->label(@$_, "communication") } @{$self->minimal_spanning_tree(@comms)};
336 2 @trade = sort map { $self->label(@$_, "trade") } @{$self->minimal_spanning_tree(@trade)};
337 2 @rich_trade = sort map { $self->label(@$_, "rich") } @{$self->minimal_spanning_tree(@rich_trade)};
338 2 return [@rich_trade, @comms, @trade];
339 }
340  
341 sub match {
342 3350 ▶ my ($re1, $re2, $sys1, $sys2) = @_;
Subroutine match: called CC=5 SCAR=16.1
Pod undocumented
343 3350 ▶ return 1 if any { /$re1/ } @$sys1 and any { /$re2/ } @$sys2;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /$re1/u; } , @$sys1) and &any(sub { /$re2/u; } , @$sys2) 109 3241 3350
Condition100%3/3
&any(sub { /$re1/u; } , @$sys1) and &any(sub { /$re2/u; } , @$sys2)
!ll&&!rl&&r
2842399109
MC/DC100%2/2
&any(sub { /$re1/u; } , @$sys1) and &any(sub { /$re2/u; } , @$sys2)
&any(sub { /$re1/u; } , @$sys1) &any(sub { /$re2/u; } , @$sys2)
Truth table100%3/3
A and B
A= &any(sub { /$re1/u; } , @$sys1)B= &any(sub { /$re2/u; } , @$sys2)
ABresult
0X0
100
111
344 3241 ▶ return 1 if any { /$re2/ } @$sys1 and any { /$re1/ } @$sys2;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /$re2/u; } , @$sys1) and &any(sub { /$re1/u; } , @$sys2) 40 3201 3241
Condition100%3/3
&any(sub { /$re2/u; } , @$sys1) and &any(sub { /$re1/u; } , @$sys2)
!ll&&!rl&&r
222098140
MC/DC100%2/2
&any(sub { /$re2/u; } , @$sys1) and &any(sub { /$re1/u; } , @$sys2)
&any(sub { /$re2/u; } , @$sys1) &any(sub { /$re1/u; } , @$sys2)
Truth table100%3/3
A and B
A= &any(sub { /$re2/u; } , @$sys1)B= &any(sub { /$re1/u; } , @$sys2)
ABresult
0X0
100
111
345 3201 return 0;
346 }
347  
348 sub minimal_spanning_tree {
349 # http://en.wikipedia.org/wiki/Kruskal%27s_algorithm
350 6 ▶ my $self = shift;
Subroutine minimal_spanning_tree: called CC=16 SCAR=27.9
Pod undocumented
351 # Initialize a priority queue Q to contain all edges in G, using the
352 # weights as keys.
353 6 my @Q = sort { @{$a}[2] <=> @{$b}[2] } @_;
354 # Define a forest T ← Ø; T will ultimately contain the edges of the MST
355 6 my @T;
356 # Define an elementary cluster C(v) ← {v}.
357 my %C;
358 6 my $id;
359 6 foreach my $edge (@Q) {
360 # edge u,v is the minimum weighted route from u to v
361 149 my ($u, $v) = @{$edge};
362 # prevent cycles in T; add u,v only if T does not already contain
363 # a path between u and v; also silence warnings
364 149 ▶ if (not $C{$u} or not $C{$v} or $C{$u} != $C{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $C{$u} && $C{$v} or $C{$u} != $C{$v}) 91 58 149
Condition100%6/6
not $C{$u} && $C{$v} or $C{$u} != $C{$v}
l!l&&r!l&&!r
801158
$C{$u} && $C{$v}
!ll&&!rl&&r
384269
MC/DC100%3/3
not $C{$u} && $C{$v} or $C{$u} != $C{$v}
$C{$u} $C{$v} $C{$u} != $C{$v}
Truth table100%4/4
not(A && B) or C
A= $C{$u}B= $C{$v}C= $C{$u} != $C{$v}
ABCresult
0XX1
10X1
1111
1100
365 # Add edge (v,u) to T.
366 91 push(@T, $edge);
367 # Merge C(v) and C(u) into one cluster, that is, union C(v) and C(u).
368 91 ▶ if ($C{$u} and $C{$v}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($C{$u} and $C{$v}) { } 11 80 91
elsif ($C{$v} and not $C{$u}) { } 16 64 80
elsif ($C{$u} and not $C{$v}) { } 42 22 64
elsif (not $C{$u} || $C{$v}) { } 22 0 22
Condition100%3/3
$C{$u} and $C{$v}
!ll&&!rl&&r
384211
MC/DC100%2/2
$C{$u} and $C{$v}
$C{$u} $C{$v}
Truth table100%3/3
A and B
A= $C{$u}B= $C{$v}
ABresult
0X0
100
111
369 11 my @group;
370 11 foreach (keys %C) {
371 202 ▶ push(@group, $_) if $C{$_} == $C{$v};
Branch: 1 branch
BranchTrueFalseTotal
if $C{$_} == $C{$v} 68 134 202
372 }
373 11 $C{$_} = $C{$u} foreach @group;
374 ▶ } elsif ($C{$v} and not $C{$u}) {
Condition66%2/3
$C{$v} and not $C{$u}
!ll&&!rl&&r
64016
MC/DC50%1/2
$C{$v} and not $C{$u}
$C{$v} not $C{$u}
Truth table66%2/3
A and not(B)
A= $C{$v}B= not $C{$u}
ABresult
0X0
100
111
375 16 $C{$u} = $C{$v};
376 ▶ } elsif ($C{$u} and not $C{$v}) {
Condition66%2/3
$C{$u} and not $C{$v}
!ll&&!rl&&r
22042
MC/DC50%1/2
$C{$u} and not $C{$v}
$C{$u} not $C{$v}
Truth table66%2/3
A and not(B)
A= $C{$u}B= not $C{$v}
ABresult
0X0
100
111
377 42 $C{$v} = $C{$u};
378 ▶ } elsif (not $C{$u} and not $C{$v}) {
Condition33%1/3
$C{$u} || $C{$v}
l!l&&r!l&&!r
0022
MC/DC0%0/2
$C{$u} || $C{$v}
$C{$u} $C{$v}
Truth table33%1/3
A || B
A= $C{$u}B= $C{$v}
ABresult
1X1
011
000
379 22 $C{$v} = $C{$u} = ++$id;
380 }
381 }
382 }
383 6 return \@T;
384 }
385  
386 sub to_text {
387 2 ▶ my $self = shift;
Subroutine to_text: called CC=4 SCAR=13.9
Pod undocumented
388 2 my $tiles = shift;
389 2 my $comms = shift;
390 2 my $text = "";
391 2 for my $x (0 .. $self->cols - 1) {
392 16 for my $y (0 .. $self->rows - 1) {
393 160 my $tile = $tiles->[$x + $y * $self->cols];
394 160 ▶ if ($tile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tile) 160 0 160
395 160 $text .= sprintf("%02d%02d @$tile\n", $x + 1, $y + 1);
396 }
397 }
398 }
399 2 $text .= join("\n", @$comms, "\ninclude traveller.txt\n");
400 2 $text .= $self->legend();
401 2 return $text;
402 }
403  
404 sub legend {
405 2 ▶ my $self = shift;
Subroutine legend: called CC=3 SCAR=11.0
Pod undocumented
406 2 my $template = qq{# frame and legend};
407 2 my $x = int(($self->cols + 1) * 1.5 * $dx);
408 2 my $y = int(($self->rows + 1) * $dy + 5);
409 2 $template .= qq{
410 other <rect fill="none" stroke="black" stroke-width="10" x="0" y="-50" width="$x" height="$y" />},
411 $x = int(($self->cols + 1) * 0.75 * $dx);
412 2 $y = int(($self->rows + 1) * $dy - 60);
413 2 $template .= qq{
414 other <text font-size="24pt" y="-10" x="$x" font-family="Optima, Helvetica, sans-serif" text-anchor="middle">coreward</text>
415 other <text font-size="24pt" y="$y" x="$x" font-family="Optima, Helvetica, sans-serif" text-anchor="middle">rimward</text>};
416 2 $x = int($self->rows * $dy / 2);
417 2 $template .= qq{
418 other <text font-size="24pt" x="-$x" y="40" transform="rotate(-90)" font-family="Optima, Helvetica, sans-serif" text-anchor="middle">spinward</text>
419 };
420 2 $y = int(($self->cols + 1) * 1.5 * $dx);
421 2 $template .= qq{
422 other <text font-size="24pt" x="$x" y="40" transform="rotate(90) translate(0, -$y)" font-family="Optima, Helvetica, sans-serif" text-anchor="middle">trailing</text>
423 };
424 2 $x = int(($self->rows + 0.5) * $dy);
425 2 ▶ $template .= qq{
Branch: 1 branch
BranchTrueFalseTotal
if $self->rows > 8 2 0 2
426 other <text font-size="14pt" x="-$x" y="30" transform="rotate(-90)" font-family="Optima, Helvetica, sans-serif">◉ gas giant – ▲ scout base – ★ navy base – π research base – ☠ pirate base</text>
427 } if $self->rows > 8;
428 2 ▶ $template .= qq{
Branch: 1 branch
BranchTrueFalseTotal
if $self->rows > 8 2 0 2
429 other <text font-size="14pt" x="-650" y="30" transform="rotate(-90)" font-family="Optima, Helvetica, sans-serif">■ imperial consulate – ☼ TAS – <tspan fill="#ff6347">▮</tspan> communication – <tspan fill="#afeeee">▮</tspan> trade <tspan fill="#ffd700">▮</tspan> long distance trade</text>
430 } if $self->rows > 8;
431 2 return $template;
432 }
433  
434 11 1;
« blib/lib/auto/share/dist/Game-TextMapper/extract-svg.pl ↑ Summary blib/lib/Game/TextMapper/Mapper.pm »