| 1 | package Game::Oware::Result; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | our @RESULTS = qw/ score draw timeout abandoned resign /; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | our @REASONS = qw/ target even no_feed cycle timeout abandon resign /; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | my %IS_RESULT = map { $_ => 1 } @RESULTS; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | my %IS_REASON = map { $_ => 1 } @REASONS; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 20 | has winner => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | has result => ( | ||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | has reason => ( | ||||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | has captured => ( | ||||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | default => {} | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 20 | has score => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | has places => ( | ||||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | default => {} | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 64 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=15 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 64 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 64 | ▶ | my $result = $self->result // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->result // ""
MC/DC0%0/1
$self->result // ""
$self->result
Truth table50%1/2
A
A= $self->result
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | die "Game::Oware::Result: '$result' is not a result" | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 64 | ▶ | unless $IS_RESULT{$result}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 64 | ▶ | my $reason = $self->reason // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->reason // ""
MC/DC0%0/1
$self->reason // ""
$self->reason
Truth table50%1/2
A
A= $self->reason
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | die "Game::Oware::Result: '$reason' is not a reason" | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 64 | ▶ | unless $IS_REASON{$reason}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 64 | my $winner = $self->winner; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 64 | ▶ | die 'Game::Oware::Result: a draw has no winner' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$result eq "draw" and defined $winner
MC/DC0%0/2
$result eq "draw" and defined $winner
$result eq "draw"
defined $winner
Truth table66%2/3
A and B
A= $result eq "draw"B= defined $winner
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | if $result eq 'draw' && defined $winner; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 64 | ▶ | die 'Game::Oware::Result: a decided game has a winner' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$result ne "draw" and $result ne "abandoned" and not defined $winner
$result ne "draw" and $result ne "abandoned"
MC/DC0%0/3
$result ne "draw" and $result ne "abandoned" and not defined $winner
$result ne "draw"
$result ne "abandoned"
not defined $winner
Truth table75%3/4
A and B and not(C)
A= $result ne "draw"B= $result ne "abandoned"C= not defined $winner
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | if $result ne 'draw' && $result ne 'abandoned' && !defined $winner; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 64 | ▶ | die "Game::Oware::Result: '$winner' is not a seat" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $winner and $winner ne "p1" and $winner ne "p2"
defined $winner and $winner ne "p1"
MC/DC0%0/3
defined $winner and $winner ne "p1" and $winner ne "p2"
defined $winner
$winner ne "p1"
$winner ne "p2"
Truth table75%3/4
A and B and C
A= defined $winnerB= $winner ne "p1"C= $winner ne "p2"
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | if defined $winner && $winner ne 'p1' && $winner ne 'p2'; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 64 | ▶ | die 'Game::Oware::Result: only a natural ending has a score' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->score and not $self->natural
MC/DC0%0/2
defined $self->score and not $self->natural
defined $self->score
not $self->natural
Truth table66%2/3
A and not(B)
A= defined $self->scoreB= not $self->natural
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | if defined $self->score && !$self->natural; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 64 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 45 | ▶ | sub natural { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
natural: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 45 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 45 | ▶ | my $result = $self->result // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->result // ""
MC/DC0%0/1
$self->result // ""
$self->result
Truth table50%1/2
A
A= $self->result
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 45 | ▶ | return $result eq 'score' || $result eq 'draw' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$result eq "score" or $result eq "draw"
MC/DC100%2/2
$result eq "score" or $result eq "draw"
$result eq "score"
$result eq "draw"
Truth table100%3/3
A or B
A= $result eq "score"B= $result eq "draw"
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub results { return [@RESULTS] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
results: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub reasons { return [@REASONS] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reasons: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 15 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 15 | my $captured = $self->captured; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | ▶ | my $line = defined $self->winner | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | ? $self->winner . ' wins by ' . $self->result | ||||||||||||||||||||||||||||||||||||||||||
| 83 | : 'a ' . $self->result; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | $line .= ' (' . $self->reason . ')'; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | ▶ | return $line . ', ' . ($captured->{p1} // 0) . ' to ' . ($captured->{p2} // 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$captured->{"p1"} // 0
$captured->{"p2"} // 0
MC/DC0%0/1
$captured->{"p1"} // 0
$captured->{"p1"}
MC/DC0%0/1
$captured->{"p2"} // 0
$captured->{"p2"}
Truth table50%1/2
A
A= $captured->{"p1"}
Truth table50%1/2
A
A= $captured->{"p2"}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||||||||