| 1 | package Game::Fanorona::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 26 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 26 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 26 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 26 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 26 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 26 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 26 | my %WON = map { $_ => 1 } qw(stones no_moves resign); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 26 | my %DRAWN = map { $_ => 1 } qw(repetition quiet ply_cap agreement); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 26 | has winner => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 26 | has how => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 26 | has position => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 26 | has moves => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 382 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 382 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 382 | my ($how, $winner) = ($self->how, $self->winner); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | Carp::croak("Game::Fanorona::Result: '" . ($how // 'undef') . "' is not a way a game ends") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 382 | ▶ | unless defined $how && ($WON{$how} || $DRAWN{$how}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%8/8
defined $how and $WON{$how} || $DRAWN{$how}
$WON{$how} or $DRAWN{$how}
$how // "undef"
MC/DC100%3/3
defined $how and $WON{$how} || $DRAWN{$how}
defined $how
$WON{$how}
$DRAWN{$how}
MC/DC100%1/1
$how // "undef"
$how
Truth table100%4/4
A and B or C
A= defined $howB= $WON{$how}C= $DRAWN{$how}
Truth table100%2/2
A
A= $how
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 380 | ▶ | if ($WON{$how}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 339 | ▶ | Carp::croak("Game::Fanorona::Result: a game ended by $how has a winner, white or black") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $winner and $winner eq "white" || $winner eq "black"
$winner eq "white" or $winner eq "black"
MC/DC100%3/3
defined $winner and $winner eq "white" || $winner eq "black"
defined $winner
$winner eq "white"
$winner eq "black"
Truth table100%4/4
A and B or C
A= defined $winnerB= $winner eq "white"C= $winner eq "black"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | unless defined $winner && ($winner eq 'white' || $winner eq 'black'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 41 | ▶ | Carp::croak("Game::Fanorona::Result: a game ended by $how has no winner") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | if defined $winner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 370 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 12 | ▶ | sub is_draw { $DRAWN{ $_[0]->how } ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_draw: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | ▶ | sub loser { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loser: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 11 | ▶ | my $winner = $self->winner // return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->winner // (return undef)
MC/DC100%1/1
$self->winner // (return undef)
$self->winner
Truth table100%2/2
A
A= $self->winner
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | ▶ | return $winner eq 'white' ? 'black' : 'white'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | sub ways { (sort(keys %WON), sort(keys %DRAWN)) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ways: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 26 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||