| 1 | package Game::Merrills::Result; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 80 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 80 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 80 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 80 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 80 | our (@REASONS, %REASON); | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 80 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 80 | @REASONS = qw/few blocked repetition no_mill agreement resign timeout/; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 80 | %REASON = map { $_ => 1 } @REASONS; | |||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | has winner => ( | ||||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'ro' | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | has reason => ( | ||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 362 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=13 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 362 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 362 | my $reason = $self->reason; | |||||||||||||||||||||||||||||||||||||||||
| 29 | die 'reason must be one of ' . join(', ', @REASONS) . ', got ' | ||||||||||||||||||||||||||||||||||||||||||
| 30 | . (defined $reason ? "'$reason'" : 'undef') | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 362 | ▶ | unless defined $reason && $REASON{$reason}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $reason and $Game::Merrills::Result::REASON{$reason}
MC/DC100%2/2
defined $reason and $Game::Merrills::Result::REASON{$reason}
defined $reason
$Game::Merrills::Result::REASON{$reason}
Truth table100%3/3
A and B
A= defined $reasonB= $Game::Merrills::Result::REASON{$reason}
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 360 | my $winner = $self->winner; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 360 | ▶ | die "winner must be white, black or undef for a draw, got '$winner'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $winner and $winner ne "white" and $winner ne "black"
defined $winner and $winner ne "white"
MC/DC100%3/3
defined $winner and $winner ne "white" and $winner ne "black"
defined $winner
$winner ne "white"
$winner ne "black"
Truth table100%4/4
A and B and C
A= defined $winnerB= $winner ne "white"C= $winner ne "black"
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | if defined $winner && $winner ne 'white' && $winner ne 'black'; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 359 | ▶ | my $drawn = $reason eq 'repetition' || $reason eq 'no_mill' || $reason eq 'agreement'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$reason eq 'repetition' || $reason eq 'no_mill' || $reason eq 'agreement'
$reason eq "repetition" or $reason eq "no_mill"
MC/DC100%3/3
$reason eq 'repetition' || $reason eq 'no_mill' || $reason eq 'agreement'
$reason eq "repetition"
$reason eq "no_mill"
$reason eq 'agreement'
Truth table100%4/4
A or B || C
A= $reason eq "repetition"B= $reason eq "no_mill"C= $reason eq 'agreement'
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 359 | ▶ | die "a game that ends by $reason is a draw and has no winner" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$drawn and defined $winner
MC/DC100%2/2
$drawn and defined $winner
$drawn
defined $winner
Truth table100%3/3
A and B
A= $drawnB= defined $winner
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | if $drawn && defined $winner; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 356 | ▶ | die "a game that ends by $reason has a winner" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$drawn or defined $winner
MC/DC100%2/2
$drawn or defined $winner
$drawn
defined $winner
Truth table100%3/3
A or B
A= $drawnB= defined $winner
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | if !$drawn && !defined $winner; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 352 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub reasons { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reasons: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | return @REASONS; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 73 | ▶ | sub is_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_draw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 73 | ▶ | return defined $_[0]->winner ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 40 | ▶ | sub loser { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loser: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 40 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 40 | ▶ | return undef if $self->is_draw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 39 | ▶ | return $self->winner eq 'white' ? 'black' : 'white'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 40 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 40 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 40 | my $reason = $self->reason; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 40 | ▶ | return 'Draw: agreed' if $reason eq 'agreement'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 36 | ▶ | return 'Draw: the same position three times' if $reason eq 'repetition'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 35 | ▶ | return 'Draw: too long without a mill' if $reason eq 'no_mill'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 34 | my $loser = ucfirst $self->loser; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 34 | my $winner = ucfirst $self->winner; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 34 | ▶ | return "$winner wins: $loser has fewer than three men" if $reason eq 'few'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 19 | ▶ | return "$winner wins: $loser has no move" if $reason eq 'blocked'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 14 | ▶ | return "$winner wins: $loser resigned" if $reason eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | return "$winner wins: $loser ran out of time"; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 80 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||||||||||||||||