blib/lib/Game/Go/Rules.pm

filter: Statementstmt 98.9% 92 / 93 Branchbran 73.0% 19 / 26 Conditioncond 64.2% 9 / 14 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 97.2% 35 / 36 Podpod 100% 11 / 11 totaltotal 90.3% 169 / 187 CC 18 SCAR 8.6
CC
18
Cov
90%
handicap_points
6.6
letter
4.4
from_letter
4.0
CRAP 2.4
« blib/lib/Game/Go/Engine.pm ↑ Summary blib/arch/Game/Go/Install/Files.pm »
1 package Game::Go::Rules;
2  
3 25 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 26 our $VERSION = '0.02';
8  
9 25 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 EMPTY => 0,
11 BLACK => 1,
12 WHITE => 2,
13 BORDER => 3,
14 25 };
15  
16 25 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
17 25 MIN_SIZE => 2,
18 MAX_SIZE => 19,
19 25 };
20  
21 25 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
22 25 OK => 0,
23 ILL_OFF => 1,
24 ILL_TAKEN => 2,
25 ILL_KO => 3,
26 ILL_SUICIDE => 4,
27 ILL_REPEAT => 5,
28 ILL_COLOUR => 6,
29 25 };
30  
31 26 our @SIZES;
32 25 ▶BEGIN { @SIZES = (9, 13, 19) }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 25 ▶use constant DEFAULT_KOMI => 6.5;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 25 ▶use constant HANDICAP_KOMI => 0.5;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 25 ▶use constant MAX_HANDICAP => 9;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 26 our %STARS;
41 25 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
42 25 %STARS = (
43 19 => { A => [15,3], B => [3,15], C => [15,15], D => [3,3], E => [9,9],
44 F => [3,9], G => [15,9], H => [9,3], I => [9,15] },
45 13 => { A => [9,3], B => [3,9], C => [9,9], D => [3,3], E => [6,6] },
46 9 => { A => [6,2], B => [2,6], C => [6,6], D => [2,2], E => [4,4] },
47 );
48 }
49  
50 26 our %HANDICAP;
51 25 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
52 25 my @big = (
53 undef, [],
54 [qw(A B)],
55 [qw(A B C)],
56 [qw(A B C D)],
57 [qw(A B C D E)],
58 [qw(A B C D F G)],
59 [qw(A B C D E F G)],
60 [qw(A B C D F G H I)],
61 [qw(A B C D E F G H I)],
62 );
63 25 %HANDICAP = (
64 19 => [@big],
65 13 => [ @big[0 .. 5] ],
66 9 => [ @big[0 .. 5] ],
67 );
68 }
69  
70 529 ▶sub max_handicap {
Subroutine max_handicap: called CC=2 SCAR=7.0
Pod documented
71 529 my $size = $_[-1];
72 529 ▶ return 0 unless $HANDICAP{$size};
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Go::Rules::HANDICAP{$size} 0 529 529
73 529 return $#{ $HANDICAP{$size} };
74 }
75  
76 39 ▶sub handicap_points {
Subroutine handicap_points: called CC=5 SCAR=18.9
Pod documented
77 39 my ($size, $n) = @_[-2, -1];
78 39 ▶ return [] unless $HANDICAP{$size} && $n && $n <= max_handicap($size);
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Go::Rules::HANDICAP{$size} and $n and $n <= max_handicap($size) 0 39 39
Condition33%2/6
$Game::Go::Rules::HANDICAP{$size} and $n and $n <= max_handicap($size)
!ll&&!rl&&r
0039
$Game::Go::Rules::HANDICAP{$size} and $n
!ll&&!rl&&r
0039
MC/DC0%0/3
$Game::Go::Rules::HANDICAP{$size} and $n and $n <= max_handicap($size)
$Game::Go::Rules::HANDICAP{$size} $n $n <= max_handicap($size)
Truth table25%1/4
A and B and C
A= $Game::Go::Rules::HANDICAP{$size}B= $nC= $n <= max_handicap($size)
ABCresult
0XX0
10X0
1100
1111
79 39 ▶ my $labels = $HANDICAP{$size}[$n] || [];
Condition50%1/2
$Game::Go::Rules::HANDICAP{$size}[$n] || []
l!l
390
MC/DC0%0/1
$Game::Go::Rules::HANDICAP{$size}[$n] || []
$Game::Go::Rules::HANDICAP{$size}[$n]
Truth table50%1/2
A
A= $Game::Go::Rules::HANDICAP{$size}[$n]
Aresult
11
00
80 39 return [ map { $STARS{$size}{$_} } @$labels ];
81 }
82  
83 181 ▶sub star_points {
Subroutine star_points: called CC=2 SCAR=7.0
Pod documented
84 181 my $size = $_[-1];
85 181 ▶ return [] unless $STARS{$size};
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Go::Rules::STARS{$size} 0 181 181
86 181 return [ map { $STARS{$size}{$_} } sort keys %{ $STARS{$size} } ];
87 }
88  
89 26 our %REFUSAL;
90 26 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
91 26 %REFUSAL = (
92 0 => 'that move is legal',
93 1 => 'that point is not on the board',
94 2 => 'there is already a stone there',
95 3 => 'the ko rule forbids retaking that point immediately',
96 4 => 'that move would leave your own stones with no liberty',
97 5 => 'that move would repeat a position the game has already had',
98 6 => 'that is not a colour',
99 );
100 }
101  
102 521 ▶sub sizes { @SIZES }
Subroutine sizes: called CC=1 SCAR=0.0
Pod documented
103 23 ▶sub refusal { $REFUSAL{ $_[-1] } }
Subroutine refusal: called CC=1 SCAR=0.0
Pod documented
104 0 ▶sub refusals { return { %REFUSAL } }
Subroutine refusals: not called CC=1 SCAR=6.9
Pod documented
105  
106 3756 ▶sub other { $_[-1] == BLACK ? WHITE : BLACK }
Subroutine other: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[-1] == 1 ? : 1942 1814 3756
107  
108 43011 ▶sub is_colour { defined $_[-1] && ($_[-1] == BLACK || $_[-1] == WHITE) }
Subroutine is_colour: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[-1] and $_[-1] == 1 || $_[-1] == 2 43010 1 43011
Condition100%6/6
defined $_[-1] && ($_[-1] == 1 || $_[-1] == 2)
!ll&&!rl&&r
116242848
$_[-1] == 1 or $_[-1] == 2
l!l&&r!l&&!r
2073422114162
MC/DC100%3/3
defined $_[-1] && ($_[-1] == 1 || $_[-1] == 2)
defined $_[-1] $_[-1] == 1 $_[-1] == 2
Truth table100%4/4
A && B or C
A= defined $_[-1]B= $_[-1] == 1C= $_[-1] == 2
ABCresult
0XX0
1000
11X1
1011
109  
110 147 ▶sub colour_name { $_[-1] == BLACK ? 'black' : $_[-1] == WHITE ? 'white' : 'nobody' }
Subroutine colour_name: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[-1] == 1 ? : 18 129 147
$_[-1] == 2 ? : 129 0 129
111  
112 5292 ▶sub letter { !defined $_[-1] ? undef : $_[-1] == BLACK ? 'b' : $_[-1] == WHITE ? 'w' : undef }
Subroutine letter: called CC=4 SCAR=14.8
Pod documented
Branch: 3 branches
BranchTrueFalseTotal
!defined($_[-1]) ? : 0 5292 5292
$_[-1] == 1 ? : 2976 2316 5292
$_[-1] == 2 ? : 2316 0 2316
113  
114 7213 ▶sub from_letter {
Subroutine from_letter: called CC=4 SCAR=13.9
Pod documented
115 7213 my $l = $_[-1];
116 7213 ▶ return undef unless defined $l;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $l 0 7213 7213
117 7213 ▶ return BLACK if $l eq 'b';
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "b" 1898 5315 7213
118 5315 ▶ return WHITE if $l eq 'w';
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "w" 5309 6 5315
119 6 return undef;
120 }
121  
122 26 1;
123  
124 __END__
« blib/lib/Game/Go/Engine.pm ↑ Summary blib/arch/Game/Go/Install/Files.pm »