blib/lib/Game/Oware/Move.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 22 / 22 Conditioncond 80.0% 16 / 20 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 93.8% 106 / 113 CC 19 SCAR 24.1
CC
19
Cov
96%
BUILD
16.1
stringify
4.0
BEGIN
1.0
CRAP 11.2
« blib/lib/Game/Oware/Result.pm ↑ Summary blib/lib/Game/Oware/Terminal.pm »
1 package Game::Oware::Move;
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 ▶use Game::Oware::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 20 our $VERSION = '0.03';
11  
12 has seat => (
13 is => 'ro',
14 isa => Str
15 20 );
16  
17 has house => (
18 is => 'ro',
19 isa => Int
20 20 );
21  
22 has sown => (
23 is => 'ro',
24 isa => Int
25 20 );
26  
27 has last => (
28 is => 'ro',
29 isa => Int
30 20 );
31  
32 has captured => (
33 is => 'ro',
34 isa => ArrayRef,
35 default => []
36 20 );
37  
38 has taken => (
39 is => 'ro',
40 isa => Int,
41 default => 0
42 20 );
43  
44 has slammed => (
45 is => 'ro',
46 isa => Int,
47 default => 0
48 20 );
49  
50 has forfeited => (
51 is => 'ro',
52 isa => ArrayRef,
53 default => []
54 20 );
55  
56 469237 ▶sub BUILD {
Subroutine BUILD: called CC=16 SCAR=27.8
Pod documented
57 469237 my ($self) = @_;
58  
59 469237 ▶ my $seat = $self->seat // '';
Condition50%1/2
$self->seat // ""
l!l
4692370
MC/DC0%0/1
$self->seat // ""
$self->seat
Truth table50%1/2
A
A= $self->seat
Aresult
11
00
60 469237 ▶ die "Game::Oware::Move: seat must be p1 or p2, not '$seat'"
Branch: 1 branch
BranchTrueFalseTotal
unless $seat eq "p1" or $seat eq "p2" 1 469236 469237
Condition100%3/3
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
2318632373731
MC/DC100%2/2
$seat eq "p1" or $seat eq "p2"
$seat eq "p1" $seat eq "p2"
Truth table100%3/3
A or B
A= $seat eq "p1"B= $seat eq "p2"
ABresult
1X1
011
000
61 unless $seat eq 'p1' || $seat eq 'p2';
62  
63 469236 Game::Oware::Board->assert_house($self->house);
64 469235 Game::Oware::Board->assert_house($self->last);
65  
66 469235 ▶ die 'Game::Oware::Move: a seat may only sow from its own house'
Branch: 1 branch
BranchTrueFalseTotal
unless "Game::Oware::Board"->owner_of($self->house) eq $seat 1 469234 469235
67 unless Game::Oware::Board->owner_of($self->house) eq $seat;
68  
69 469234 my $sown = $self->sown;
70 469234 ▶ die 'Game::Oware::Move: a move sows at least one seed'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sown and $sown =~ /\A\d+\z/ and $sown > 0 1 469233 469234
Condition50%3/6
defined $sown and $sown =~ /\A\d+\z/ and $sown > 0
!ll&&!rl&&r
01469233
defined $sown and $sown =~ /\A\d+\z/
!ll&&!rl&&r
00469234
MC/DC33%1/3
defined $sown and $sown =~ /\A\d+\z/ and $sown > 0
defined $sown $sown =~ /\A\d+\z/ $sown > 0
Truth table50%2/4
A and B and C
A= defined $sownB= $sown =~ /\A\d+\z/C= $sown > 0
ABCresult
0XX0
10X0
1100
1111
71 unless defined $sown && $sown =~ /\A\d+\z/ && $sown > 0;
72  
73 469233 my $captured = $self->captured;
74 469233 ▶ die 'Game::Oware::Move: a move never captures more houses than it sowed'
Branch: 1 branch
BranchTrueFalseTotal
if @$captured > $sown 1 469232 469233
75 if @$captured > $sown;
76  
77 die 'Game::Oware::Move: a seat never captures its own house'
78 469232 ▶ if grep { Game::Oware::Board->owner_of($_) eq $seat } @$captured;
Branch: 1 branch
BranchTrueFalseTotal
if grep {"Game::Oware::Board"->owner_of($_) eq $seat;} @$captured 1 469231 469232
79  
80 469231 ▶ die 'Game::Oware::Move: taken disagrees with captured'
Branch: 1 branch
BranchTrueFalseTotal
if not @$captured and $self->taken 1 469230 469231
Condition100%3/3
not @$captured and $self->taken
!ll&&!rl&&r
666824025481
MC/DC100%2/2
not @$captured and $self->taken
not @$captured $self->taken
Truth table100%3/3
not(A) and B
A= not @$capturedB= $self->taken
ABresult
0X0
100
111
81 if !@$captured && $self->taken;
82  
83 469230 my $forfeited = $self->forfeited;
84  
85 469230 ▶ die 'Game::Oware::Move: a move either captured its chain or forfeited it'
Branch: 1 branch
BranchTrueFalseTotal
if @$forfeited and @$captured 1 469229 469230
Condition100%3/3
@$forfeited and @$captured
!ll&&!rl&&r
4690961331
MC/DC100%2/2
@$forfeited and @$captured
@$forfeited @$captured
Truth table100%3/3
A and B
A= @$forfeitedB= @$captured
ABresult
0X0
100
111
86 if @$forfeited && @$captured;
87  
88 469229 ▶ die 'Game::Oware::Move: only a grand slam forfeits a chain'
Branch: 1 branch
BranchTrueFalseTotal
if @$forfeited and not $self->slammed 1 469228 469229
Condition100%3/3
@$forfeited and not $self->slammed
!ll&&!rl&&r
4690961321
MC/DC100%2/2
@$forfeited and not $self->slammed
@$forfeited not $self->slammed
Truth table100%3/3
A and not(B)
A= @$forfeitedB= not $self->slammed
ABresult
0X0
100
111
89 if @$forfeited && !$self->slammed;
90  
91 469228 return $self;
92 }
93  
94 6 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
95 6 my ($self) = @_;
96 6 require Game::Oware::Notation;
97 6 return Game::Oware::Notation->letter_of($self->house);
98 }
99  
100 5 ▶sub stringify {
Subroutine stringify: called CC=4 SCAR=13.9
Pod documented
101 5 my ($self) = @_;
102 5 my $name = $self->name;
103 5 ▶ return $name . ' (slam forfeited)' if @{ $self->forfeited };
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->forfeited;} 2 3 5
104 3 ▶ return $name unless @{ $self->captured };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->captured;} 1 2 3
105 2 ▶ return $name . ' takes ' . $self->taken . ($self->slammed ? ' (slam)' : '');
Branch: 1 branch
BranchTrueFalseTotal
$self->slammed ? : 1 1 2
106 }
107  
108 20 1;
109  
110 __END__
« blib/lib/Game/Oware/Result.pm ↑ Summary blib/lib/Game/Oware/Terminal.pm »