blib/lib/Game/Merrills/Points.pm

filter: Statementstmt 100% 69 / 69 Branchbran 100% 8 / 8 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 17 / 17 Podpod 100% 9 / 9 totaltotal 100% 112 / 112 CC 10 SCAR 8.7
CC
10
Cov
100%
_check
5.0
BEGIN
4.0
point
2.0
CRAP 2.4
« blib/lib/Game/Merrills/Move.pm ↑ Summary blib/lib/Game/Merrills/Error.pm »
1 package Game::Merrills::Points;
2  
3 85 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 85 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 86 our $VERSION = '0.01';
7  
8 85 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 85 POINTS => 24,
10 SIZE => 7,
11 85 };
12  
13 86 our (@NAME, %POINT, @ROW, @COL, @ADJACENT, @MILLS, @MILLS_OF);
14  
15 86 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=13.9
16 86 @NAME = qw/
17 a7 d7 g7
18 b6 d6 f6
19 c5 d5 e5
20 a4 b4 c4 e4 f4 g4
21 c3 d3 e3
22 b2 d2 f2
23 a1 d1 g1
24 /;
25  
26 86 @ADJACENT = (
27 [1, 9], [0, 2, 4], [1, 14],
28 [4, 10], [1, 3, 5, 7], [4, 13],
29 [7, 11], [4, 6, 8], [7, 12],
30 [0, 10, 21], [3, 9, 11, 18], [6, 10, 15],
31 [8, 13, 17], [5, 12, 14, 20], [2, 13, 23],
32 [11, 16], [15, 17, 19], [12, 16],
33 [10, 19], [16, 18, 20, 22], [13, 19],
34 [9, 22], [19, 21, 23], [14, 22],
35 );
36  
37 86 @MILLS = (
38 [0, 1, 2], [3, 4, 5], [6, 7, 8],
39 [9, 10, 11], [12, 13, 14],
40 [15, 16, 17], [18, 19, 20], [21, 22, 23],
41 [0, 9, 21], [3, 10, 18], [6, 11, 15],
42 [1, 4, 7], [16, 19, 22],
43 [8, 12, 17], [5, 13, 20], [2, 14, 23],
44 );
45  
46 86 for my $n (0 .. $#NAME) {
47 2064 my ($file, $rank) = $NAME[$n] =~ m/^([a-g])([1-7])$/;
48 2064 $POINT{$NAME[$n]} = $n;
49 2064 $ROW[$n] = SIZE - $rank;
50 2064 $COL[$n] = ord($file) - ord('a');
51 2064 $MILLS_OF[$n] = [];
52 }
53  
54 86 for my $mill (@MILLS) {
55 1376 push @{$MILLS_OF[$_]}, $mill for @{$mill};
56 }
57 }
58  
59 3116030 ▶sub _check {
Subroutine _check: called CC=5 SCAR=16.1
60 3116030 my ($n) = @_;
61 3116030 ▶ die 'point must be 0 .. 23, got ' . (defined $n ? "'$n'" : 'undef')
Branch: 2 branches
BranchTrueFalseTotal
unless defined $n and $n =~ /^[0-9]+$/ and $n < 24 48 3115982 3116030
defined $n ? : 42 6 48
Condition100%6/6
defined $n and $n =~ /^[0-9]+$/ and $n < 24
!ll&&!rl&&r
30183115982
defined $n and $n =~ /^[0-9]+$/
!ll&&!rl&&r
6243116000
MC/DC100%3/3
defined $n and $n =~ /^[0-9]+$/ and $n < 24
defined $n $n =~ /^[0-9]+$/ $n < 24
Truth table100%4/4
A and B and C
A= defined $nB= $n =~ /^[0-9]+$/C= $n < 24
ABCresult
0XX0
10X0
1100
1111
62 unless defined $n && $n =~ m/^[0-9]+$/ && $n < POINTS;
63 3115982 return $n;
64 }
65  
66 63725 ▶sub all_points {
Subroutine all_points: called CC=1 SCAR=0.0
Pod documented
67 63725 return (0 .. POINTS - 1);
68 }
69  
70 44648 ▶sub point {
Subroutine point: called CC=2 SCAR=6.9
Pod documented
71 44648 my ($name) = @_;
72 44648 ▶ return undef unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 44647 44648
73 44647 return $POINT{lc $name};
74 }
75  
76 427548 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
77 427548 my ($n) = @_;
78 427548 _check($n);
79 427540 return $NAME[$n];
80 }
81  
82 159260 ▶sub row_of {
Subroutine row_of: called CC=1 SCAR=0.0
Pod documented
83 159260 my ($n) = @_;
84 159260 _check($n);
85 159254 return $ROW[$n];
86 }
87  
88 159104 ▶sub col_of {
Subroutine col_of: called CC=1 SCAR=0.0
Pod documented
89 159104 my ($n) = @_;
90 159104 _check($n);
91 159098 return $COL[$n];
92 }
93  
94 2013 ▶sub adjacent {
Subroutine adjacent: called CC=1 SCAR=0.0
Pod documented
95 2013 my ($n) = @_;
96 2013 _check($n);
97 2007 return @{$ADJACENT[$n]};
98 }
99  
100 1055 ▶sub is_adjacent {
Subroutine is_adjacent: called CC=2 SCAR=6.9
Pod documented
101 1055 my ($from, $to) = @_;
102 1055 _check($from);
103 1055 _check($to);
104 1049 ▶ return scalar(grep { $_ == $to } @{$ADJACENT[$from]}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar grep({$_ == $to;} @{$Game::Merrills::Points::ADJACENT[$from];}) ? : 141 908 1049
105 }
106  
107 2210 ▶sub mills {
Subroutine mills: called CC=1 SCAR=0.0
Pod documented
108 2210 return map { [@{$_}] } @MILLS;
109 }
110  
111 32 ▶sub mills_of {
Subroutine mills_of: called CC=1 SCAR=0.0
Pod documented
112 32 my ($n) = @_;
113 32 _check($n);
114 26 return map { [@{$_}] } @{$MILLS_OF[$n]};
115 }
116  
117 86 1;
118  
119 __END__
« blib/lib/Game/Merrills/Move.pm ↑ Summary blib/lib/Game/Merrills/Error.pm »