blib/lib/Game/TextMapper/Traveller.pm

filter: Statementstmt 100% 245 / 245 Branchbran 93.9% 139 / 148 Conditioncond 92.4% 158 / 171 MC/DCmcdc 62.6% 52 / 83 Subroutinesub 100% 26 / 26 Podpod 6.6% 1 / 15 totaltotal 90.2% 621 / 688 CC 139 SCAR 39.8
CC
139
Cov
96%
system
89.2
comms
23.2
minimal_spanning_tree
16.2
CRAP 53.7
« blib/lib/auto/share/dist/Game-TextMapper/extract-svg.pl ↑ Summary blib/lib/Game/TextMapper/Command/random.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"] 72 88 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 88 ▶ my $self = shift;
Subroutine system: called CC=89 SCAR=44.9
Pod undocumented
70 88 my $size = roll2d6() - 2;
71 88 my $atmosphere = max(0, roll2d6() - 7 + $size);
72 88 ▶ $atmosphere = 0 if $size == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 3 85 88
73 88 my $hydro = roll2d6() - 7 + $atmosphere;
74 88 ▶ $hydro -= 4 if $atmosphere < 2 or $atmosphere >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere < 2 or $atmosphere >= 10 27 61 88
Condition100%3/3
$atmosphere < 2 or $atmosphere >= 10
l!l&&r!l&&!r
20761
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 88 ▶ $hydro = 0 if $hydro < 0 or $size < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro < 0 or $size < 2 23 65 88
Condition100%3/3
$hydro < 0 or $size < 2
l!l&&r!l&&!r
22165
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 88 ▶ $hydro = 10 if $hydro > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro > 10 5 83 88
77 88 my $population = roll2d6() - 2;
78 88 my $government = max(0, roll2d6() - 7 + $population);
79 88 my $law = max(0, roll2d6() - 7 + $government);
80 88 my $starport = roll2d6();
81 88 my $naval_base = 0;
82 88 my $scout_base = 0;
83 88 my $research_base = 0;
84 88 my $pirate_base = 0;
85 88 my $tech = roll1d6();
86 88 ▶ if ($starport <= 4) {
Branch: 5 branches
BranchTrueFalseTotal
if ($starport <= 4) { } 15 73 88
elsif ($starport <= 6) { } 25 48 73
elsif ($starport <= 8) { } 17 31 48
elsif ($starport <= 9) { } 12 19 31
elsif ($starport <= 11) { } 15 4 19
87 15 $starport = "A";
88 15 $tech += 6;
89 15 ▶ $scout_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 3 12 15
90 15 ▶ $naval_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 7 8 15
91 15 ▶ $research_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 6 9 15
92 } elsif ($starport <= 6) {
93 25 $starport = "B";
94 25 $tech += 4;
95 25 ▶ $scout_base = 1 if roll2d6() >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 9 6 19 25
96 25 ▶ $naval_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 13 12 25
97 25 ▶ $research_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 3 22 25
98 } elsif ($starport <= 8) {
99 17 $starport = "C";
100 17 $tech += 2;
101 17 ▶ $scout_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 3 14 17
102 17 ▶ $research_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 3 14 17
103 17 ▶ $pirate_base = 1 if roll2d6() >= 12;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 12 0 17 17
104 } elsif ($starport <= 9) {
105 12 $starport = "D";
106 12 ▶ $scout_base = 1 if roll2d6() >= 7;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 7 5 7 12
107 12 ▶ $pirate_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 4 8 12
108 } elsif ($starport <= 11) {
109 15 $starport = "E";
110 15 ▶ $pirate_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 1 14 15
111 } else {
112 4 $starport = "X";
113 4 $tech -= 4;
114 }
115 88 ▶ $tech += 1 if $size <= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 4 40 48 88
116 88 ▶ $tech += 1 if $size <= 1; # +2 total
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 1 8 80 88
117 88 ▶ $tech += 1 if $atmosphere <= 3 or $atmosphere >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere <= 3 or $atmosphere >= 10 41 47 88
Condition100%3/3
$atmosphere <= 3 or $atmosphere >= 10
l!l&&r!l&&!r
34747
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 88 ▶ $tech += 1 if $hydro >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 9 18 70 88
119 88 ▶ $tech += 1 if $hydro >= 10; # +2 total
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 10 10 78 88
120 88 ▶ $tech += 1 if $population >= 1 and $population <= 5;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 1 and $population <= 5 50 38 88
Condition100%3/3
$population >= 1 and $population <= 5
!ll&&!rl&&r
13750
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 88 ▶ $tech += 2 if $population >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 5 83 88
122 88 ▶ $tech += 2 if $population >= 10; # +4 total
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 10 3 85 88
123 88 ▶ $tech += 1 if $government == 0 or $government == 5;
Branch: 1 branch
BranchTrueFalseTotal
if $government == 0 or $government == 5 24 64 88
Condition100%3/3
$government == 0 or $government == 5
l!l&&r!l&&!r
111364
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 88 ▶ $tech -= 2 if $government == 13; # D
Branch: 1 branch
BranchTrueFalseTotal
if $government == 13 1 87 88
125 88 ▶ $tech = 0 if $tech < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $tech < 0 1 87 88
126 88 my $gas_giant = roll2d6() <= 9;
127 88 my $name = $self->compute_name();
128 88 ▶ $name = uc($name) if $population >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 5 83 88
129 88 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 88 my @tiles;
132 88 ▶ push(@tiles, "gas") if $gas_giant;
Branch: 1 branch
BranchTrueFalseTotal
if $gas_giant 77 11 88
133 88 push(@tiles, "size-" . code($size));
134 88 ▶ push(@tiles, "asteroid")
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 3 85 88
135 if $size == 0;
136 88 push(@tiles, "atmosphere-" . code($atmosphere));
137 88 ▶ push(@tiles, "vacuum")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere == 0 14 74 88
138 if $atmosphere == 0;
139 88 push(@tiles, "hydrosphere-" . code($hydro));
140 88 ▶ push(@tiles, "water")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro eq "A" 0 88 88
141 if $hydro eq "A";
142 88 ▶ push(@tiles, "desert")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere >= 2 and $hydro == 0 7 81 88
Condition100%3/3
$atmosphere >= 2 and $hydro == 0
!ll&&!rl&&r
20617
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 88 ▶ push(@tiles, "ice")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 1 and $atmosphere <= 1 0 88 88
Condition66%2/3
$hydro >= 1 and $atmosphere <= 1
!ll&&!rl&&r
27610
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 88 ▶ push(@tiles, "fluid")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 1 and $atmosphere >= 10 7 81 88
Condition100%3/3
$hydro >= 1 and $atmosphere >= 10
!ll&&!rl&&r
27547
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 88 push(@tiles, "population-" . code($population));
152 88 ▶ push(@tiles, "barren")
Branch: 1 branch
BranchTrueFalseTotal
if $population eq 0 and $law eq 0 and $government eq 0 0 88 88
Condition66%4/6
$population eq 0 and $law eq 0 and $government eq 0
!ll&&!rl&&r
8710
$population eq 0 and $law eq 0
!ll&&!rl&&r
8701
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 table50%2/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 88 ▶ push(@tiles, "low")
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 1 and $population <= 3 28 60 88
Condition100%3/3
$population >= 1 and $population <= 3
!ll&&!rl&&r
15928
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 88 ▶ push(@tiles, "high")
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 5 83 88
159 if $population >= 9;
160 88 ▶ 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 11 77 88
Condition100%15/15
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5 and $population <= 7
!ll&&!rl&&r
70711
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5
!ll&&!rl&&r
61918
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8
!ll&&!rl&&r
461527
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4
!ll&&!rl&&r
41542
$atmosphere >= 4 and $atmosphere <= 9
!ll&&!rl&&r
34747
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 88 ▶ push(@tiles, "non-agriculture")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere <= 3 and $hydro <= 3 and $population >= 6 13 75 88
Condition100%6/6
$atmosphere <= 3 and $hydro <= 3 and $population >= 6
!ll&&!rl&&r
611413
$atmosphere <= 3 and $hydro <= 3
!ll&&!rl&&r
54727
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 88 ▶ 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 1 87 88
Condition100%3/3
&any(sub { $atmosphere == $_; } , 0, 1, 2, 4, 7, 9) and $population >= 9
!ll&&!rl&&r
42451
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 88 ▶ push(@tiles, "non-industrial")
Branch: 1 branch
BranchTrueFalseTotal
if $population <= 6 63 25 88
172 if $population <= 6;
173 88 ▶ push(@tiles, "rich")
Branch: 1 branch
BranchTrueFalseTotal
if $government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6 and $population <= 8 2 86 88
Condition93%14/15
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6 and $population <= 8
!ll&&!rl&&r
8602
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6
!ll&&!rl&&r
7882
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8
!ll&&!rl&&r
423610
$government >= 4 and $government <= 9
!ll&&!rl&&r
33946
$atmosphere == 6 or $atmosphere == 8
l!l&&r!l&&!r
7336
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 table77%7/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 88 ▶ push(@tiles, "poor")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere >= 2 and $atmosphere <= 5 and $hydro <= 3 11 77 88
Condition100%6/6
$atmosphere >= 2 and $atmosphere <= 5 and $hydro <= 3
!ll&&!rl&&r
601711
$atmosphere >= 2 and $atmosphere <= 5
!ll&&!rl&&r
204028
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 88 push(@tiles, "tech-" . code($tech));
181 88 push(@tiles, "government-" . code($government));
182 88 push(@tiles, "starport-$starport");
183 88 push(@tiles, "law-" . code($law));
184 88 ▶ push(@tiles, "naval") if $naval_base;
Branch: 1 branch
BranchTrueFalseTotal
if $naval_base 20 68 88
185 88 ▶ push(@tiles, "scout") if $scout_base;
Branch: 1 branch
BranchTrueFalseTotal
if $scout_base 17 71 88
186 88 ▶ push(@tiles, "research") if $research_base;
Branch: 1 branch
BranchTrueFalseTotal
if $research_base 12 76 88
187 88 ▶ push(@tiles, "pirate", "red") if $pirate_base;
Branch: 1 branch
BranchTrueFalseTotal
if $pirate_base 5 83 88
188 88 ▶ 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 11 48 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
5749
$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
33743
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0 or $government == 7 or $government == 10
l!l&&r!l&&!r
29450
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0 or $government == 7
l!l&&r!l&&!r
23654
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0
l!l&&r!l&&!r
15860
$atmosphere >= 10 or $population and $government == 0
l!l&&r!l&&!r
6968
$population and $government == 0
!ll&&!rl&&r
1679
$population and $law == 0
!ll&&!rl&&r
1598
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 88 push(@tiles, qq{name="$name"}, qq{uwp="$uwp"});
198 88 return \@tiles;
199 }
200  
201 sub code {
202 1232 ▶ my $code = shift;
Subroutine code: called CC=2 SCAR=6.9
Pod undocumented
203 1232 ▶ return $code if $code <= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $code <= 9 1072 160 1232
204 160 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 43 push(@d, one(@first));
217 43 push(@d, one(@second));
218 }
219 2 return \@d;
220 }
221  
222 sub compute_name {
223 88 ▶ my $self = shift;
Subroutine compute_name: called CC=2 SCAR=6.9
Pod undocumented
224 88 my $max = scalar @{$self->digraphs};
225 88 my $length = 3 + rand(3); # length of name before adding one more
226 88 my $name = '';
227 88 ▶ while (length($name) < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $name < $length) 213 88 301
228 213 my $i = 2*int(rand($max/2));
229 213 $name .= $self->digraphs->[$i];
230 213 $name .= $self->digraphs->[$i+1];
231 }
232 88 $name =~ s/\.//g;
233 88 return ucfirst($name);
234 }
235  
236 sub one {
237 86 ▶ return $_[int(rand(scalar @_))];
Subroutine one: called CC=1 SCAR=0.0
Pod undocumented
238 }
239  
240 sub roll1d6 {
241 2076 ▶ return 1+int(rand(6));
Subroutine roll1d6: called CC=1 SCAR=0.0
Pod undocumented
242 }
243  
244 sub roll2d6 {
245 914 ▶ return roll1d6() + roll1d6();
Subroutine roll2d6: called CC=1 SCAR=0.0
Pod undocumented
246 }
247  
248 sub xy {
249 88 ▶ my $self = shift;
Subroutine xy: called CC=1 SCAR=0.0
Pod undocumented
250 88 my $i = shift;
251 88 my $y = int($i / $self->cols);
252 88 my $x = $i % $self->cols;
253 88 $log->debug("$i ($x, $y)");
254 88 return $x + 1, $y + 1;
255 }
256  
257 sub label {
258 95 ▶ my ($self, $from, $to, $d, $label) = @_;
Subroutine label: called CC=1 SCAR=0.0
Pod undocumented
259 95 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.4
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) 88 2 90
272 88 my $from = shift(@coordinates);
273 88 my ($x1, $y1, $system1) = @$from;
274 88 ▶ 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) 4 84 88
275 84 for my $to (@coordinates) {
276 1805 my ($x2, $y2, $system2) = @$to;
277 1805 ▶ 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) 79 1726 1805
278 1726 my $d = $self->distance($x1, $y1, $x2, $y2);
279 1726 ▶ 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)) 63 1663 1726
Condition100%3/3
$d <= 2 and match(qr/^(starport-[AB]|naval)$/u, qr/^(starport-[AB]|naval)$/u, $system1, $system2)
!ll&&!rl&&r
144421963
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 63 push(@comms, [$from, $to, $d]);
281 }
282 1726 ▶ 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 1665 1665
Condition87%34/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
14442820
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
610221
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
610221
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
601221
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
600222
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
4911222
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
481233
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
462234
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
460236
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
415236
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
401241
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
364242
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
333246
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 61 push(@trade, [$from, $to, $d]);
325 }
326 1726 ▶ 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)) 12 1714 1726
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
123048412
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 12 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 3863 ▶ my ($re1, $re2, $sys1, $sys2) = @_;
Subroutine match: called CC=5 SCAR=16.1
Pod undocumented
343 3863 ▶ 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) 85 3778 3863
Condition100%3/3
&any(sub { /$re1/u; } , @$sys1) and &any(sub { /$re2/u; } , @$sys2)
!ll&&!rl&&r
329947985
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 3778 ▶ 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) 51 3727 3778
Condition100%3/3
&any(sub { /$re2/u; } , @$sys1) and &any(sub { /$re1/u; } , @$sys2)
!ll&&!rl&&r
2574115351
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 3727 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 136 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 136 ▶ 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}) 95 41 136
Condition100%6/6
not $C{$u} && $C{$v} or $C{$u} != $C{$v}
l!l&&r!l&&!r
791641
$C{$u} && $C{$v}
!ll&&!rl&&r
483157
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 95 push(@T, $edge);
367 # Merge C(v) and C(u) into one cluster, that is, union C(v) and C(u).
368 95 ▶ if ($C{$u} and $C{$v}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($C{$u} and $C{$v}) { } 16 79 95
elsif ($C{$v} and not $C{$u}) { } 21 58 79
elsif ($C{$u} and not $C{$v}) { } 31 27 58
elsif (not $C{$u} || $C{$v}) { } 27 0 27
Condition100%3/3
$C{$u} and $C{$v}
!ll&&!rl&&r
483116
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 16 my @group;
370 16 foreach (keys %C) {
371 329 ▶ push(@group, $_) if $C{$_} == $C{$v};
Branch: 1 branch
BranchTrueFalseTotal
if $C{$_} == $C{$v} 63 266 329
372 }
373 16 $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
58021
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 21 $C{$u} = $C{$v};
376 ▶ } elsif ($C{$u} and not $C{$v}) {
Condition66%2/3
$C{$u} and not $C{$v}
!ll&&!rl&&r
27031
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 31 $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
0027
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 27 $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/Command/random.pm »