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 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 23 ▶use Game::Oware::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 23 our $VERSION = '0.04';
11  
12 has seat => (
13 is => 'ro',
14 isa => Str
15 23 );
16  
17 has house => (
18 is => 'ro',
19 isa => Int
20 23 );
21  
22 has sown => (
23 is => 'ro',
24 isa => Int
25 23 );
26  
27 has last => (
28 is => 'ro',
29 isa => Int
30 23 );
31  
32 has captured => (
33 is => 'ro',
34 isa => ArrayRef,
35 default => []
36 23 );
37  
38 has taken => (
39 is => 'ro',
40 isa => Int,
41 default => 0
42 23 );
43  
44 has slammed => (
45 is => 'ro',
46 isa => Int,
47 default => 0
48 23 );
49  
50 has forfeited => (
51 is => 'ro',
52 isa => ArrayRef,
53 default => []
54 23 );
55  
56 525395 ▶sub BUILD {
Subroutine BUILD: called CC=16 SCAR=27.8
Pod documented
57 525395 my ($self) = @_;
58  
59 525395 ▶ my $seat = $self->seat // '';
Condition50%1/2
$self->seat // ""
l!l
5253950
MC/DC0%0/1
$self->seat // ""
$self->seat
Truth table50%1/2
A
A= $self->seat
Aresult
11
00
60 525395 ▶ 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 525394 525395
Condition100%3/3
$seat eq "p1" or $seat eq "p2"
l!l&&r!l&&!r
2595422658521
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 525394 Game::Oware::Board->assert_house($self->house);
64 525393 Game::Oware::Board->assert_house($self->last);
65  
66 525393 ▶ 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 525392 525393
67 unless Game::Oware::Board->owner_of($self->house) eq $seat;
68  
69 525392 my $sown = $self->sown;
70 525392 ▶ 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 525391 525392
Condition50%3/6
defined $sown and $sown =~ /\A\d+\z/ and $sown > 0
!ll&&!rl&&r
01525391
defined $sown and $sown =~ /\A\d+\z/
!ll&&!rl&&r
00525392
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 525391 my $captured = $self->captured;
74 525391 ▶ die 'Game::Oware::Move: a move never captures more houses than it sowed'
Branch: 1 branch
BranchTrueFalseTotal
if @$captured > $sown 1 525390 525391
75 if @$captured > $sown;
76  
77 die 'Game::Oware::Move: a seat never captures its own house'
78 525390 ▶ 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 525389 525390
79  
80 525389 ▶ die 'Game::Oware::Move: taken disagrees with captured'
Branch: 1 branch
BranchTrueFalseTotal
if not @$captured and $self->taken 1 525388 525389
Condition100%3/3
not @$captured and $self->taken
!ll&&!rl&&r
722634531251
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 525388 my $forfeited = $self->forfeited;
84  
85 525388 ▶ die 'Game::Oware::Move: a move either captured its chain or forfeited it'
Branch: 1 branch
BranchTrueFalseTotal
if @$forfeited and @$captured 1 525387 525388
Condition100%3/3
@$forfeited and @$captured
!ll&&!rl&&r
5252401471
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 525387 ▶ die 'Game::Oware::Move: only a grand slam forfeits a chain'
Branch: 1 branch
BranchTrueFalseTotal
if @$forfeited and not $self->slammed 1 525386 525387
Condition100%3/3
@$forfeited and not $self->slammed
!ll&&!rl&&r
5252401461
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 525386 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 23 1;
109  
110 __END__
« blib/lib/Game/Oware/Result.pm ↑ Summary blib/lib/Game/Oware/Terminal.pm »