blib/lib/Game/Merrills/Board.pm

filter: Statementstmt 100% 76 / 76 Branchbran 100% 28 / 28 Conditioncond 94.4% 17 / 18 MC/DCmcdc 90.9% 10 / 11 Subroutinesub 100% 21 / 21 Podpod 91.6% 11 / 12 totaltotal 98.1% 163 / 166 CC 24 SCAR 17.3
CC
24
Cov
99%
BUILD
13.0
in_mill
6.0
_value
4.0
CRAP 5.6
« blib/lib/Game/Merrills.pm ↑ Summary blib/lib/Game/Merrills/Move.pm »
1 package Game::Merrills::Board;
2  
3 85 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 85 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 85 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7 85 ▶use Game::Merrills::Points;
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 85 our $VERSION = '0.01';
10  
11 85 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
12 85 EMPTY => 0,
13 WHITE => 1,
14 BLACK => -1,
15 MEN => 9,
16 85 };
17  
18 85 our (%VALUE, %SIDE);
19  
20 85 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
21 85 %VALUE = (white => WHITE, black => BLACK);
22 85 %SIDE = (WHITE, 'white', BLACK, 'black');
23 }
24  
25 has cells => (
26 is => 'rw',
27 isa => ArrayRef,
28 475 ▶ default => sub { opening() }
Subroutine __ANON__: called CC=1 SCAR=0.0
29 85 );
30  
31 has hand => (
32 is => 'rw',
33 isa => HashRef,
34 282 ▶ default => sub { { white => MEN, black => MEN } }
Subroutine __ANON__: called CC=1 SCAR=0.0
35 85 );
36  
37 5622 ▶sub BUILD {
Subroutine BUILD: called CC=13 SCAR=25.7
Pod undocumented
38 5622 my ($self) = @_;
39 5622 my $cells = $self->cells;
40 die 'cells must be an arrayref of 24 values'
41 5622 ▶ unless ref $cells eq 'ARRAY' && @{$cells} == Game::Merrills::Points::POINTS;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cells eq "ARRAY" and @{$cells;} == 24 1 5621 5622
Condition66%2/3
ref $cells eq "ARRAY" and @{$cells;} == 24
!ll&&!rl&&r
015621
MC/DC50%1/2
ref $cells eq "ARRAY" and @{$cells;} == 24
ref $cells eq "ARRAY" @{$cells;} == 24
Truth table66%2/3
A and B
A= ref $cells eq "ARRAY"B= @{$cells;} == 24
ABresult
0X0
100
111
42 5621 for my $point (Game::Merrills::Points::all_points()) {
43 134904 my $value = $cells->[$point];
44 134904 ▶ die 'cell ' . Game::Merrills::Points::name($point) . ' must be -1, 0 or 1, got '
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value and $value =~ /^(?:-1|0|1)$/ 2 134902 134904
defined $value ? : 1 1 2
Condition100%3/3
defined $value and $value =~ /^(?:-1|0|1)$/
!ll&&!rl&&r
11134902
MC/DC100%2/2
defined $value and $value =~ /^(?:-1|0|1)$/
defined $value $value =~ /^(?:-1|0|1)$/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /^(?:-1|0|1)$/
ABresult
0X0
100
111
45 . (defined $value ? "'$value'" : 'undef')
46 unless defined $value && $value =~ m/^(?:-1|0|1)$/;
47 134902 $cells->[$point] = $value + 0;
48 }
49 5619 my $hand = $self->hand;
50 5619 for my $side (qw/white black/) {
51 11236 my $held = $hand->{$side};
52 11236 ▶ die "hand of $side must be 0 .. 9, got " . (defined $held ? "'$held'" : 'undef')
Branch: 2 branches
BranchTrueFalseTotal
unless defined $held and $held =~ /^[0-9]$/ 2 11234 11236
defined $held ? : 1 1 2
Condition100%3/3
defined $held and $held =~ /^[0-9]$/
!ll&&!rl&&r
1111234
MC/DC100%2/2
defined $held and $held =~ /^[0-9]$/
defined $held $held =~ /^[0-9]$/
Truth table100%3/3
A and B
A= defined $heldB= $held =~ /^[0-9]$/
ABresult
0X0
100
111
53 unless defined $held && $held =~ m/^[0-9]$/;
54 11234 $hand->{$side} = $held + 0;
55 11234 ▶ die "$side has more than nine men"
Branch: 1 branch
BranchTrueFalseTotal
if $self->count($side) + $held > 9 1 11233 11234
56 if $self->count($side) + $held > MEN;
57 }
58 die 'hand must hold white and black and nothing else'
59 5616 ▶ unless keys %{$hand} == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$hand;} == 2 1 5615 5616
60 5615 return $self;
61 }
62  
63 18741 ▶sub _value {
Subroutine _value: called CC=4 SCAR=13.9
64 18741 my ($side) = @_;
65 die 'side must be white or black, got ' . (defined $side ? "'$side'" : 'undef')
66 18741 ▶ unless defined $side && exists $VALUE{$side};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $side and exists $Game::Merrills::Board::VALUE{$side} 9 18732 18741
defined $side ? : 5 4 9
Condition100%3/3
defined $side and exists $Game::Merrills::Board::VALUE{$side}
!ll&&!rl&&r
4518732
MC/DC100%2/2
defined $side and exists $Game::Merrills::Board::VALUE{$side}
defined $side exists $Game::Merrills::Board::VALUE{$side}
Truth table100%3/3
A and B
A= defined $sideB= exists $Game::Merrills::Board::VALUE{$side}
ABresult
0X0
100
111
67 18732 return $VALUE{$side};
68 }
69  
70 481 ▶sub opening {
Subroutine opening: called CC=1 SCAR=0.0
Pod documented
71 481 return [ (EMPTY) x Game::Merrills::Points::POINTS ];
72 }
73  
74 98667 ▶sub at {
Subroutine at: called CC=1 SCAR=0.0
Pod documented
75 98667 return $_[0]->cells->[ Game::Merrills::Points::_check($_[1]) ];
76 }
77  
78 87801 ▶sub side_at {
Subroutine side_at: called CC=2 SCAR=6.9
Pod documented
79 87801 ▶ my $value = $_[0]->at($_[1]) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $value = $_[0]->at($_[1]) or return undef 30123 57677 87800
80 30123 return $SIDE{$value};
81 }
82  
83 685 ▶sub set {
Subroutine set: called CC=2 SCAR=6.9
Pod documented
84 685 my ($self, $point, $side) = @_;
85 685 Game::Merrills::Points::_check($point);
86 684 ▶ $self->cells->[$point] = defined $side ? _value($side) : EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
defined $side ? : 643 41 684
87 683 return $self;
88 }
89  
90 5310 ▶sub empty {
Subroutine empty: called CC=2 SCAR=6.9
Pod documented
91 5310 ▶ return $_[0]->at($_[1]) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->at($_[1]) ? : 3047 2262 5309
92 }
93  
94 11554 ▶sub points_of {
Subroutine points_of: called CC=1 SCAR=0.0
Pod documented
95 11554 my ($self, $side) = @_;
96 11554 my $value = _value($side);
97 11548 my $cells = $self->cells;
98 11548 return grep { $cells->[$_] == $value } Game::Merrills::Points::all_points();
99 }
100  
101 11247 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
102 11247 my ($self, $side) = @_;
103 11247 return scalar(() = $self->points_of($side));
104 }
105  
106 6544 ▶sub in_hand {
Subroutine in_hand: called CC=1 SCAR=0.0
Pod documented
107 6544 my ($self, $side) = @_;
108 6544 _value($side);
109 6542 return $self->hand->{$side};
110 }
111  
112 7 ▶sub men {
Subroutine men: called CC=1 SCAR=0.0
Pod documented
113 7 my ($self, $side) = @_;
114 7 return $self->count($side) + $self->in_hand($side);
115 }
116  
117 5552 ▶sub in_mill {
Subroutine in_mill: called CC=6 SCAR=17.9
Pod documented
118 5552 my ($self, $point) = @_;
119 5552 ▶ my $value = $self->at($point) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $value = $self->at($point) or return 0 5502 49 5551
120 5502 my $cells = $self->cells;
121 5502 for my $mill (@{ $Game::Merrills::Points::MILLS_OF[$point] }) {
122 10508 ▶ return 1 if $cells->[ $mill->[0] ] == $value
Branch: 1 branch
BranchTrueFalseTotal
if $$cells[$mill->[0]] == $value and $$cells[$mill->[1]] == $value and $$cells[$mill->[2]] == $value 844 9664 10508
Condition100%6/6
$$cells[$mill->[0]] == $value and $$cells[$mill->[1]] == $value and $$cells[$mill->[2]] == $value
!ll&&!rl&&r
81251539844
$$cells[$mill->[0]] == $value and $$cells[$mill->[1]] == $value
!ll&&!rl&&r
504730782383
MC/DC100%3/3
$$cells[$mill->[0]] == $value and $$cells[$mill->[1]] == $value and $$cells[$mill->[2]] == $value
$$cells[$mill->[0]] == $value $$cells[$mill->[1]] == $value $$cells[$mill->[2]] == $value
Truth table100%4/4
A and B and C
A= $$cells[$mill->[0]] == $valueB= $$cells[$mill->[1]] == $valueC= $$cells[$mill->[2]] == $value
ABCresult
0XX0
10X0
1100
1111
123 && $cells->[ $mill->[1] ] == $value
124 && $cells->[ $mill->[2] ] == $value;
125 }
126 4658 return 0;
127 }
128  
129 1 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
130 1 my ($self) = @_;
131 return ref($self)->new(
132 1 cells => [ @{ $self->cells } ],
133 1 hand => { %{ $self->hand } }
134 );
135 }
136  
137 85 1;
138  
139 __END__
« blib/lib/Game/Merrills.pm ↑ Summary blib/lib/Game/Merrills/Move.pm »