blib/lib/Game/Brandubh/Result.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 18 / 18 Conditioncond 100% 18 / 18 MC/DCmcdc 100% 10 / 10 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 99.0% 104 / 105 CC 16 SCAR 17.5
CC
16
Cov
100%
BUILD
11.0
loser
3.0
by_players
3.0
CRAP 5.8
« blib/lib/Game/Brandubh.pm ↑ Summary blib/lib/Game/Brandubh/Bot.pm »
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
BranchTrueFalseTotal
unless defined $how and $Game::Brandubh::Result::WIN{$how} || $Game::Brandubh::Result::DRAW{$how} 3 4021 4024
Condition100%6/6
defined $how and $Game::Brandubh::Result::WIN{$how} || $Game::Brandubh::Result::DRAW{$how}
!ll&&!rl&&r
124021
$Game::Brandubh::Result::WIN{$how} or $Game::Brandubh::Result::DRAW{$how}
l!l&&r!l&&!r
34545672
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}
ABCresult
0XX0
1000
11X1
1011
33  
34 4021 my $winner = $self->winner;
35 4021 ▶ if ($WIN{$how}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Game::Brandubh::Result::WIN{$how}) { } 3454 567 4021
36 3454 ▶ Carp::croak("Game::Brandubh::Result: a game ended by $how has a winner, attackers or defenders")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $winner and $winner eq "attackers" || $winner eq "defenders" 10 3444 3454
Condition100%6/6
defined $winner and $winner eq "attackers" || $winner eq "defenders"
!ll&&!rl&&r
553444
$winner eq "attackers" or $winner eq "defenders"
l!l&&r!l&&!r
90225425
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"
ABCresult
0XX0
1000
11X1
1011
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
BranchTrueFalseTotal
unless defined $self->seat 5 3439 3444
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
BranchTrueFalseTotal
if defined $winner or defined $self->seat 12 555 567
Condition100%3/3
defined $winner or defined $self->seat
l!l&&r!l&&!r
84555
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$Game::Brandubh::Result::DRAW{$_[0]->how} ? : 12 57 69
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
BranchTrueFalseTotal
unless defined $winner 4 112 116
54 112 ▶ return $winner eq 'attackers' ? 'defenders' : 'attackers';
Branch: 1 branch
BranchTrueFalseTotal
$winner eq 'attackers' ? : 22 90 112
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
BranchTrueFalseTotal
$how eq 'resign' || $how eq 'agreed' ? : 35 81 116
Condition100%3/3
$how eq "resign" or $how eq "agreed"
l!l&&r!l&&!r
251081
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"
ABresult
1X1
011
000
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__
« blib/lib/Game/Brandubh.pm ↑ Summary blib/lib/Game/Brandubh/Bot.pm »