blib/lib/Game/Go/Result.pm

filter: Statementstmt 100% 54 / 54 Branchbran 58.3% 14 / 24 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 12 / 12 Podpod 83.3% 5 / 6 totaltotal 82.8% 92 / 111 CC 16 SCAR 13.8
CC
16
Cov
84%
stringify
7.5
margin
4.5
BUILD
4.1
CRAP 4.0
« blib/lib/Game/Go/Bot.pm ↑ Summary blib/lib/Game/Go/Scoring.pm »
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
BranchTrueFalseTotal
unless defined $r and grep {$_ eq $r;} @Game::Go::Result::RESULTS 1 30 31
defined $r ? : 1 0 1
Condition66%2/3
defined $r and grep {$_ eq $r;} @Game::Go::Result::RESULTS
!ll&&!rl&&r
0130
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$_[0]->result eq 'score' ? : 8 0 8
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
BranchTrueFalseTotal
unless $self->scored 0 7 7
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
BranchTrueFalseTotal
unless defined $b and defined $w 0 7 7
Condition33%1/3
defined $b and defined $w
!ll&&!rl&&r
007
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $self->winner 0 1 1
54 1 ▶ return $self->winner == $B ? { $B => 1, $W => 2 } : { $B => 2, $W => 1 };
Branch: 1 branch
BranchTrueFalseTotal
$self->winner == $B ? : 1 0 1
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
BranchTrueFalseTotal
unless defined $self->winner 0 4 4
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
BranchTrueFalseTotal
if $r eq "resign" 0 4 4
65 4 ▶ return "$who wins on time" if $r eq 'timeout';
Branch: 1 branch
BranchTrueFalseTotal
if $r eq "timeout" 0 4 4
66  
67 4 my $by = $self->margin;
68 4 ▶ return "$who wins" unless defined $by;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $by 0 4 4
69 4 ▶ my $how = $self->scored_by && $self->scored_by eq 'area'
Branch: 1 branch
BranchTrueFalseTotal
$self->scored_by && $self->scored_by eq 'area' ? : 1 3 4
Condition66%2/3
$self->scored_by and $self->scored_by eq "area"
!ll&&!rl&&r
031
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"
ABresult
0X0
100
111
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__
« blib/lib/Game/Go/Bot.pm ↑ Summary blib/lib/Game/Go/Scoring.pm »