| 1 | package Game::Checkers::Result; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 30 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 30 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 30 | our %REASON = ( | |||||||||||||||||||||||||||||||||||||||||
| 11 | no_moves => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 12 | resign => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | repetition => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | no_progress => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | agreement => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | timeout => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | has winner => ( | ||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'ro' | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 30 | ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | has reason => ( | ||||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 30 | ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 44 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=7 SCAR=21.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 44 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 44 | my $reason = $self->reason; | |||||||||||||||||||||||||||||||||||||||||
| 31 | die "reason must be one of " . join(', ', sort keys %REASON) . ", got " | ||||||||||||||||||||||||||||||||||||||||||
| 32 | . (defined $reason ? "'$reason'" : 'undef') | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 44 | ▶ | unless defined $reason && $REASON{$reason}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $reason and $Game::Checkers::Result::REASON{$reason}
MC/DC0%0/2
defined $reason and $Game::Checkers::Result::REASON{$reason}
defined $reason
$Game::Checkers::Result::REASON{$reason}
Truth table33%1/3
A and B
A= defined $reasonB= $Game::Checkers::Result::REASON{$reason}
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 44 | my $winner = $self->winner; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 44 | ▶ | die "winner must be black, white or undef for a draw, got '$winner'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $winner and $winner ne "black" and $winner ne "white"
defined $winner and $winner ne "black"
MC/DC0%0/3
defined $winner and $winner ne "black" and $winner ne "white"
defined $winner
$winner ne "black"
$winner ne "white"
Truth table75%3/4
A and B and C
A= defined $winnerB= $winner ne "black"C= $winner ne "white"
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | if defined $winner && $winner ne 'black' && $winner ne 'white'; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 44 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 46 | ▶ | sub is_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_draw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 46 | ▶ | return defined $_[0]->winner ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 10 | ▶ | sub loser { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loser: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 10 | ▶ | return undef if $self->is_draw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ▶ | return $self->winner eq 'black' ? 'white' : 'black'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 22 | ▶ | sub pdn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pdn: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 22 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 22 | ▶ | return '1/2-1/2' if $self->is_draw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 12 | ▶ | return $self->winner eq 'white' ? '1-0' : '0-1'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=8 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | my $reason = $self->reason; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | ▶ | if ($self->is_draw) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | return 'Draw: agreed' if $reason eq 'agreement'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | return 'Draw: threefold repetition' if $reason eq 'repetition'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | return 'Draw: forty moves without progress' if $reason eq 'no_progress'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return 'Draw'; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 10 | my $loser = ucfirst $self->loser; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | my $winner = ucfirst $self->winner; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | return "$winner wins: $loser has no move" if $reason eq 'no_moves'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | return "$winner wins: $loser resigned" if $reason eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return "$winner wins: $loser ran out of time" if $reason eq 'timeout'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return "$winner wins"; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||||||||||||||||