blib/lib/Game/Go/Move.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 75.0% 15 / 20 Conditioncond 91.6% 11 / 12 MC/DCmcdc 87.5% 7 / 8 Subroutinesub 92.3% 12 / 13 Podpod 83.3% 5 / 6 totaltotal 90.5% 96 / 106 CC 15 SCAR 17.8
CC
15
Cov
91%
BUILD
11.0
stringify
5.5
kinds
2.0
CRAP 5.9
« blib/lib/Game/Go/Notation.pm ↑ Summary blib/lib/Game/Go/Bot.pm »
1 package Game::Go::Move;
2  
3 25 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 25 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 25 ▶use Game::Go::Rules;
Subroutine __ANON__: called CC=1 SCAR=0.0
10  
11 25 our $VERSION = '0.02';
12  
13 25 our @KINDS;
14 25 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
15 25 @KINDS = qw(
16 play pass handicap resign
17 mark unmark seki unseki done accept dispute
18 );
19 }
20  
21 25 our %WANTS_POINT;
22 25 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 25 %WANTS_POINT = map { $_ => 1 } qw(play handicap mark unmark seki unseki);
24 }
25  
26 25 has kind => (is => 'ro', isa => Str);
27 25 has colour => (is => 'ro');
28 25 has point => (is => 'ro');
29 25 has caps => (is => 'ro', isa => ArrayRef, default => []);
30  
31 37267 ▶sub BUILD {
Subroutine BUILD: called CC=11 SCAR=24.0
Pod undocumented
32 37267 my ($self) = @_;
33 37267 my $kind = $self->kind;
34  
35 die "Game::Go::Move: no such kind '" . (defined $kind ? $kind : '(undef)') . "'"
36 37267 ▶ unless defined $kind && grep { $_ eq $kind } @KINDS;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $kind and grep {$_ eq $kind;} @Game::Go::Move::KINDS 1 37266 37267
defined $kind ? : 1 0 1
Condition66%2/3
defined $kind and grep {$_ eq $kind;} @Game::Go::Move::KINDS
!ll&&!rl&&r
0137266
MC/DC50%1/2
defined $kind and grep {$_ eq $kind;} @Game::Go::Move::KINDS
defined $kind grep {$_ eq $kind;} @Game::Go::Move::KINDS
Truth table66%2/3
A and B
A= defined $kindB= grep {$_ eq $kind;} @Game::Go::Move::KINDS
ABresult
0X0
100
111
37  
38 die "Game::Go::Move: a '$kind' move takes no point"
39 37266 ▶ if !$WANTS_POINT{$kind} && defined $self->point;
Branch: 1 branch
BranchTrueFalseTotal
if not $Game::Go::Move::WANTS_POINT{$kind} and defined $self->point 1 37265 37266
Condition100%3/3
not $Game::Go::Move::WANTS_POINT{$kind} and defined $self->point
!ll&&!rl&&r
3594813171
MC/DC100%2/2
not $Game::Go::Move::WANTS_POINT{$kind} and defined $self->point
not $Game::Go::Move::WANTS_POINT{$kind} defined $self->point
Truth table100%3/3
not(A) and B
A= not $Game::Go::Move::WANTS_POINT{$kind}B= defined $self->point
ABresult
0X0
100
111
40 die "Game::Go::Move: a '$kind' move needs a point"
41 37265 ▶ if $WANTS_POINT{$kind} && !defined $self->point;
Branch: 1 branch
BranchTrueFalseTotal
if $Game::Go::Move::WANTS_POINT{$kind} and not defined $self->point 1 37264 37265
Condition100%3/3
$Game::Go::Move::WANTS_POINT{$kind} and not defined $self->point
!ll&&!rl&&r
1317359471
MC/DC100%2/2
$Game::Go::Move::WANTS_POINT{$kind} and not defined $self->point
$Game::Go::Move::WANTS_POINT{$kind} not defined $self->point
Truth table100%3/3
A and not(B)
A= $Game::Go::Move::WANTS_POINT{$kind}B= not defined $self->point
ABresult
0X0
100
111
42  
43 die "Game::Go::Move: only a play captures, not a '$kind'"
44 37264 ▶ if $kind ne 'play' && @{ $self->caps };
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "play" and @{$self->caps;} 1 37263 37264
Condition100%3/3
$kind ne "play" and @{$self->caps;}
!ll&&!rl&&r
3577014931
MC/DC100%2/2
$kind ne "play" and @{$self->caps;}
$kind ne "play" @{$self->caps;}
Truth table100%3/3
A and B
A= $kind ne "play"B= @{$self->caps;}
ABresult
0X0
100
111
45  
46 37263 ▶ die "Game::Go::Move: a move needs a colour"
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Go::Rules::is_colour($self->colour) 1 37262 37263
47 unless Game::Go::Rules::is_colour($self->colour);
48  
49 37262 return;
50 }
51  
52 0 ▶sub kinds { @KINDS }
Subroutine kinds: not called CC=1 SCAR=6.9
Pod documented
53  
54 1 ▶sub is_pass { $_[0]->kind eq 'pass' }
Subroutine is_pass: called CC=1 SCAR=0.0
Pod documented
55 1 ▶sub is_play { $_[0]->kind eq 'play' }
Subroutine is_play: called CC=1 SCAR=0.0
Pod documented
56  
57 139 ▶sub captured { scalar @{ $_[0]->caps } }
Subroutine captured: called CC=1 SCAR=0.0
Pod documented
58  
59 1 ▶sub stringify {
Subroutine stringify: called CC=5 SCAR=17.0
Pod documented
60 1 my ($self) = @_;
61 1 my $who = Game::Go::Rules::colour_name($self->colour);
62 1 ▶ return "$who passes" if $self->kind eq 'pass';
Branch: 1 branch
BranchTrueFalseTotal
if $self->kind eq "pass" 0 1 1
63 1 ▶ return "$who resigns" if $self->kind eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $self->kind eq "resign" 0 1 1
64 1 ▶ my $where = defined $self->point ? ' at ' . $self->point : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->point ? : 1 0 1
65 1 ▶ my $took = $self->captured ? ', taking ' . $self->captured : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->captured ? : 1 0 1
66 1 return $who . ' ' . $self->kind . $where . $took;
67 }
68  
69 25 1;
70  
71 __END__
« blib/lib/Game/Go/Notation.pm ↑ Summary blib/lib/Game/Go/Bot.pm »