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 29 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 our $VERSION = '0.04';
8  
9 29 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 EMPTY => 0,
11 BLACK => 1,
12 WHITE => 2,
13 BORDER => 3,
14 29 };
15  
16 29 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
17 29 MIN_SIZE => 2,
18 MAX_SIZE => 19,
19 29 };
20  
21 29 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
22 29 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 29 };
30  
31 30 our @SIZES;
32 29 ▶BEGIN { @SIZES = (9, 13, 19) }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 29 ▶use constant DEFAULT_KOMI => 6.5;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 29 ▶use constant HANDICAP_KOMI => 0.5;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 29 ▶use constant MAX_HANDICAP => 9;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 30 our %STARS;
41 29 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
42 29 %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 30 our %HANDICAP;
51 29 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
52 29 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 29 %HANDICAP = (
64 19 => [@big],
65 13 => [ @big[0 .. 5] ],
66 9 => [ @big[0 .. 5] ],
67 );
68 }
69  
70 739 ▶sub max_handicap {
Subroutine max_handicap: called CC=2 SCAR=7.0
Pod documented
71 739 my $size = $_[-1];
72 739 ▶ return 0 unless $HANDICAP{$size};
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Go::Rules::HANDICAP{$size} 0 739 739
73 739 return $#{ $HANDICAP{$size} };
74 }
75  
76 65 ▶sub handicap_points {
Subroutine handicap_points: called CC=5 SCAR=18.9
Pod documented
77 65 my ($size, $n) = @_[-2, -1];
78 65 ▶ 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 65 65
Condition33%2/6
$Game::Go::Rules::HANDICAP{$size} and $n and $n <= max_handicap($size)
!ll&&!rl&&r
0065
$Game::Go::Rules::HANDICAP{$size} and $n
!ll&&!rl&&r
0065
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 65 ▶ my $labels = $HANDICAP{$size}[$n] || [];
Condition50%1/2
$Game::Go::Rules::HANDICAP{$size}[$n] || []
l!l
650
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 65 return [ map { $STARS{$size}{$_} } @$labels ];
81 }
82  
83 436 ▶sub star_points {
Subroutine star_points: called CC=2 SCAR=7.0
Pod documented
84 436 my $size = $_[-1];
85 436 ▶ return [] unless $STARS{$size};
Branch: 1 branch
BranchTrueFalseTotal
unless $Game::Go::Rules::STARS{$size} 0 436 436
86 436 return [ map { $STARS{$size}{$_} } sort keys %{ $STARS{$size} } ];
87 }
88  
89 30 our %REFUSAL;
90 30 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
91 30 %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 1007 ▶sub sizes { @SIZES }
Subroutine sizes: called CC=1 SCAR=0.0
Pod documented
103 24 ▶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 5908 ▶sub other { $_[-1] == BLACK ? WHITE : BLACK }
Subroutine other: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[-1] == 1 ? : 3058 2850 5908
107  
108 68729 ▶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 68728 1 68729
Condition100%6/6
defined $_[-1] && ($_[-1] == 1 || $_[-1] == 2)
!ll&&!rl&&r
116268566
$_[-1] == 1 or $_[-1] == 2
l!l&&r!l&&!r
2831540251162
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 325 ▶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 ? : 35 290 325
$_[-1] == 2 ? : 290 0 290
111  
112 8113 ▶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 8113 8113
$_[-1] == 1 ? : 4439 3674 8113
$_[-1] == 2 ? : 3674 0 3674
113  
114 13671 ▶sub from_letter {
Subroutine from_letter: called CC=4 SCAR=13.9
Pod documented
115 13671 my $l = $_[-1];
116 13671 ▶ return undef unless defined $l;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $l 0 13671 13671
117 13671 ▶ return BLACK if $l eq 'b';
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "b" 3705 9966 13671
118 9966 ▶ return WHITE if $l eq 'w';
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "w" 9960 6 9966
119 6 return undef;
120 }
121  
122 30 1;
123  
124 __END__
« blib/lib/Game/Go/Engine.pm ↑ Summary blib/arch/Game/Go/Install/Files.pm »