lib/BalanceOfPower/Dice.pm

filter: Statementstmt 17.4% 18 / 103 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 4 / 12 Podpod 0.0% 0 / 6 totaltotal 14.0% 22 / 157 CC 17 SCAR 30.6
CC
17
Cov
13%
shuffle_array
56.0
tricked
20.0
random
12.0
CRAP 21.4
« lib/BalanceOfPower/Relations/War.pm ↑ Summary lib/BalanceOfPower/Relations/RelPack.pm »
1 package BalanceOfPower::Dice;
2 11 $BalanceOfPower::Dice::VERSION = '0.300010';
3 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 with 'BalanceOfPower::Role::Logger';
9  
10 has tricks => (
11 is => 'rw',
12 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
13 11 );
14 has trick_counters => (
15 is => 'rw',
16 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 11 );
18 11 has forced_advisor => (
19 is => 'rw',
20 default => 0
21 );
22 11 has only_one_nation_acting => (
23 is => 'rw',
24 default => 0
25 );
26  
27 sub random
28 {
29 0 ▶ my $self = shift;
Subroutine random: not called CC=3 SCAR=24.8
Pod undocumented
30 0 my $min = shift;
31 0 my $max = shift;
32 0 ▶ my $message = shift || "NO MESSAGE [$min-$max]";
Condition0%0/2
shift() || "NO MESSAGE [$min-$max]"
l!l
00
MC/DC0%0/1
shift() || "NO MESSAGE [$min-$max]"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
33 0 my $out = $self->tricked($message);
34 0 ▶ if(defined $out)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out) { } 0 0 0
35 {
36 0 $self->write_log($message, $out, 1);
37 0 return $out;
38 }
39 else
40 {
41 0 my $random_range = $max - $min + 1;
42 0 $out = int(rand($random_range)) + $min;
43 0 $self->write_log($message, $out, 0);
44 0 return $out;
45 }
46 }
47  
48 sub random10
49 {
50 0 ▶ my $self = shift;
Subroutine random10: not called CC=3 SCAR=24.8
Pod undocumented
51 0 my $min = shift;
52 0 my $max = shift;
53 0 ▶ my $message = shift || "NO MESSAGE [$min-$max]";
Condition0%0/2
shift() || "NO MESSAGE [$min-$max]"
l!l
00
MC/DC0%0/1
shift() || "NO MESSAGE [$min-$max]"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
54 0 my $out = $self->tricked($message);
55 0 ▶ if(defined $out)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out) { } 0 0 0
56 {
57 0 $self->write_log($message, $out, 1);
58 0 return $out;
59 }
60 else
61 {
62 0 my $random_range = (($max - $min) / 10) + 1;
63 0 $out = (int(rand($random_range)) * 10) + $min;
64 0 $self->write_log($message, $out, 0);
65 0 return $out;
66 }
67 }
68  
69 sub random_around_zero
70 {
71 0 ▶ my $self = shift;
Subroutine random_around_zero: not called CC=3 SCAR=24.8
Pod undocumented
72 0 my $max = shift;
73 0 ▶ my $divider = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
74 0 my $message = shift;
75 0 my $out = $self->tricked($message);
76 0 ▶ if(defined $out)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out) { } 0 0 0
77 {
78 0 $self->write_log($message, $out, 1);
79 0 return $out;
80 }
81 else
82 {
83 0 my $random_max = $max * 2;
84 0 my $r = $self->random(0, $random_max, "Inside dice, from random_around_zero");
85 0 $r = $r - $max;
86 0 $r = $r / $divider;
87 0 $self->write_log($message, $r, 0);
88 0 return $r;
89 }
90 }
91 sub shuffle_array
92 {
93 0 ▶ my $self = shift;
Subroutine shuffle_array: not called CC=7 SCAR=40.3
Pod undocumented
94 0 ▶ my $message = shift || "NO MESSAGE IN SHUFFLE";
Condition0%0/2
shift() || 'NO MESSAGE IN SHUFFLE'
l!l
00
MC/DC0%0/1
shift() || 'NO MESSAGE IN SHUFFLE'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
95 0 my @array = @_;
96 0 ▶ if($message =~ /^Choosing advisor for (.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($message =~ /^Choosing advisor for (.*)$/) 0 0 0
97 {
98 0 my $nation = $1;
99 0 my @array_back;
100 0 my $tricked = 0;
101 0 ▶ if($self->forced_advisor())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->forced_advisor) { } 0 0 0
102 {
103 0 @array_back = ( $self->forced_advisor() );
104 0 $tricked = 1;
105 }
106 else
107 {
108 0 @array_back = shuffle @array;
109 }
110 0 ▶ if($self->only_one_nation_acting)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->only_one_nation_acting) 0 0 0
111 {
112 0 ▶ if($self->only_one_nation_acting ne $nation)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->only_one_nation_acting ne $nation) 0 0 0
113 {
114 0 @array_back = ("Noone");
115 0 $tricked = 1;
116 }
117 }
118 0 $self->write_log($message, "<<array>>, first result: " . $array_back[0], $tricked);
119 return @array_back
120 0 }
121  
122 0 ▶ if(@array == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@array == 0) 0 0 0
123 {
124 0 $self->write_log($message, "<<array>>, Array empty");
125 0 return @array;
126 }
127 0 @array = shuffle @array;
128 0 $self->write_log($message, "<<array>>, first result: " . $array[0]);
129 0 return @array;
130 }
131 sub tricked
132 {
133 0 ▶ my $self = shift;
Subroutine tricked: not called CC=4 SCAR=30.0
Pod undocumented
134 0 my $message = shift;
135 0 ▶ if(exists $self->tricks->{$message})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->tricks->{$message}) { } 0 0 0
136 {
137 0 my $index;
138 0 ▶ if(exists $self->trick_counters->{$message})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->trick_counters->{$message}) { } 0 0 0
139 {
140 0 $index = $self->trick_counters->{$message};
141 }
142 else
143 {
144 0 $index = 0;
145 }
146 0 my $result;
147 0 ▶ if(exists $self->tricks->{$message}->[$index])
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->tricks->{$message}[$index]) { } 0 0 0
148 {
149 0 $result = $self->tricks->{$message}->[$index];
150 }
151 else
152 {
153 0 $result = undef;
154 }
155 0 $self->trick_counters->{$message} = $index + 1;
156 0 return $result;
157 }
158 else
159 {
160 0 return undef;
161 }
162 }
163  
164 sub write_log
165 {
166 0 ▶ my $self = shift;
Subroutine write_log: not called CC=2 SCAR=17.9
Pod undocumented
167 0 my $message = shift;
168 0 my $result = shift;
169 0 my $tricked = shift;
170 0 ▶ if($tricked)
Branch: 1 branch
BranchTrueFalseTotal
if ($tricked) 0 0 0
171 {
172 0 $message .= " *TRICKED* ";
173 }
174 0 $message = "[" . $message . "] $result";
175 0 $self->log($message);
176 }
177  
178 11 1;
« lib/BalanceOfPower/Relations/War.pm ↑ Summary lib/BalanceOfPower/Relations/RelPack.pm »