blib/lib/Game/TextMapper/Traveller.pm

filter: Statementstmt 100% 245 / 245 Branchbran 94.5% 138 / 146 Conditioncond 92.4% 160 / 173 MC/DCmcdc 82.1% 69 / 84 Subroutinesub 100% 28 / 28 Podpod 6.6% 1 / 15 totaltotal 92.7% 641 / 691 CC 139 SCAR 39.7
CC
139
Cov
96%
system
89.1
comms
23.2
minimal_spanning_tree
16.2
CRAP 53.1
« blib/lib/auto/share/dist/Game-TextMapper/extract-svg.pl ↑ Summary blib/lib/Game/TextMapper/Schroeder/Alpine.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 2 ▶sub generate_map {
Subroutine generate_map: called CC=2 SCAR=6.9
Pod documented
55 2 my $self = shift;
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)];
Condition100%2/2
$systems{$_} || ['empty']
l!l
7090
MC/DC100%1/1
$systems{$_} || ['empty']
$systems{$_}
Truth table100%2/2
A
A= $systems{$_}
Aresult
11
00
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 70 ▶sub system {
Subroutine system: called CC=89 SCAR=44.9
Pod undocumented
69 70 my $self = shift;
70 70 my $size = roll2d6() - 2;
71 70 my $atmosphere = max(0, roll2d6() - 7 + $size);
72 70 ▶ $atmosphere = 0 if $size == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 3 67 70
73 70 my $hydro = roll2d6() - 7 + $atmosphere;
74 70 ▶ $hydro -= 4 if $atmosphere < 2 or $atmosphere >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere < 2 or $atmosphere >= 10 21 49 70
Condition100%3/3
$atmosphere < 2 or $atmosphere >= 10
l!l&&r!l&&!r
13849
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 70 ▶ $hydro = 0 if $hydro < 0 or $size < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro < 0 or $size < 2 16 54 70
Condition100%3/3
$hydro < 0 or $size < 2
l!l&&r!l&&!r
15154
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 70 ▶ $hydro = 10 if $hydro > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro > 10 0 70 70
77 70 my $population = roll2d6() - 2;
78 70 my $government = max(0, roll2d6() - 7 + $population);
79 70 my $law = max(0, roll2d6() - 7 + $government);
80 70 my $starport = roll2d6();
81 70 my $naval_base = 0;
82 70 my $scout_base = 0;
83 70 my $research_base = 0;
84 70 my $pirate_base = 0;
85 70 my $tech = roll1d6();
86 70 ▶ if ($starport <= 4) {
Branch: 5 branches
BranchTrueFalseTotal
if ($starport <= 4) { } 8 62 70
elsif ($starport <= 6) { } 13 49 62
elsif ($starport <= 8) { } 25 24 49
elsif ($starport <= 9) { } 9 15 24
elsif ($starport <= 11) { } 11 4 15
87 8 $starport = "A";
88 8 $tech += 6;
89 8 ▶ $scout_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 1 7 8
90 8 ▶ $naval_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 4 4 8
91 8 ▶ $research_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 3 5 8
92 } elsif ($starport <= 6) {
93 13 $starport = "B";
94 13 $tech += 4;
95 13 ▶ $scout_base = 1 if roll2d6() >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 9 4 9 13
96 13 ▶ $naval_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 5 8 13
97 13 ▶ $research_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 3 10 13
98 } elsif ($starport <= 8) {
99 25 $starport = "C";
100 25 $tech += 2;
101 25 ▶ $scout_base = 1 if roll2d6() >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 8 14 11 25
102 25 ▶ $research_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 7 18 25
103 25 ▶ $pirate_base = 1 if roll2d6() >= 12;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 12 2 23 25
104 } elsif ($starport <= 9) {
105 9 $starport = "D";
106 9 ▶ $scout_base = 1 if roll2d6() >= 7;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 7 3 6 9
107 9 ▶ $pirate_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 2 7 9
108 } elsif ($starport <= 11) {
109 11 $starport = "E";
110 11 ▶ $pirate_base = 1 if roll2d6() >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if roll2d6() >= 10 3 8 11
111 } else {
112 4 $starport = "X";
113 4 $tech -= 4;
114 }
115 70 ▶ $tech += 1 if $size <= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 4 32 38 70
116 70 ▶ $tech += 1 if $size <= 1; # +2 total
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 1 8 62 70
117 70 ▶ $tech += 1 if $atmosphere <= 3 or $atmosphere >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere <= 3 or $atmosphere >= 10 34 36 70
Condition100%3/3
$atmosphere <= 3 or $atmosphere >= 10
l!l&&r!l&&!r
26836
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 70 ▶ $tech += 1 if $hydro >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 9 7 63 70
119 70 ▶ $tech += 1 if $hydro >= 10; # +2 total
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 10 3 67 70
120 70 ▶ $tech += 1 if $population >= 1 and $population <= 5;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 1 and $population <= 5 38 32 70
Condition100%3/3
$population >= 1 and $population <= 5
!ll&&!rl&&r
52738
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 70 ▶ $tech += 2 if $population >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 8 62 70
122 70 ▶ $tech += 2 if $population >= 10; # +4 total
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 10 2 68 70
123 70 ▶ $tech += 1 if $government == 0 or $government == 5;
Branch: 1 branch
BranchTrueFalseTotal
if $government == 0 or $government == 5 7 63 70
Condition100%3/3
$government == 0 or $government == 5
l!l&&r!l&&!r
4363
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 70 ▶ $tech -= 2 if $government == 13; # D
Branch: 1 branch
BranchTrueFalseTotal
if $government == 13 0 70 70
125 70 ▶ $tech = 0 if $tech < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $tech < 0 1 69 70
126 70 my $gas_giant = roll2d6() <= 9;
127 70 my $name = $self->compute_name();
128 70 ▶ $name = uc($name) if $population >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 8 62 70
129 70 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 70 my @tiles;
132 70 ▶ push(@tiles, "gas") if $gas_giant;
Branch: 1 branch
BranchTrueFalseTotal
if $gas_giant 54 16 70
133 70 push(@tiles, "size-" . code($size));
134 70 ▶ push(@tiles, "asteroid")
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 3 67 70
135 if $size == 0;
136 70 push(@tiles, "atmosphere-" . code($atmosphere));
137 70 ▶ push(@tiles, "vacuum")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere == 0 8 62 70
138 if $atmosphere == 0;
139 70 push(@tiles, "hydrosphere-" . code($hydro));
140 70 ▶ push(@tiles, "water")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro eq "A" 0 70 70
141 if $hydro eq "A";
142 70 ▶ push(@tiles, "desert")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere >= 2 and $hydro == 0 5 65 70
Condition100%3/3
$atmosphere >= 2 and $hydro == 0
!ll&&!rl&&r
13525
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 70 ▶ push(@tiles, "ice")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 1 and $atmosphere <= 1 0 70 70
Condition66%2/3
$hydro >= 1 and $atmosphere <= 1
!ll&&!rl&&r
18520
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 70 ▶ push(@tiles, "fluid")
Branch: 1 branch
BranchTrueFalseTotal
if $hydro >= 1 and $atmosphere >= 10 8 62 70
Condition100%3/3
$hydro >= 1 and $atmosphere >= 10
!ll&&!rl&&r
18448
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 70 push(@tiles, "population-" . code($population));
152 70 ▶ push(@tiles, "barren")
Branch: 1 branch
BranchTrueFalseTotal
if $population eq 0 and $law eq 0 and $government eq 0 3 67 70
Condition100%6/6
$population eq 0 and $law eq 0 and $government eq 0
!ll&&!rl&&r
6613
$population eq 0 and $law eq 0
!ll&&!rl&&r
6514
MC/DC100%3/3
$population eq 0 and $law eq 0 and $government eq 0
$population eq 0 $law eq 0 $government eq 0
Truth table100%4/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 70 ▶ push(@tiles, "low")
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 1 and $population <= 3 13 57 70
Condition100%3/3
$population >= 1 and $population <= 3
!ll&&!rl&&r
55213
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 70 ▶ push(@tiles, "high")
Branch: 1 branch
BranchTrueFalseTotal
if $population >= 9 8 62 70
159 if $population >= 9;
160 70 ▶ 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 6 64 70
Condition100%15/15
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5 and $population <= 7
!ll&&!rl&&r
6046
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8 and $population >= 5
!ll&&!rl&&r
501010
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4 and $hydro <= 8
!ll&&!rl&&r
43720
$atmosphere >= 4 and $atmosphere <= 9 and $hydro >= 4
!ll&&!rl&&r
34927
$atmosphere >= 4 and $atmosphere <= 9
!ll&&!rl&&r
26836
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 70 ▶ push(@tiles, "non-agriculture")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere <= 3 and $hydro <= 3 and $population >= 6 9 61 70
Condition100%6/6
$atmosphere <= 3 and $hydro <= 3 and $population >= 6
!ll&&!rl&&r
49129
$atmosphere <= 3 and $hydro <= 3
!ll&&!rl&&r
44521
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 70 ▶ 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 7 63 70
Condition100%3/3
&any(sub { $atmosphere == $_; } , 0, 1, 2, 4, 7, 9) and $population >= 9
!ll&&!rl&&r
28357
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 70 ▶ push(@tiles, "non-industrial")
Branch: 1 branch
BranchTrueFalseTotal
if $population <= 6 51 19 70
172 if $population <= 6;
173 70 ▶ push(@tiles, "rich")
Branch: 1 branch
BranchTrueFalseTotal
if $government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6 and $population <= 8 1 69 70
Condition100%15/15
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6 and $population <= 8
!ll&&!rl&&r
6811
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8 and $population >= 6
!ll&&!rl&&r
6622
$government >= 4 and $government <= 9 and $atmosphere == 6 || $atmosphere == 8
!ll&&!rl&&r
36304
$government >= 4 and $government <= 9
!ll&&!rl&&r
30634
$atmosphere == 6 or $atmosphere == 8
l!l&&r!l&&!r
2230
MC/DC66%4/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 70 ▶ push(@tiles, "poor")
Branch: 1 branch
BranchTrueFalseTotal
if $atmosphere >= 2 and $atmosphere <= 5 and $hydro <= 3 14 56 70
Condition100%6/6
$atmosphere >= 2 and $atmosphere <= 5 and $hydro <= 3
!ll&&!rl&&r
441214
$atmosphere >= 2 and $atmosphere <= 5
!ll&&!rl&&r
133126
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 70 push(@tiles, "tech-" . code($tech));
181 70 push(@tiles, "government-" . code($government));
182 70 push(@tiles, "starport-$starport");
183 70 push(@tiles, "law-" . code($law));
184 70 ▶ push(@tiles, "naval") if $naval_base;
Branch: 1 branch
BranchTrueFalseTotal
if $naval_base 9 61 70
185 70 ▶ push(@tiles, "scout") if $scout_base;
Branch: 1 branch
BranchTrueFalseTotal
if $scout_base 22 48 70
186 70 ▶ push(@tiles, "research") if $research_base;
Branch: 1 branch
BranchTrueFalseTotal
if $research_base 13 57 70
187 70 ▶ push(@tiles, "pirate", "red") if $pirate_base;
Branch: 1 branch
BranchTrueFalseTotal
if $pirate_base 7 63 70
188 70 ▶ 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 32 38 70
Condition91%22/24
not $pirate_base and $atmosphere >= 10 || $population && $government == 0 || $population && $law == 0 || $government == 7 || $government == 10 || $law >= 9
!ll&&!rl&&r
73132
$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
23931
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0 or $government == 7 or $government == 10
l!l&&r!l&&!r
17640
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0 or $government == 7
l!l&&r!l&&!r
12546
$atmosphere >= 10 or $population and $government == 0 or $population and $law == 0
l!l&&r!l&&!r
6651
$atmosphere >= 10 or $population and $government == 0
l!l&&r!l&&!r
6057
$population and $government == 0
!ll&&!rl&&r
5520
$population and $law == 0
!ll&&!rl&&r
5466
MC/DC88%8/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 table38%8/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 70 push(@tiles, qq{name="$name"}, qq{uwp="$uwp"});
198 70 return \@tiles;
199 }
200  
201 980 ▶sub code {
Subroutine code: called CC=2 SCAR=6.9
Pod undocumented
202 980 my $code = shift;
203 980 ▶ return $code if $code <= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $code <= 9 872 108 980
204 108 return chr(55+$code); # 10 is A
205 }
206  
207 2 ▶sub compute_digraphs {
Subroutine compute_digraphs: called CC=2 SCAR=6.9
Pod undocumented
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
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 44 push(@d, one(@first));
217 44 push(@d, one(@second));
218 }
219 2 return \@d;
220 }
221  
222 70 ▶sub compute_name {
Subroutine compute_name: called CC=2 SCAR=6.9
Pod undocumented
223 70 my $self = shift;
224 70 my $max = scalar @{$self->digraphs};
225 70 my $length = 3 + rand(3); # length of name before adding one more
226 70 my $name = '';
227 70 ▶ while (length($name) < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $name < $length) 167 70 237
228 167 my $i = 2*int(rand($max/2));
229 167 $name .= $self->digraphs->[$i];
230 167 $name .= $self->digraphs->[$i+1];
231 }
232 70 $name =~ s/\.//g;
233 70 return ucfirst($name);
234 }
235  
236 88 ▶sub one {
Subroutine one: called CC=1 SCAR=0.0
Pod undocumented
237 88 return $_[int(rand(scalar @_))];
238 }
239  
240 1684 ▶sub roll1d6 {
Subroutine roll1d6: called CC=1 SCAR=0.0
Pod undocumented
241 1684 return 1+int(rand(6));
242 }
243  
244 727 ▶sub roll2d6 {
Subroutine roll2d6: called CC=1 SCAR=0.0
Pod undocumented
245 727 return roll1d6() + roll1d6();
246 }
247  
248 70 ▶sub xy {
Subroutine xy: called CC=1 SCAR=0.0
Pod undocumented
249 70 my $self = shift;
250 70 my $i = shift;
251 70 my $y = int($i / $self->cols);
252 70 my $x = $i % $self->cols;
253 70 $log->debug("$i ($x, $y)");
254 70 return $x + 1, $y + 1;
255 }
256  
257 64 ▶sub label {
Subroutine label: called CC=1 SCAR=0.0
Pod undocumented
258 64 my ($self, $from, $to, $d, $label) = @_;
259 64 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 2 ▶sub comms {
Subroutine comms: called CC=23 SCAR=31.4
Pod undocumented
265 2 my $self = shift;
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) 70 2 72
272 70 my $from = shift(@coordinates);
273 70 my ($x1, $y1, $system1) = @$from;
274 70 ▶ 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 66 70
275 66 for my $to (@coordinates) {
276 1117 my ($x2, $y2, $system2) = @$to;
277 1117 ▶ 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) 57 1060 1117
278 1060 my $d = $self->distance($x1, $y1, $x2, $y2);
279 1060 ▶ 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)) 21 1039 1060
Condition100%3/3
$d <= 2 and match(qr/^(starport-[AB]|naval)$/u, qr/^(starport-[AB]|naval)$/u, $system1, $system2)
!ll&&!rl&&r
86817121
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 21 push(@comms, [$from, $to, $d]);
281 }
282 1060 ▶ 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)) 57 1003 1060
Condition84%33/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
86813557
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
570135
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
570135
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
570135
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
570135
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
543135
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
540138
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
3519138
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
350157
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
278157
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
234165
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
203169
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
191172
MC/DC57%8/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 table60%9/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 57 push(@trade, [$from, $to, $d]);
325 }
326 1060 ▶ 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)) 8 1052 1060
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
7243288
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 8 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 2529 ▶sub match {
Subroutine match: called CC=5 SCAR=16.1
Pod undocumented
342 2529 my ($re1, $re2, $sys1, $sys2) = @_;
343 2529 ▶ return 1 if any { /$re1/ } @$sys1 and any { /$re2/ } @$sys2;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /$re1/u; } , @$sys1) and &any(sub { /$re2/u; } , @$sys2) 58 2471 2529
Condition100%3/3
&any(sub { /$re1/u; } , @$sys1) and &any(sub { /$re2/u; } , @$sys2)
!ll&&!rl&&r
219227958
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 2471 ▶ return 1 if any { /$re2/ } @$sys1 and any { /$re1/ } @$sys2;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /$re2/u; } , @$sys1) and &any(sub { /$re1/u; } , @$sys2) 28 2443 2471
Condition100%3/3
&any(sub { /$re2/u; } , @$sys1) and &any(sub { /$re1/u; } , @$sys2)
!ll&&!rl&&r
176368028
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 2443 return 0;
346 }
347  
348 6 ▶sub minimal_spanning_tree {
Subroutine minimal_spanning_tree: called CC=16 SCAR=27.9
Pod undocumented
349 # http://en.wikipedia.org/wiki/Kruskal%27s_algorithm
350 6 my $self = shift;
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 86 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 86 ▶ 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}) 64 22 86
Condition100%6/6
not $C{$u} && $C{$v} or $C{$u} != $C{$v}
l!l&&r!l&&!r
541022
$C{$u} && $C{$v}
!ll&&!rl&&r
262832
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 64 push(@T, $edge);
367 # Merge C(v) and C(u) into one cluster, that is, union C(v) and C(u).
368 64 ▶ if ($C{$u} and $C{$v}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($C{$u} and $C{$v}) { } 10 54 64
elsif ($C{$v} and not $C{$u}) { } 8 46 54
elsif ($C{$u} and not $C{$v}) { } 28 18 46
elsif (not $C{$u} || $C{$v}) { } 18 0 18
Condition100%3/3
$C{$u} and $C{$v}
!ll&&!rl&&r
262810
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 10 my @group;
370 10 foreach (keys %C) {
371 129 ▶ push(@group, $_) if $C{$_} == $C{$v};
Branch: 1 branch
BranchTrueFalseTotal
if $C{$_} == $C{$v} 42 87 129
372 }
373 10 $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
4608
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 8 $C{$u} = $C{$v};
376 ▶ } elsif ($C{$u} and not $C{$v}) {
Condition66%2/3
$C{$u} and not $C{$v}
!ll&&!rl&&r
18028
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 28 $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
0018
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 18 $C{$v} = $C{$u} = ++$id;
380 }
381 }
382 }
383 6 return \@T;
384 }
385  
386 2 ▶sub to_text {
Subroutine to_text: called CC=4 SCAR=13.9
Pod undocumented
387 2 my $self = shift;
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 2 ▶sub legend {
Subroutine legend: called CC=3 SCAR=11.0
Pod undocumented
405 2 my $self = shift;
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/Schroeder/Alpine.pm »