blib/lib/Game/Oware/Board.pm

filter: Statementstmt 97.4% 76 / 78 Branchbran 92.3% 24 / 26 Conditioncond 80.0% 12 / 15 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 94.7% 18 / 19 Podpod 100% 11 / 11 totaltotal 91.7% 145 / 158 CC 21 SCAR 11.0
CC
21
Cov
94%
capture_chain
5.0
store_of
4.1
houses_of
4.1
CRAP 3.0
« blib/lib/Game/Oware/Rules.pm ↑ Summary blib/lib/Game/Oware/Error.pm »
1 package Game::Oware::Board;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 27 our $VERSION = '0.04';
7  
8 27 ▶use constant HOUSES => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use constant CELLS => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use constant SEEDS => 48;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use constant PER_HOUSE => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use constant P1_STORE => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use constant P2_STORE => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 616 ▶sub opening { return [ (PER_HOUSE) x HOUSES, 0, 0 ] }
Subroutine opening: called CC=1 SCAR=0.0
Pod documented
16  
17 0 ▶sub clone { my ($class, $board) = @_; return [ @$board ] }
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
18  
19 122 ▶sub total {
Subroutine total: called CC=2 SCAR=6.9
Pod documented
20 122 my ($class, $board) = @_;
21 122 my $total = 0;
22 122 $total += $_ for @$board;
23 122 return $total;
24 }
25  
26 1889462 ▶sub other { my ($class, $seat) = @_; return $seat eq 'p1' ? 'p2' : 'p1' }
Subroutine other: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$seat eq 'p1' ? : 946977 942485 1889462
27  
28 525303 ▶sub store_of {
Subroutine store_of: called CC=4 SCAR=14.2
Pod documented
29 525303 my ($class, $seat) = @_;
30 525303 ▶ die "Game::Oware::Board: there is no seat '$seat'"
Branch: 1 branch
BranchTrueFalseTotal
unless $seat eq "p1" or $seat eq "p2" 0 525303 525303
Condition66%2/3
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
2595132657900
MC/DC0%0/2
$seat eq "p1" or $seat eq "p2"
$seat eq "p1" $seat eq "p2"
Truth table66%2/3
A or B
A= $seat eq "p1"B= $seat eq "p2"
ABresult
1X1
011
000
31 unless $seat eq 'p1' || $seat eq 'p2';
32 525303 ▶ return $seat eq 'p1' ? P1_STORE : P2_STORE;
Branch: 1 branch
BranchTrueFalseTotal
$seat eq 'p1' ? : 259513 265790 525303
33 }
34  
35 1227058 ▶sub owner_of {
Subroutine owner_of: called CC=2 SCAR=6.9
Pod documented
36 1227058 my ($class, $house) = @_;
37 1227058 $class->assert_house($house);
38 1227056 ▶ return $house < 6 ? 'p1' : 'p2';
Branch: 1 branch
BranchTrueFalseTotal
$house < 6 ? : 611684 615372 1227056
39 }
40  
41 1483099 ▶sub houses_of {
Subroutine houses_of: called CC=4 SCAR=14.2
Pod documented
42 1483099 my ($class, $seat) = @_;
43 1483099 ▶ die "Game::Oware::Board: there is no seat '$seat'"
Branch: 1 branch
BranchTrueFalseTotal
unless $seat eq "p1" or $seat eq "p2" 0 1483099 1483099
Condition66%2/3
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
7438867392130
MC/DC0%0/2
$seat eq "p1" or $seat eq "p2"
$seat eq "p1" $seat eq "p2"
Truth table66%2/3
A or B
A= $seat eq "p1"B= $seat eq "p2"
ABresult
1X1
011
000
44 unless $seat eq 'p1' || $seat eq 'p2';
45 1483099 ▶ return $seat eq 'p1' ? (0 .. 5) : (6 .. 11);
Branch: 1 branch
BranchTrueFalseTotal
$seat eq 'p1' ? : 743886 739213 1483099
46 }
47  
48 784155 ▶sub seeds_on_side {
Subroutine seeds_on_side: called CC=2 SCAR=6.9
Pod documented
49 784155 my ($class, $board, $seat) = @_;
50 784155 my $seeds = 0;
51 784155 $seeds += $board->[$_] for $class->houses_of($seat);
52 784155 return $seeds;
53 }
54  
55 3358939 ▶sub assert_house {
Subroutine assert_house: called CC=4 SCAR=13.9
Pod documented
56 3358939 my ($class, $house) = @_;
57 3358939 ▶ die 'Game::Oware::Board: a house is 0 to 11'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $house and $house =~ /\A\d+\z/ and $house < 12 8 3358931 3358939
Condition83%5/6
defined $house and $house =~ /\A\d+\z/ and $house < 12
!ll&&!rl&&r
263358931
defined $house and $house =~ /\A\d+\z/
!ll&&!rl&&r
023358937
MC/DC66%2/3
defined $house and $house =~ /\A\d+\z/ and $house < 12
defined $house $house =~ /\A\d+\z/ $house < 12
Truth table75%3/4
A and B and C
A= defined $houseB= $house =~ /\A\d+\z/C= $house < 12
ABCresult
0XX0
10X0
1100
1111
58 unless defined $house && $house =~ /\A\d+\z/ && $house < HOUSES;
59 3358931 return $house;
60 }
61  
62 525394 ▶sub sow {
Subroutine sow: called CC=4 SCAR=13.9
Pod documented
63 525394 my ($class, $board, $house) = @_;
64 525394 $class->assert_house($house);
65  
66 525392 my $hand = $board->[$house];
67 525392 ▶ die "Game::Oware::Board: house $house is empty, so there is nothing to sow"
Branch: 1 branch
BranchTrueFalseTotal
unless $hand 1 525391 525392
68 unless $hand;
69  
70 525391 my $next = [ @$board ];
71 525391 $next->[$house] = 0;
72  
73 525391 my $i = $house;
74 525391 my $last = $house;
75 525391 ▶ while ($hand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hand) 2038066 525391 2563457
76 2038066 $i = ($i + 1) % HOUSES;
77 2038066 ▶ next if $i == $house;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $house 4881 2033185 2038066
78 2033185 $next->[$i]++;
79 2033185 $last = $i;
80 2033185 $hand--;
81 }
82  
83 525391 return ($next, $last, $board->[$house]);
84 }
85  
86 525392 ▶sub capture_chain {
Subroutine capture_chain: called CC=5 SCAR=16.1
Pod documented
87 525392 my ($class, $board, $last, $sown, $seat) = @_;
88 525392 $class->assert_house($last);
89  
90 525391 my $foe = $class->other($seat);
91  
92 525391 my @chain;
93 525391 my $i = $last;
94 525391 ▶ while (@chain < $sown) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chain < $sown) 606204 7572 613776
95 606204 ▶ last unless $class->owner_of($i) eq $foe;
Branch: 1 branch
BranchTrueFalseTotal
unless $class->owner_of($i) eq $foe 260803 345401 606204
96  
97 345401 my $count = $board->[$i];
98 345401 ▶ last unless $count == 2 || $count == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless $count == 2 or $count == 3 257016 88385 345401
Condition100%3/3
$count == 2 or $count == 3
l!l&&r!l&&!r
5718931196257016
MC/DC100%2/2
$count == 2 or $count == 3
$count == 2 $count == 3
Truth table100%3/3
A or B
A= $count == 2B= $count == 3
ABresult
1X1
011
000
99  
100 88385 push @chain, $i;
101 88385 $i = ($i - 1) % HOUSES;
102 }
103  
104 525391 return @chain;
105 }
106  
107 27 1;
108  
109 __END__
« blib/lib/Game/Oware/Rules.pm ↑ Summary blib/lib/Game/Oware/Error.pm »