blib/lib/Game/Theory/TwoPersonMatrix.pm

filter: Statementstmt 100% 247 / 247 Branchbran 94.0% 47 / 50 Conditioncond 72.7% 24 / 33 MC/DCmcdc 52.3% 11 / 21 Subroutinesub 100% 26 / 26 Podpod 100% 12 / 12 totaltotal 94.3% 367 / 389 CC 65 SCAR 17.5
CC
65
Cov
96%
pareto_optimal
10.0
mm_tally
9.0
s_expected_payoff
7.0
CRAP 5.7
↑ Summary
1 package Game::Theory::TwoPersonMatrix;
2 2 our $AUTHORITY = 'cpan:GENE';
3  
4 # ABSTRACT: Analyze a 2 person matrix game
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.2207';
10  
11 2 ▶use Carp qw( carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Algorithm::Combinatorics qw( permutations );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Array::Transpose qw( transpose );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use List::SomeUtils qw( all zip );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use List::Util qw( max min sum0 );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use List::Util::WeightedChoice qw( choose_weighted );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19  
20 38 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
21 38 my $class = shift;
22 38 my %args = @_;
23 my $self = {
24 1 => $args{1},
25 2 => $args{2},
26 payoff => $args{payoff},
27 payoff1 => $args{payoff1},
28 payoff2 => $args{payoff2},
29 38 };
30 38 bless $self, $class;
31 38 return $self;
32 }
33  
34  
35 sub expected_payoff
36 13 ▶{
Subroutine expected_payoff: called CC=5 SCAR=16.1
Pod documented
37 13 my ($self) = @_;
38  
39 13 my $expected_payoff;
40  
41 # For each strategy of player 1...
42 13 for my $i ( sort keys %{ $self->{1} } )
43 {
44 # For each strategy of player 2...
45 29 for my $j ( sort keys %{ $self->{2} } )
46 {
47 # Expected value is the sum of the probabilities of each payoff
48 76 ▶ if ( $self->{payoff1} && $self->{payoff2} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'payoff1'} and $self->{'payoff2'}) { } 8 68 76
Condition66%2/3
$self->{"payoff1"} and $self->{"payoff2"}
!ll&&!rl&&r
6808
MC/DC50%1/2
$self->{"payoff1"} and $self->{"payoff2"}
$self->{"payoff1"} $self->{"payoff2"}
Truth table66%2/3
A and B
A= $self->{"payoff1"}B= $self->{"payoff2"}
ABresult
0X0
100
111
49 {
50 8 $expected_payoff->[0] += $self->{1}{$i} * $self->{2}{$j} * $self->{payoff1}[$i - 1][$j - 1];
51 8 $expected_payoff->[1] += $self->{1}{$i} * $self->{2}{$j} * $self->{payoff2}[$i - 1][$j - 1];
52 }
53 else {
54 68 $expected_payoff += $self->{1}{$i} * $self->{2}{$j} * $self->{payoff}[$i - 1][$j - 1];
55 }
56 }
57 }
58  
59 13 return $expected_payoff;
60 }
61  
62  
63 sub s_expected_payoff
64 4 ▶{
Subroutine s_expected_payoff: called CC=7 SCAR=19.5
Pod documented
65 4 my ($self) = @_;
66  
67 4 my $expected_payoff;
68  
69 # For each strategy of player 1...
70 4 for my $i ( sort keys %{ $self->{1} } )
71 {
72 # For each strategy of player 2...
73 8 for my $j ( sort keys %{ $self->{2} } )
74 {
75 # Expected value is the sum of the probabilities of each payoff
76 16 ▶ if ( $self->{payoff1} && $self->{payoff2} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'payoff1'} and $self->{'payoff2'}) { } 8 8 16
Condition66%2/3
$self->{"payoff1"} and $self->{"payoff2"}
!ll&&!rl&&r
808
MC/DC50%1/2
$self->{"payoff1"} and $self->{"payoff2"}
$self->{"payoff1"} $self->{"payoff2"}
Truth table66%2/3
A and B
A= $self->{"payoff1"}B= $self->{"payoff2"}
ABresult
0X0
100
111
77 {
78 8 $expected_payoff->[0] .= " + $self->{1}{$i} * $self->{2}{$j} * $self->{payoff1}[$i - 1][$j - 1]";
79 8 $expected_payoff->[1] .= " + $self->{1}{$i} * $self->{2}{$j} * $self->{payoff2}[$i - 1][$j - 1]";
80 }
81 else {
82 8 $expected_payoff .= " + $self->{1}{$i} * $self->{2}{$j} * $self->{payoff}[$i - 1][$j - 1]";
83 }
84 }
85 }
86  
87 my $deplus = sub
88 6 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
89 6 my ($string) = @_;
90 6 $string =~ s/^ \+ (.+)$/$1/;
91 6 return $string;
92 4 };
93  
94 4 ▶ if ( $self->{payoff1} && $self->{payoff2} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'payoff1'} and $self->{'payoff2'}) { } 2 2 4
Condition66%2/3
$self->{"payoff1"} and $self->{"payoff2"}
!ll&&!rl&&r
202
MC/DC50%1/2
$self->{"payoff1"} and $self->{"payoff2"}
$self->{"payoff1"} $self->{"payoff2"}
Truth table66%2/3
A and B
A= $self->{"payoff1"}B= $self->{"payoff2"}
ABresult
0X0
100
111
95 {
96 2 $expected_payoff->[0] = $deplus->($expected_payoff->[0]);
97 2 $expected_payoff->[1] = $deplus->($expected_payoff->[1]);
98 }
99 else {
100 2 $expected_payoff = $deplus->($expected_payoff);
101 }
102  
103 4 return $expected_payoff;
104 }
105  
106  
107 sub counter_strategy
108 3 ▶{
Subroutine counter_strategy: called CC=5 SCAR=16.1
Pod documented
109 3 my ( $self, $player ) = @_;
110  
111 3 my $counter_strategy = [];
112 3 my %seen;
113  
114 3 ▶ my $opponent = $player == 1 ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$player == 1 ? : 1 2 3
115  
116 3 my @keys = 1 .. keys %{ $self->{$player} };
117 3 my @pure = ( 1, (0) x ( @keys - 1 ) );
118  
119 3 my $i = permutations( \@pure );
120  
121 3 ▶ while ( my $strategies = $i->next )
Branch: 1 branch
BranchTrueFalseTotal
if (my $strategies = $i->next) 10 3 13
122 {
123 10 ▶ next if $seen{"@$strategies"}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{join $", @$strategies}++ 3 7 10
124  
125 my $g = Game::Theory::TwoPersonMatrix->new(
126 $player => { zip @keys, @$strategies },
127 $opponent => $self->{$opponent},
128 7 ▶ payoff => $self->{payoff} || $self->{"payoff$player"},
Condition66%2/3
$self->{'payoff'} || $$self{"payoff$player"}
l!l&&r!l&&!r
340
MC/DC0%0/2
$self->{'payoff'} || $$self{"payoff$player"}
$self->{'payoff'} $$self{"payoff$player"}
Truth table66%2/3
A || B
A= $self->{'payoff'}B= $$self{"payoff$player"}
ABresult
1X1
011
000
129 );
130  
131 7 push @$counter_strategy, $g->expected_payoff;
132 }
133  
134 3 return $counter_strategy;
135 }
136  
137  
138 sub saddlepoint
139 5 ▶{
Subroutine saddlepoint: called CC=6 SCAR=17.9
Pod documented
140 5 my ($self) = @_;
141  
142 5 my $saddlepoint;
143  
144 5 my $rsize = @{ $self->{payoff} } - 1;
145 5 my $csize = @{ $self->{payoff}[0] } - 1;
146  
147 5 for my $row ( 0 .. $rsize )
148 {
149 # Get the minimum value of the current row
150 14 my $min = min @{ $self->{payoff}[$row] };
151  
152 # Inspect each column given the row
153 14 for my $col ( 0 .. $csize )
154 {
155 # Get the payoff
156 36 my $val = $self->{payoff}[$row][$col];
157  
158 # Is the payoff also the row minimum?
159 36 ▶ if ( $val == $min )
Branch: 1 branch
BranchTrueFalseTotal
if ($val == $min) 16 20 36
160 {
161 # Gather the column values for each row
162 16 my @col;
163 16 for my $r ( 0 .. $rsize )
164 {
165 50 push @col, $self->{payoff}[$r][$col];
166 }
167 # Get the maximum value of the columns
168 16 my $max = max @col;
169  
170 # Is the payoff also the column maximum?
171 16 ▶ if ( $val == $max )
Branch: 1 branch
BranchTrueFalseTotal
if ($val == $max) 5 11 16
172 {
173 5 $saddlepoint->{"$row,$col"} = $val;
174 }
175 }
176 }
177 }
178  
179 5 return $saddlepoint;
180 }
181  
182  
183 sub oddments
184 1 ▶{
Subroutine oddments: called CC=3 SCAR=11.0
Pod documented
185 1 my ($self) = @_;
186  
187 1 my $rsize = @{ $self->{payoff}[0] };
188 1 my $csize = @{ $self->{payoff} };
189 1 ▶ carp 'Payoff matrix must be 2x2' unless $rsize == 2 && $csize == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $rsize == 2 and $csize == 2 0 1 1
Condition33%1/3
$rsize == 2 and $csize == 2
!ll&&!rl&&r
001
MC/DC0%0/2
$rsize == 2 and $csize == 2
$rsize == 2 $csize == 2
Truth table33%1/3
A and B
A= $rsize == 2B= $csize == 2
ABresult
0X0
100
111
190  
191 1 my ( $player, $opponent );
192  
193 1 my $A = $self->{payoff}[0][0];
194 1 my $B = $self->{payoff}[0][1];
195 1 my $C = $self->{payoff}[1][0];
196 1 my $D = $self->{payoff}[1][1];
197  
198 1 my ( $x, $y );
199 1 $x = abs( $D - $C );
200 1 $y = abs( $A - $B );
201 1 my $i = $x / ( $x + $y );
202 1 my $j = $y / ( $x + $y );
203 1 $player = [ $i, $j ];
204  
205 1 $x = abs( $D - $B );
206 1 $y = abs( $A - $C );
207 1 $i = $x / ( $x + $y );
208 1 $j = $y / ( $x + $y );
209 1 $opponent = [ $i, $j ];
210  
211 1 return [ $player, $opponent ];
212 }
213  
214  
215 sub row_reduce
216 2 ▶{
Subroutine row_reduce: called CC=7 SCAR=19.5
Pod documented
217 2 my ($self) = @_;
218  
219 2 my @spliced;
220  
221 2 my $rsize = @{ $self->{payoff} } - 1;
222 2 my $csize = @{ $self->{payoff}[0] } - 1;
223  
224 2 for my $row ( 0 .. $rsize )
225 {
226 #warn "R:$row = @{ $self->{payoff}[$row] }\n";
227 7 for my $r ( 0 .. $rsize )
228 {
229 25 ▶ next if $r == $row;
Branch: 1 branch
BranchTrueFalseTotal
if $r == $row 7 18 25
230 #warn "\tN:$r = @{ $self->{payoff}[$r] }\n";
231 18 my @cmp;
232 18 for my $x ( 0 .. $csize )
233 {
234 54 ▶ push @cmp, ( $self->{payoff}[$row][$x] <= $self->{payoff}[$r][$x] ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'payoff'}[$row][$x] <= $self->{'payoff'}[$r][$x] ? : 30 24 54
235 }
236 #warn "\t\tC:@cmp\n";
237 18 ▶ if ( all { $_ == 1 } @cmp )
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { $_ == 1; } , @cmp)) 3 15 18
238 {
239 3 push @spliced, $row;
240 }
241 }
242 }
243  
244 2 $self->_reduce_game( $self->{payoff}, \@spliced, 1 );
245  
246 2 return $self->{payoff};
247 }
248  
249  
250 sub col_reduce
251 3 ▶{
Subroutine col_reduce: called CC=7 SCAR=19.5
Pod documented
252 3 my ($self) = @_;
253  
254 3 my @spliced;
255  
256 3 my $transposed = transpose( $self->{payoff} );
257  
258 3 my $rsize = @$transposed - 1;
259 3 my $csize = @{ $transposed->[0] } - 1;
260  
261 3 for my $row ( 0 .. $rsize )
262 {
263 #warn "R:$row = @{ $transposed->[$row] }\n";
264 10 for my $r ( 0 .. $rsize )
265 {
266 34 ▶ next if $r == $row;
Branch: 1 branch
BranchTrueFalseTotal
if $r == $row 10 24 34
267 #warn "\tN:$r = @{ $transposed->[$r] }\n";
268 24 my @cmp;
269 24 for my $x ( 0 .. $csize )
270 {
271 72 ▶ push @cmp, ( $transposed->[$row][$x] >= $transposed->[$r][$x] ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$transposed->[$row][$x] >= $transposed->[$r][$x] ? : 38 34 72
272 }
273 #warn "\t\tC:@cmp\n";
274 24 ▶ if ( all { $_ == 1 } @cmp )
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { $_ == 1; } , @cmp)) 3 21 24
275 {
276 3 push @spliced, $row;
277 }
278 }
279 }
280  
281 3 $self->_reduce_game( $transposed, \@spliced, 2 );
282  
283 3 $self->{payoff} = transpose( $transposed );
284  
285 3 return $self->{payoff};
286 }
287  
288 sub _reduce_game
289 5 ▶{
Subroutine _reduce_game: called CC=3 SCAR=11.0
290 5 my ( $self, $payoff, $spliced, $player ) = @_;
291  
292 5 my $seen = 0;
293 5 for my $row ( @$spliced )
294 {
295 6 $row -= $seen++;
296 # Reduce the payoff column
297 6 splice @$payoff, $row, 1;
298 # Eliminate the strategy of the opponent
299 6 ▶ delete $self->{$player}{$row + 1} if exists $self->{$player}{$row + 1};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$player}{$row + 1} 6 0 6
300 }
301 }
302  
303  
304 sub mm_tally
305 2 ▶{
Subroutine mm_tally: called CC=9 SCAR=22.0
Pod documented
306 2 my ($self) = @_;
307  
308 2 my $mm_tally;
309  
310 2 ▶ if ( $self->{payoff1} && $self->{payoff2} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'payoff1'} and $self->{'payoff2'}) { } 1 1 2
Condition66%2/3
$self->{"payoff1"} and $self->{"payoff2"}
!ll&&!rl&&r
101
MC/DC50%1/2
$self->{"payoff1"} and $self->{"payoff2"}
$self->{"payoff1"} $self->{"payoff2"}
Truth table66%2/3
A and B
A= $self->{"payoff1"}B= $self->{"payoff2"}
ABresult
0X0
100
111
311 {
312 # Find maximum of row minimums for the player
313 1 $mm_tally = $self->_tally_max( $mm_tally, 1, $self->{payoff1} );
314  
315 # Find minimum of column maximums for the opponent
316 1 my @m = ();
317 1 my %s = ();
318  
319 1 my $transposed = transpose( $self->{payoff2} );
320  
321 1 for my $row ( 0 .. @$transposed - 1 )
322 {
323 2 $s{$row} = min @{ $transposed->[$row] };
324 2 push @m, $s{$row};
325 }
326  
327 1 $mm_tally->{2}{value} = max @m;
328  
329 1 for my $row ( sort keys %s )
330 {
331 2 ▶ push @{ $mm_tally->{2}{strategy} }, ( $s{$row} == $mm_tally->{2}{value} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s{$row} == $mm_tally->{'2'}{'value'} ? : 1 1 2
332 }
333 }
334 else
335 {
336 # Find maximum of row minimums
337 1 $mm_tally = $self->_tally_max( $mm_tally, 1, $self->{payoff} );
338  
339 # Find minimum of column maximums
340 1 my @m = ();
341 1 my %s = ();
342  
343 1 my $transposed = transpose( $self->{payoff} );
344  
345 1 for my $row ( 0 .. @$transposed - 1 )
346 {
347 4 $s{$row} = max @{ $transposed->[$row] };
348 4 push @m, $s{$row};
349 }
350  
351 1 $mm_tally->{2}{value} = min @m;
352  
353 1 for my $row ( sort keys %s )
354 {
355 4 ▶ push @{ $mm_tally->{2}{strategy} }, ( $s{$row} == $mm_tally->{2}{value} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s{$row} == $mm_tally->{'2'}{'value'} ? : 2 2 4
356 }
357 }
358  
359 2 return $mm_tally;
360 }
361  
362 sub _tally_max
363 2 ▶{
Subroutine _tally_max: called CC=4 SCAR=13.9
364 2 my ( $self, $mm_tally, $player, $payoff ) = @_;
365  
366 2 my @m;
367 my %s;
368  
369 # Find maximum of row minimums
370 2 for my $row ( 0 .. @$payoff - 1 )
371 {
372 5 $s{$row} = min @{ $payoff->[$row] };
373 5 push @m, $s{$row};
374 }
375  
376 2 $mm_tally->{$player}{value} = max @m;
377  
378 2 for my $row ( sort keys %s )
379 {
380 5 ▶ push @{ $mm_tally->{$player}{strategy} }, ( $s{$row} == $mm_tally->{$player}{value} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s{$row} == $mm_tally->{$player}{'value'} ? : 2 3 5
381 }
382  
383 2 return $mm_tally;
384 }
385  
386  
387 sub pareto_optimal
388 4 ▶{
Subroutine pareto_optimal: called CC=10 SCAR=23.0
Pod documented
389 4 my ($self) = @_;
390  
391 4 my $pareto_optimal;
392  
393 4 my $rsize = @{ $self->{payoff1} } - 1;
394 4 my $csize = @{ $self->{payoff1}[0] } - 1;
395  
396 # Compare each row & column with every other
397 4 for my $row ( 0 .. $rsize )
398 {
399 8 for my $col ( 0 .. $csize )
400 {
401 #warn "RC:$row,$col = ($self->{payoff1}[$row][$col],$self->{payoff2}[$row][$col])\n";
402  
403 # Find all pairs to compare against
404 16 my %seen;
405 16 for my $r ( 0 .. $rsize )
406 {
407 32 for my $c ( 0 .. $csize )
408 {
409 64 ▶ next if ( $r == $row && $c == $col ) || $seen{"$r,$c"}++;
Branch: 1 branch
BranchTrueFalseTotal
if $r == $row and $c == $col or $seen{"$r,$c"}++ 16 48 64
Condition83%5/6
$r == $row and $c == $col or $seen{"$r,$c"}++
l!l&&r!l&&!r
16048
$r == $row and $c == $col
!ll&&!rl&&r
321616
MC/DC66%2/3
$r == $row and $c == $col or $seen{"$r,$c"}++
$r == $row $c == $col $seen{"$r,$c"}++
Truth table60%3/5
A and B or C
A= $r == $rowB= $c == $colC= $seen{"$r,$c"}++
ABCresult
11X1
0X11
1011
0X00
1000
410  
411 48 my $p = $self->{payoff1}[$row][$col];
412 48 my $q = $self->{payoff2}[$row][$col];
413 #warn "\trc:$r,$c = ($self->{payoff1}[$r][$c],$self->{payoff2}[$r][$c])\n";
414  
415 48 ▶ if ( $p >= $self->{payoff1}[$r][$c] && $q >= $self->{payoff2}[$r][$c] )
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= $self->{"payoff1"}[$r][$c] and $q >= $self->{"payoff2"}[$r][$c]) 8 40 48
Condition100%3/3
$p >= $self->{"payoff1"}[$r][$c] and $q >= $self->{"payoff2"}[$r][$c]
!ll&&!rl&&r
23178
MC/DC100%2/2
$p >= $self->{"payoff1"}[$r][$c] and $q >= $self->{"payoff2"}[$r][$c]
$p >= $self->{"payoff1"}[$r][$c] $q >= $self->{"payoff2"}[$r][$c]
Truth table100%3/3
A and B
A= $p >= $self->{"payoff1"}[$r][$c]B= $q >= $self->{"payoff2"}[$r][$c]
ABresult
0X0
100
111
416 {
417 #warn "\t\t$row,$col > $r,$c at ($p,$q)\n";
418 # XXX We exploit the unique key feature of perl hashes
419 8 $pareto_optimal->{ "$row,$col" } = [ $p, $q ];
420 }
421 }
422 }
423 }
424 }
425  
426 4 return $pareto_optimal;
427 }
428  
429  
430 sub nash
431 7 ▶{
Subroutine nash: called CC=6 SCAR=17.9
Pod documented
432 7 my ($self) = @_;
433  
434 7 my $nash;
435  
436 7 my $rsize = @{ $self->{payoff1} } - 1;
437 7 my $csize = @{ $self->{payoff1}[0] } - 1;
438  
439 # Find all row & column max pairs
440 7 for my $row ( 0 .. $rsize )
441 {
442 15 my $rmax = max @{ $self->{payoff2}[$row] };
443  
444 15 for my $col ( 0 .. $csize )
445 {
446 #warn "RC:$row,$col = ($self->{payoff1}[$row][$col],$self->{payoff2}[$row][$col])\n";
447  
448 36 my @col;
449 36 for my $r ( 0 .. $rsize )
450 {
451 84 push @col, $self->{payoff1}[$r][$col];
452 }
453 36 my $cmax = max @col;
454  
455 36 my $p = $self->{payoff1}[$row][$col];
456 36 my $q = $self->{payoff2}[$row][$col];
457  
458 36 ▶ if ( $p == $cmax && $q == $rmax )
Branch: 1 branch
BranchTrueFalseTotal
if ($p == $cmax and $q == $rmax) 10 26 36
Condition100%3/3
$p == $cmax and $q == $rmax
!ll&&!rl&&r
19710
MC/DC100%2/2
$p == $cmax and $q == $rmax
$p == $cmax $q == $rmax
Truth table100%3/3
A and B
A= $p == $cmaxB= $q == $rmax
ABresult
0X0
100
111
459 {
460 #warn "\t$p == $cmax && $q == $rmax\n";
461 10 $nash->{"$row,$col"} = [ $p, $q ];
462 }
463 }
464 }
465  
466 7 return $nash;
467 }
468  
469  
470 sub play
471 4 ▶{
Subroutine play: called CC=4 SCAR=13.9
Pod documented
472 4 my ( $self, %strategies ) = @_;
473  
474 4 my $play;
475  
476 # Allow for alternate strategies
477 4 $self->{$_} = $strategies{$_} for keys %strategies;
478  
479 4 my $rplay = $self->_player_move(1);
480 4 my $cplay = $self->_player_move(2);
481  
482 $play->{ "$rplay,$cplay" } = exists $self->{payoff} && $self->{payoff}
483 ? $self->{payoff}[$rplay - 1][$cplay - 1]
484 4 ▶ : [ $self->{payoff1}[$rplay - 1][$cplay - 1], $self->{payoff2}[$rplay - 1][$cplay - 1] ];
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'payoff'} && $self->{'payoff'} ? : 2 2 4
Condition66%2/3
exists $self->{"payoff"} and $self->{"payoff"}
!ll&&!rl&&r
022
MC/DC50%1/2
exists $self->{"payoff"} and $self->{"payoff"}
exists $self->{"payoff"} $self->{"payoff"}
Truth table66%2/3
A and B
A= exists $self->{"payoff"}B= $self->{"payoff"}
ABresult
0X0
100
111
485  
486 4 return $play;
487 }
488  
489 8 ▶sub _player_move {
Subroutine _player_move: called CC=2 SCAR=7.0
490 8 my ( $self, $player ) = @_;
491  
492 8 my $keys = [ sort keys %{ $self->{$player} } ];
493 8 my $weights = [ map { $self->{$player}{$_} } @$keys ];
494  
495 # Handle the [0, 0, ...] edge case
496 8 ▶ $weights = [ (1) x @$weights ] if 0 == sum0 @$weights;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == &sum0(@$weights) 0 8 8
497  
498 8 return choose_weighted( $keys, $weights );
499 }
500  
501 2 1;
502  
503 __END__
↑ Summary