| 1 | package Game::Go::Result; | ||||||||||||||||||||||||||||||||
| 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 @RESULTS; | |||||||||||||||||||||||||||||||
| 14 | 25 | ▶ | BEGIN { @RESULTS = qw(score resign timeout abandoned) } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 25 | has winner => (is => 'ro'); | |||||||||||||||||||||||||||||||
| 17 | 25 | has result => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 25 | has scored_by => (is => 'ro'); | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 25 | has scores => (is => 'ro', isa => HashRef, default => {}); | |||||||||||||||||||||||||||||||
| 22 | 25 | has territory => (is => 'ro', isa => HashRef, default => {}); | |||||||||||||||||||||||||||||||
| 23 | 25 | has prisoners => (is => 'ro', isa => HashRef, default => {}); | |||||||||||||||||||||||||||||||
| 24 | 25 | has area => (is => 'ro', isa => HashRef, default => {}); | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 25 | has komi => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||
| 27 | 25 | has dame => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 31 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 30 | 31 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 31 | 31 | my $r = $self->result; | |||||||||||||||||||||||||||||||
| 32 | die "Game::Go::Result: no such result '" . (defined $r ? $r : '(undef)') . "'" | ||||||||||||||||||||||||||||||||
| 33 | 31 | ▶ | unless defined $r && grep { $_ eq $r } @RESULTS; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $r and grep {$_ eq $r;} @Game::Go::Result::RESULTS
MC/DC50%1/2
defined $r and grep {$_ eq $r;} @Game::Go::Result::RESULTS
defined $r
grep {$_ eq $r;} @Game::Go::Result::RESULTS
Truth table66%2/3
A and B
A= defined $rB= grep {$_ eq $r;} @Game::Go::Result::RESULTS
| |||||||||||||||||||||||||||||||||
| 34 | 30 | return; | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub results { @RESULTS } | ||||||||||||||||||||||||||||||
|
Subroutine
results: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | sub scored { $_[0]->result eq 'score' ? 1 : 0 } | ||||||||||||||||||||||||||||||
|
Subroutine
scored: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | sub margin { | ||||||||||||||||||||||||||||||
|
Subroutine
margin: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 43 | 7 | ▶ | return undef unless $self->scored; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 7 | my $b = $self->scores->{ Game::Go::Rules::BLACK }; | |||||||||||||||||||||||||||||||
| 45 | 7 | my $w = $self->scores->{ Game::Go::Rules::WHITE }; | |||||||||||||||||||||||||||||||
| 46 | 7 | ▶ | return undef unless defined $b && defined $w; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $b and defined $w
MC/DC0%0/2
defined $b and defined $w
defined $b
defined $w
Truth table33%1/3
A and B
A= defined $bB= defined $w
| |||||||||||||||||||||||||||||||||
| 47 | 7 | return abs($b - $w); | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub places { | ||||||||||||||||||||||||||||||
|
Subroutine
places: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 51 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 52 | 1 | my ($B, $W) = (Game::Go::Rules::BLACK, Game::Go::Rules::WHITE); | |||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | return { $B => 1, $W => 1 } unless defined $self->winner; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | return $self->winner == $B ? { $B => 1, $W => 2 } : { $B => 2, $W => 1 }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 58 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 59 | 4 | my $r = $self->result; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | return 'the game was abandoned' unless defined $self->winner; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 4 | my $who = ucfirst Game::Go::Rules::colour_name($self->winner); | |||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | return "$who wins by resignation" if $r eq 'resign'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | return "$who wins on time" if $r eq 'timeout'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 4 | my $by = $self->margin; | |||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | return "$who wins" unless defined $by; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | my $how = $self->scored_by && $self->scored_by eq 'area' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->scored_by and $self->scored_by eq "area"
MC/DC50%1/2
$self->scored_by and $self->scored_by eq "area"
$self->scored_by
$self->scored_by eq "area"
Truth table66%2/3
A and B
A= $self->scored_byB= $self->scored_by eq "area"
| |||||||||||||||||||||||||||||||||
| 70 | ? ' (scored by area, the players did not agree)' : ''; | ||||||||||||||||||||||||||||||||
| 71 | 4 | return "$who wins by $by$how"; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 25 | 1; | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||||||