| 1 | package Game::Sternhalma::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 30 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 30 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 30 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 30 | my %HOW = map { $_ => 1 } qw(home cap deadlock resign); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 30 | has how => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 30 | has places => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 30 | has ply => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 30 | has position => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=8 SCAR=21.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | my $how = $self->how; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | Carp::croak("Game::Sternhalma::Result: '" . (defined $how ? $how : 'undef') . "' is not a way a game ends") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | unless defined $how && $HOW{$how}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $how and $HOW{$how}
MC/DC50%1/2
defined $how and $HOW{$how}
defined $how
$HOW{$how}
Truth table66%2/3
A and B
A= defined $howB= $HOW{$how}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | my $places = $self->places; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | Carp::croak('Game::Sternhalma::Result: places is a place for every seat, 1 the best') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 8 | ▶ | unless ref $places eq 'ARRAY' && @$places && !grep { !defined || !/\A[1-9][0-9]*\z/ } @$places; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
ref $places eq "ARRAY" and @$places and not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
ref $places eq "ARRAY" and @$places
defined $_ && /\A[1-9][0-9]*\z/u
MC/DC33%1/3
ref $places eq "ARRAY" and @$places and not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
ref $places eq "ARRAY"
@$places
not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
MC/DC50%1/2
defined $_ && /\A[1-9][0-9]*\z/u
defined $_
/\A[1-9][0-9]*\z/u
Truth table50%2/4
A and B and not(C)
A= ref $places eq "ARRAY"B= @$placesC= not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
Truth table66%2/3
A && B
A= defined $_B= /\A[1-9][0-9]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | sub seats { scalar @{ $_[0]->places } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub place_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place_of: called CC=4 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | return undef unless defined $seat && $seat =~ /\A[0-9]+\z/ && $seat < $self->seats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats
defined $seat and $seat =~ /\A[0-9]+\z/u
MC/DC0%0/3
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats
defined $seat
$seat =~ /\A[0-9]+\z/u
$seat < $self->seats
Truth table25%1/4
A and B and C
A= defined $seatB= $seat =~ /\A[0-9]+\z/uC= $seat < $self->seats
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | return $self->places->[$seat]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # The seats in the order they finished, best first; seats sharing a place in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # seat order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | sub ranking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ranking: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | my $p = $self->places; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | return sort { $p->[$a] <=> $p->[$b] || $a <=> $b } 0 .. $#$p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$p->[$a] <=> $p->[$b] || $a <=> $b
MC/DC0%0/2
$p->[$a] <=> $p->[$b] || $a <=> $b
$p->[$a] <=> $p->[$b]
$a <=> $b
Truth table66%2/3
A || B
A= $p->[$a] <=> $p->[$b]B= $a <=> $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # The one seat in first place, or undef when first is shared. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | ▶ | sub winner { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
winner: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | my @first = grep { $self->places->[$_] == 1 } 0 .. $self->seats - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | return @first == 1 ? $first[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | sub ways { sort keys %HOW } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ways: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||