| 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
Condition66%2/3
$e->{"kind"} eq "play" or $e->{"kind"} eq "handicap"
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"
| |||||||||||||||||||||||||||||
| 20 | 485 | ▶ | my $who = Game::Go::Rules::from_letter($e->{actor}) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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)
MC/DC0%0/2
$o{'raw'} || raw($game)
$o{'raw'}
raw($game)
Truth table33%1/3
A || B
A= $o{'raw'}B= raw($game)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$o{'scored_by'} || 'territory'
$o{'scored_by'}
Truth table50%1/2
A
A= $o{'scored_by'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 29 | my $played = stones_played($game); | |||||||||||||||||||||||||||
| 77 | 29 | ▶ | return undef unless $played->{$B} == $played->{$W}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 25 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||