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 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 our $VERSION = '0.03';
7  
8 24 ▶use constant HOUSES => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use constant CELLS => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use constant SEEDS => 48;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use constant PER_HOUSE => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 24 ▶use constant P1_STORE => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use constant P2_STORE => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 82 ▶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 1670068 ▶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' ? : 837558 832510 1670068
27  
28 469151 ▶sub store_of {
Subroutine store_of: called CC=4 SCAR=14.2
Pod documented
29 469151 my ($class, $seat) = @_;
30 469151 ▶ die "Game::Oware::Board: there is no seat '$seat'"
Branch: 1 branch
BranchTrueFalseTotal
unless $seat eq "p1" or $seat eq "p2" 0 469151 469151
Condition66%2/3
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
2318322373190
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 469151 ▶ return $seat eq 'p1' ? P1_STORE : P2_STORE;
Branch: 1 branch
BranchTrueFalseTotal
$seat eq 'p1' ? : 231832 237319 469151
33 }
34  
35 1096710 ▶sub owner_of {
Subroutine owner_of: called CC=2 SCAR=6.9
Pod documented
36 1096710 my ($class, $house) = @_;
37 1096710 $class->assert_house($house);
38 1096708 ▶ return $house < 6 ? 'p1' : 'p2';
Branch: 1 branch
BranchTrueFalseTotal
$house < 6 ? : 547720 548988 1096708
39 }
40  
41 1303584 ▶sub houses_of {
Subroutine houses_of: called CC=4 SCAR=14.2
Pod documented
42 1303584 my ($class, $seat) = @_;
43 1303584 ▶ die "Game::Oware::Board: there is no seat '$seat'"
Branch: 1 branch
BranchTrueFalseTotal
unless $seat eq "p1" or $seat eq "p2" 0 1303584 1303584
Condition66%2/3
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
6538876496970
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 1303584 ▶ return $seat eq 'p1' ? (0 .. 5) : (6 .. 11);
Branch: 1 branch
BranchTrueFalseTotal
$seat eq 'p1' ? : 653887 649697 1303584
46 }
47  
48 686751 ▶sub seeds_on_side {
Subroutine seeds_on_side: called CC=2 SCAR=6.9
Pod documented
49 686751 my ($class, $board, $seat) = @_;
50 686751 my $seeds = 0;
51 686751 $seeds += $board->[$_] for $class->houses_of($seat);
52 686751 return $seeds;
53 }
54  
55 2984563 ▶sub assert_house {
Subroutine assert_house: called CC=4 SCAR=13.9
Pod documented
56 2984563 my ($class, $house) = @_;
57 2984563 ▶ 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 2984555 2984563
Condition83%5/6
defined $house and $house =~ /\A\d+\z/ and $house < 12
!ll&&!rl&&r
262984555
defined $house and $house =~ /\A\d+\z/
!ll&&!rl&&r
022984561
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 2984555 return $house;
60 }
61  
62 469236 ▶sub sow {
Subroutine sow: called CC=4 SCAR=13.9
Pod documented
63 469236 my ($class, $board, $house) = @_;
64 469236 $class->assert_house($house);
65  
66 469234 my $hand = $board->[$house];
67 469234 ▶ die "Game::Oware::Board: house $house is empty, so there is nothing to sow"
Branch: 1 branch
BranchTrueFalseTotal
unless $hand 1 469233 469234
68 unless $hand;
69  
70 469233 my $next = [ @$board ];
71 469233 $next->[$house] = 0;
72  
73 469233 my $i = $house;
74 469233 my $last = $house;
75 469233 ▶ while ($hand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hand) 1827860 469233 2297093
76 1827860 $i = ($i + 1) % HOUSES;
77 1827860 ▶ next if $i == $house;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $house 4281 1823579 1827860
78 1823579 $next->[$i]++;
79 1823579 $last = $i;
80 1823579 $hand--;
81 }
82  
83 469233 return ($next, $last, $board->[$house]);
84 }
85  
86 469234 ▶sub capture_chain {
Subroutine capture_chain: called CC=5 SCAR=16.1
Pod documented
87 469234 my ($class, $board, $last, $sown, $seat) = @_;
88 469234 $class->assert_house($last);
89  
90 469233 my $foe = $class->other($seat);
91  
92 469233 my @chain;
93 469233 my $i = $last;
94 469233 ▶ while (@chain < $sown) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chain < $sown) 543501 7120 550621
95 543501 ▶ last unless $class->owner_of($i) eq $foe;
Branch: 1 branch
BranchTrueFalseTotal
unless $class->owner_of($i) eq $foe 230780 312721 543501
96  
97 312721 my $count = $board->[$i];
98 312721 ▶ last unless $count == 2 || $count == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless $count == 2 or $count == 3 231333 81388 312721
Condition100%3/3
$count == 2 or $count == 3
l!l&&r!l&&!r
5241128977231333
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 81388 push @chain, $i;
101 81388 $i = ($i - 1) % HOUSES;
102 }
103  
104 469233 return @chain;
105 }
106  
107 24 1;
108  
109 __END__
« blib/lib/Game/Oware/Rules.pm ↑ Summary blib/lib/Game/Oware/Error.pm »