| 1 | package Game::Brandubh::Result; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 44 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 44 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 44 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 44 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 44 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 44 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 44 | our (%WIN, %DRAW); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 44 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 44 | %WIN = map { $_ => 1 } qw(corner edge capture no_pieces resign); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 44 | %DRAW = map { $_ => 1 } qw(repetition no_move ply_cap agreed); | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 44 | has how => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 44 | has winner => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 44 | has seat => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 44 | has ply => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 44 | has position => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4024 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 4024 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 4024 | my $how = $self->how; | |||||||||||||||||||||||||||||||||||||||||
| 31 | Carp::croak('Game::Brandubh::Result: a result says how the game ended') | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 4024 | ▶ | unless defined $how && ($WIN{$how} || $DRAW{$how}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $how and $Game::Brandubh::Result::WIN{$how} || $Game::Brandubh::Result::DRAW{$how}
$Game::Brandubh::Result::WIN{$how} or $Game::Brandubh::Result::DRAW{$how}
MC/DC100%3/3
defined $how and $Game::Brandubh::Result::WIN{$how} || $Game::Brandubh::Result::DRAW{$how}
defined $how
$Game::Brandubh::Result::WIN{$how}
$Game::Brandubh::Result::DRAW{$how}
Truth table100%4/4
A and B or C
A= defined $howB= $Game::Brandubh::Result::WIN{$how}C= $Game::Brandubh::Result::DRAW{$how}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 4021 | my $winner = $self->winner; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 4021 | ▶ | if ($WIN{$how}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3454 | ▶ | Carp::croak("Game::Brandubh::Result: a game ended by $how has a winner, attackers or defenders") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $winner and $winner eq "attackers" || $winner eq "defenders"
$winner eq "attackers" or $winner eq "defenders"
MC/DC100%3/3
defined $winner and $winner eq "attackers" || $winner eq "defenders"
defined $winner
$winner eq "attackers"
$winner eq "defenders"
Truth table100%4/4
A and B or C
A= defined $winnerB= $winner eq "attackers"C= $winner eq "defenders"
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | unless defined $winner && ($winner eq 'attackers' || $winner eq 'defenders'); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 3444 | ▶ | Carp::croak("Game::Brandubh::Result: a game ended by $how names the winner's seat") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | unless defined $self->seat; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 567 | ▶ | Carp::croak("Game::Brandubh::Result: a game drawn by $how has no winner") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $winner or defined $self->seat
MC/DC100%2/2
defined $winner or defined $self->seat
defined $winner
defined $self->seat
Truth table100%3/3
A or B
A= defined $winnerB= defined $self->seat
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | if defined $winner || defined $self->seat; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 3994 | return; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 69 | ▶ | sub is_draw { $DRAW{ $_[0]->how } ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_draw: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 116 | ▶ | sub loser { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loser: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 116 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 116 | my $winner = $self->winner; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 116 | ▶ | return undef unless defined $winner; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 112 | ▶ | return $winner eq 'attackers' ? 'defenders' : 'attackers'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 116 | ▶ | sub by_players { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
by_players: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 116 | my $how = $_[0]->how; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 116 | ▶ | return $how eq 'resign' || $how eq 'agreed' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$how eq "resign" or $how eq "agreed"
MC/DC100%2/2
$how eq "resign" or $how eq "agreed"
$how eq "resign"
$how eq "agreed"
Truth table100%3/3
A or B
A= $how eq "resign"B= $how eq "agreed"
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub hows { sort(keys %WIN, keys %DRAW) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 44 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||||||||||||||||