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 29 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 29 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 29 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 29 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 29 ▶use Game::Go::Rules;
Subroutine __ANON__: called CC=1 SCAR=0.0
10  
11 29 our $VERSION = '0.04';
12  
13 29 our @KINDS;
14 29 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
15 29 @KINDS = qw(
16 play pass handicap resign
17 mark unmark seki unseki done accept dispute
18 );
19 }
20  
21 29 our %WANTS_POINT;
22 29 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 29 %WANTS_POINT = map { $_ => 1 } qw(play handicap mark unmark seki unseki);
24 }
25  
26 29 has kind => (is => 'ro', isa => Str);
27 29 has colour => (is => 'ro');
28 29 has point => (is => 'ro');
29 29 has caps => (is => 'ro', isa => ArrayRef, default => []);
30  
31 59863 ▶sub BUILD {
Subroutine BUILD: called CC=11 SCAR=24.0
Pod undocumented
32 59863 my ($self) = @_;
33 59863 my $kind = $self->kind;
34  
35 die "Game::Go::Move: no such kind '" . (defined $kind ? $kind : '(undef)') . "'"
36 59863 ▶ unless defined $kind && grep { $_ eq $kind } @KINDS;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $kind and grep {$_ eq $kind;} @Game::Go::Move::KINDS 1 59862 59863
defined $kind ? : 1 0 1
Condition66%2/3
defined $kind and grep {$_ eq $kind;} @Game::Go::Move::KINDS
!ll&&!rl&&r
0159862
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 59862 ▶ if !$WANTS_POINT{$kind} && defined $self->point;
Branch: 1 branch
BranchTrueFalseTotal
if not $Game::Go::Move::WANTS_POINT{$kind} and defined $self->point 1 59861 59862
Condition100%3/3
not $Game::Go::Move::WANTS_POINT{$kind} and defined $self->point
!ll&&!rl&&r
5769421671
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 59861 ▶ if $WANTS_POINT{$kind} && !defined $self->point;
Branch: 1 branch
BranchTrueFalseTotal
if $Game::Go::Move::WANTS_POINT{$kind} and not defined $self->point 1 59860 59861
Condition100%3/3
$Game::Go::Move::WANTS_POINT{$kind} and not defined $self->point
!ll&&!rl&&r
2167576931
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 59860 ▶ if $kind ne 'play' && @{ $self->caps };
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "play" and @{$self->caps;} 1 59859 59860
Condition100%3/3
$kind ne "play" and @{$self->caps;}
!ll&&!rl&&r
5729125681
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 59859 ▶ die "Game::Go::Move: a move needs a colour"
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Go::Rules::is_colour($self->colour) 1 59858 59859
47 unless Game::Go::Rules::is_colour($self->colour);
48  
49 59858 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 308 ▶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 29 1;
70  
71 __END__
« blib/lib/Game/Go/Notation.pm ↑ Summary blib/lib/Game/Go/Bot.pm »