blib/lib/Game/Go/Scoring.pm

filter: Statementstmt 100% 48 / 48 Branchbran 66.6% 12 / 18 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 85.1% 80 / 94 CC 14 SCAR 13.0
CC
14
Cov
86%
score
5.5
stones_played
5.1
agree_under_equivalence
4.0
CRAP 3.7
« blib/lib/Game/Go/Result.pm ↑ Summary blib/lib/Game/Go/Engine.pm »
1 package Game::Go::Scoring;
2  
3 25 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 ▶use Game::Go::Rules;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use Game::Go::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 25 our $VERSION = '0.03';
11  
12 25 my $B = Game::Go::Rules::BLACK;
13 25 my $W = Game::Go::Rules::WHITE;
14  
15 34 ▶sub stones_played {
Subroutine stones_played: called CC=5 SCAR=16.2
Pod documented
16 34 my ($game) = @_;
17 34 my %n = ($B => 0, $W => 0);
18 34 for my $e (@{ $game->log }) {
19 523 ▶ next unless $e->{kind} eq 'play' || $e->{kind} eq 'handicap';
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"kind"} eq "play" or $e->{"kind"} eq "handicap" 38 485 523
Condition66%2/3
$e->{"kind"} eq "play" or $e->{"kind"} eq "handicap"
l!l&&r!l&&!r
485038
MC/DC50%1/2
$e->{"kind"} eq "play" or $e->{"kind"} eq "handicap"
$e->{"kind"} eq "play" $e->{"kind"} eq "handicap"
Truth table66%2/3
A or B
A= $e->{"kind"} eq "play"B= $e->{"kind"} eq "handicap"
ABresult
1X1
011
000
20 485 ▶ my $who = Game::Go::Rules::from_letter($e->{actor}) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $who = Game::Go::Rules::from_letter($e->{"actor"}) or next 485 0 485
21 485 $n{$who}++;
22 }
23 34 return \%n;
24 }
25  
26 52 ▶sub raw { $_[0]->raw_score }
Subroutine raw: called CC=1 SCAR=0.0
Pod documented
27  
28 26 ▶sub score {
Subroutine score: called CC=5 SCAR=17.0
Pod documented
29 26 my ($game, %o) = @_;
30 26 ▶ my $raw = $o{raw} || raw($game);
Condition33%1/3
$o{'raw'} || raw($game)
l!l&&r!l&&!r
0260
MC/DC0%0/2
$o{'raw'} || raw($game)
$o{'raw'} raw($game)
Truth table33%1/3
A || B
A= $o{'raw'}B= raw($game)
ABresult
1X1
011
000
31  
32 26 my $bs = $raw->{score_b} / 10;
33 26 my $ws = $raw->{score_w} / 10;
34  
35 26 ▶ my $winner = $bs > $ws ? $B : $ws > $bs ? $W : undef;
Branch: 2 branches
BranchTrueFalseTotal
$bs > $ws ? : 10 16 26
$ws > $bs ? : 16 0 16
36  
37 return Game::Go::Result->new(
38 winner => $winner,
39 result => 'score',
40 scored_by => $o{scored_by} || 'territory',
41 scores => { $B => $bs, $W => $ws },
42 territory => { $B => $raw->{territory_b}, $W => $raw->{territory_w} },
43 prisoners => { $B => $raw->{prisoners_b}, $W => $raw->{prisoners_w} },
44 area => { $B => $raw->{area_b}, $W => $raw->{area_w} },
45 komi => $game->komi,
46 dame => $raw->{dame},
47 26 ▶ );
Condition50%1/2
$o{'scored_by'} || 'territory'
l!l
260
MC/DC0%0/1
$o{'scored_by'} || 'territory'
$o{'scored_by'}
Truth table50%1/2
A
A= $o{'scored_by'}
Aresult
11
00
48 }
49  
50 2 ▶sub score_by_area {
Subroutine score_by_area: called CC=3 SCAR=11.8
Pod documented
51 2 my ($game) = @_;
52 2 my $a = $game->raw_area;
53  
54 2 my $bs = $a->{area_b};
55 2 my $ws = $a->{area_w} + $game->komi;
56 2 ▶ my $winner = $bs > $ws ? $B : $ws > $bs ? $W : undef;
Branch: 2 branches
BranchTrueFalseTotal
$bs > $ws ? : 2 0 2
$ws > $bs ? : 0 0 0
57  
58 return Game::Go::Result->new(
59 winner => $winner,
60 result => 'score',
61 scored_by => 'area',
62 scores => { $B => $bs, $W => $ws },
63 territory => {},
64 prisoners => {},
65 area => { $B => $a->{area_b}, $W => $a->{area_w} },
66 komi => $game->komi,
67 dame => $a->{dame},
68 2 );
69 }
70  
71 31 ▶sub agree_under_equivalence {
Subroutine agree_under_equivalence: called CC=4 SCAR=13.9
Pod documented
72 31 my ($game) = @_;
73  
74 31 ▶ return undef if @{ $game->marked_seki };
Branch: 1 branch
BranchTrueFalseTotal
if @{$game->marked_seki;} 2 29 31
75  
76 29 my $played = stones_played($game);
77 29 ▶ return undef unless $played->{$B} == $played->{$W};
Branch: 1 branch
BranchTrueFalseTotal
unless $played->{$B} == $played->{$W} 3 26 29
78  
79 26 my $raw = raw($game);
80  
81 my $territory = ($raw->{territory_b} - $raw->{prisoners_w})
82 26 - ($raw->{territory_w} - $raw->{prisoners_b});
83 26 my $area = $raw->{area_b} - $raw->{area_w};
84  
85 26 ▶ return $territory == $area ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$territory == $area ? : 26 0 26
86 }
87  
88 25 1;
89  
90 __END__
« blib/lib/Game/Go/Result.pm ↑ Summary blib/lib/Game/Go/Engine.pm »