lib/BalanceOfPower/Nation/Role/IA.pm

filter: Statementstmt 85.1% 80 / 94 Branchbran 63.6% 28 / 44 Conditioncond 44.4% 8 / 18 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 7 totaltotal 70.5% 132 / 187 CC 31 SCAR 29.3
CC
31
Cov
74%
good_prey
37.5
accept_military_support
9.9
decision
8.0
CRAP 18.8
« blib/lib/BalanceOfPower/Commands/TargetNation.pm ↑ Summary blib/lib/BalanceOfPower/Dice.pm »
1 package BalanceOfPower::Nation::Role::IA;
2 11 $BalanceOfPower::Nation::Role::IA::VERSION = '0.200000';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Array::Utils qw(intersect);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use BalanceOfPower::Utils qw( prev_turn );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 has executive => (
12 is => 'rw',
13 handles => { decide => 'decide' }
14
15 );
16  
17 sub decision
18 {
19 64 ▶ my $self = shift;
Subroutine decision: called CC=8 SCAR=20.8
Pod undocumented
20 64 my $world = shift;
21 64 my @advisors;
22 64 ▶ if($world->at_war($self->name) || $world->at_civil_war($self->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->at_war($self->name) or $world->at_civil_war($self->name)) { } 9 55 64
Condition100%3/3
$world->at_war($self->name) or $world->at_civil_war($self->name)
l!l&&r!l&&!r
4555
MC/DC100%2/2
$world->at_war($self->name) or $world->at_civil_war($self->name)
$world->at_war($self->name) $world->at_civil_war($self->name)
Truth table100%3/3
A or B
A= $world->at_war($self->name)B= $world->at_civil_war($self->name)
ABresult
1X1
011
000
23 {
24 9 @advisors = ('military');
25 }
26 else
27 {
28 55 @advisors = ('domestic', 'economy', 'military');
29 }
30 64 @advisors = $world->shuffle("Choosing advisor for ".$self->name, @advisors);
31 64 foreach my $a (@advisors)
32 {
33 73 my $decision = undef;
34 73 ▶ if($a eq 'domestic')
Branch: 3 branches
BranchTrueFalseTotal
if ($a eq 'domestic') { } 21 52 73
elsif ($a eq 'economy') { } 14 38 52
elsif ($a eq 'military') { } 24 14 38
35 {
36 21 $decision = $self->domestic_advisor();
37 }
38 elsif($a eq 'economy')
39 {
40 14 $decision = $self->economy_advisor();
41 }
42 elsif($a eq 'military')
43 {
44 24 $decision = $self->military_advisor();
45 }
46 73 ▶ return $self->name . ": " . $decision if($decision);
Branch: 1 branch
BranchTrueFalseTotal
if $decision 48 25 73
47 }
48 16 return undef;
49 }
50  
51 sub advisor
52 {
53 59 ▶ my $self = shift;
Subroutine advisor: called CC=3 SCAR=11.0
Pod undocumented
54 59 my @orders = @_;
55 59 my $order = undef;
56 59 for(@orders)
57 {
58 224 $order = $self->decide($_);
59 224 ▶ return $order if $order;
Branch: 1 branch
BranchTrueFalseTotal
if $order 48 176 224
60 }
61 11 return undef;
62 }
63  
64 sub domestic_advisor
65 {
66 21 ▶ my $self = shift;
Subroutine domestic_advisor: called CC=1 SCAR=0.0
Pod undocumented
67 21 return $self->advisor("LOWER DISORDER",
68 "BOOST PRODUCTION",
69 "TREATY NAG WITH",
70 "DIPLOMATIC PRESSURE ON",
71 "MILITARY AID FOR",
72 "PROGRESS");
73 }
74  
75 sub economy_advisor
76 {
77 14 ▶ my $self = shift;
Subroutine economy_advisor: called CC=1 SCAR=0.0
Pod undocumented
78 14 return $self->advisor("TREATY COM WITH",
79 "DELETE TRADEROUTE",
80 "ADD ROUTE",
81 "ECONOMIC AID");
82 }
83  
84 sub military_advisor
85 {
86 24 ▶ my $self = shift;
Subroutine military_advisor: called CC=1 SCAR=0.0
Pod undocumented
87 24 return $self->advisor("DECLARE WAR TO",
88 "AID INSURGENTS IN",
89 "MILITARY SUPPORT",
90 "REBEL MILITARY SUPPORT",
91 "RECALL MILITARY SUPPORT",
92 "BUILD TROOPS");
93 }
94 sub accept_military_support
95 {
96 4 ▶ my $self = shift;
Subroutine accept_military_support: called CC=5 SCAR=22.9
Pod undocumented
97 4 my $other = shift;
98 4 my $world = shift;
99 4 ▶ if($world->already_in_military_support($self->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->already_in_military_support($self->name)) 0 4 4
100 {
101 0 my $supd = $world->supported($self->name);
102 0 ▶ if($supd && $supd->node1 eq $other)
Branch: 1 branch
BranchTrueFalseTotal
if ($supd and $supd->node1 eq $other) { } 0 0 0
Condition0%0/3
$supd and $supd->node1 eq $other
!ll&&!rl&&r
000
MC/DC0%0/2
$supd and $supd->node1 eq $other
$supd $supd->node1 eq $other
Truth table0%0/3
A and B
A= $supdB= $supd->node1 eq $other
ABresult
0X0
100
111
103 {
104 0 return 1;
105 }
106 else
107 {
108 0 return 0;
109 }
110 }
111 4 ▶ return 0 if($world->diplomacy_status($self->name, $other) eq 'HATE');
Branch: 1 branch
BranchTrueFalseTotal
if $world->diplomacy_status($self->name, $other) eq "HATE" 0 4 4
112 4 return $self->army < ARMY_TO_ACCEPT_MILITARY_SUPPORT;
113 }
114  
115 sub good_prey
116 {
117 19 ▶ my $self = shift;
Subroutine good_prey: called CC=18 SCAR=36.2
Pod undocumented
118 19 my $enemy = shift;
119 19 my $world = shift;
120  
121 19 my $crisis = $world->crisis_exists($self->name, $enemy->name);
122 19 ▶ my $level = $crisis ? $crisis->get_crisis_level : ALLY_CONFLICT_LEVEL_FOR_INVOLVEMENT;
Branch: 1 branch
BranchTrueFalseTotal
$crisis ? : 17 2 19
123  
124 19 ▶ if($self->army < MIN_ARMY_FOR_WAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->army < 5) 16 3 19
125 {
126 16 return 0;
127 }
128 3 my $war_points = 0;
129  
130 #ARMY EVALUATION
131 3 my $army_ratio;
132 3 ▶ if($enemy->army > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($enemy->army > 0) { } 1 2 3
133 {
134 1 $army_ratio = int($self->army / $enemy->army);
135 }
136 else
137 {
138 2 $army_ratio = 3;
139 }
140 3 ▶ if($army_ratio < 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($army_ratio < 1) 0 3 3
141 {
142 0 my $reverse_army_ratio = $enemy->army / $self->army;
143 0 ▶ if($reverse_army_ratio > MIN_INFERIOR_ARMY_RATIO_FOR_WAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse_army_ratio > 1.2) { } 0 0 0
144 {
145 0 return 0;
146 }
147 else
148 {
149 0 $army_ratio = -1;
150 }
151 }
152 3 $war_points += $army_ratio;
153  
154 #INTERNAL EVALUATION
155 3 ▶ if($self->internal_disorder_status eq 'Peace')
Branch: 3 branches
BranchTrueFalseTotal
if ($self->internal_disorder_status eq 'Peace') { } 3 0 3
elsif ($self->internal_disorder_status eq 'Terrorism') { } 0 0 0
elsif ($self->internal_disorder_status eq 'Insurgence') { } 0 0 0
156 {
157 3 $war_points += 1;
158 }
159 elsif($self->internal_disorder_status eq 'Terrorism')
160 {
161 0 $war_points += 0;
162 }
163 elsif($self->internal_disorder_status eq 'Insurgence')
164 {
165 0 $war_points += -1;
166 }
167  
168 #WEALTH EVALUATION/PROGRES EVALUATION
169 3 my $wealth = $world->get_statistics_value(prev_turn($self->current_year), $self->name, 'wealth');
170 3 my $enemy_wealth = $world->get_statistics_value(prev_turn($self->current_year), $enemy->name, 'wealth');
171 3 my $progress_delta = $enemy->progress - $self->progress;
172 3 ▶ if($wealth && $enemy_wealth)
Branch: 1 branch
BranchTrueFalseTotal
if ($wealth and $enemy_wealth) { } 1 2 3
Condition66%2/3
$wealth and $enemy_wealth
!ll&&!rl&&r
201
MC/DC50%1/2
$wealth and $enemy_wealth
$wealth $enemy_wealth
Truth table66%2/3
A and B
A= $wealthB= $enemy_wealth
ABresult
0X0
100
111
173 {
174 1 ▶ if($enemy_wealth > $wealth)
Branch: 1 branch
BranchTrueFalseTotal
if ($enemy_wealth > $wealth) { } 0 1 1
175 {
176 0 $war_points += 1
177 }
178 else
179 {
180 1 ▶ if($progress_delta > 0 && $progress_delta < MAX_AFFORDABLE_PROGRESS)
Branch: 1 branch
BranchTrueFalseTotal
if ($progress_delta > 0 and $progress_delta < "0.8") 0 1 1
Condition33%1/3
$progress_delta > 0 and $progress_delta < "0.8"
!ll&&!rl&&r
100
MC/DC0%0/2
$progress_delta > 0 and $progress_delta < "0.8"
$progress_delta > 0 $progress_delta < "0.8"
Truth table33%1/3
A and B
A= $progress_delta > 0B= $progress_delta < "0.8"
ABresult
0X0
100
111
181 {
182 0 $war_points += 1
183 }
184
185 }
186 }
187 else
188 {
189 2 $war_points += 1;
190 }
191  
192
193 #COALITION EVALUATION
194 3 ▶ if($world->empire($self->name) && $world->empire($enemy->name) && $world->empire($self->name) > $world->empire($enemy->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->empire($self->name) and $world->empire($enemy->name) and $world->empire($self->name) > $world->empire($enemy->name)) 0 3 3
Condition33%2/6
$world->empire($self->name) and $world->empire($enemy->name) and $world->empire($self->name) > $world->empire($enemy->name)
!ll&&!rl&&r
030
$world->empire($self->name) and $world->empire($enemy->name)
!ll&&!rl&&r
003
MC/DC0%0/3
$world->empire($self->name) and $world->empire($enemy->name) and $world->empire($self->name) > $world->empire($enemy->name)
$world->empire($self->name) $world->empire($enemy->name) $world->empire($self->name) > $world->empire($enemy->name)
Truth table25%1/4
A and B and C
A= $world->empire($self->name)B= $world->empire($enemy->name)C= $world->empire($self->name) > $world->empire($enemy->name)
ABCresult
0XX0
10X0
1100
1111
195 {
196 0 $war_points += 1;
197 }
198 3 ▶ if($war_points + $level >= 4)
Branch: 1 branch
BranchTrueFalseTotal
if ($war_points + $level >= 4) { } 3 0 3
199 {
200 3 return 1;
201 }
202 else
203 {
204 0 return 0;
205 }
206 }
207  
208 11 1;
209  
« blib/lib/BalanceOfPower/Commands/TargetNation.pm ↑ Summary blib/lib/BalanceOfPower/Dice.pm »