| 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.03'; | |||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $kind and grep {$_ eq $kind;} @Game::Go::Move::KINDS
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
| |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | die "Game::Go::Move: a '$kind' move takes no point" | ||||||||||||||||||||||||||||||||
| 39 | 37266 | ▶ | if !$WANTS_POINT{$kind} && defined $self->point; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $Game::Go::Move::WANTS_POINT{$kind} and defined $self->point
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
| |||||||||||||||||||||||||||||||||
| 40 | die "Game::Go::Move: a '$kind' move needs a point" | ||||||||||||||||||||||||||||||||
| 41 | 37265 | ▶ | if $WANTS_POINT{$kind} && !defined $self->point; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$Game::Go::Move::WANTS_POINT{$kind} and not defined $self->point
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
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | die "Game::Go::Move: only a play captures, not a '$kind'" | ||||||||||||||||||||||||||||||||
| 44 | 37264 | ▶ | if $kind ne 'play' && @{ $self->caps }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$kind ne "play" and @{$self->caps;}
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;}
| |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 37263 | ▶ | die "Game::Go::Move: a move needs a colour" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | return "$who resigns" if $self->kind eq 'resign'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | my $where = defined $self->point ? ' at ' . $self->point : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | my $took = $self->captured ? ', taking ' . $self->captured : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 1 | return $who . ' ' . $self->kind . $where . $took; | |||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 25 | 1; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||