blib/lib/Game/Dominoes/Rules.pm

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 7 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 91.5% 54 / 59 CC 9 SCAR 16.0
CC
9
Cov
94%
candidates
8.1
can_play
2.0
BEGIN
1.0
CRAP 4.9
« blib/lib/Game/Dominoes/Notation.pm ↑ Summary blib/lib/Game/Dominoes/Tile.pm »
1 package Game::Dominoes::Rules;
2  
3 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 38 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 38 ▶use Game::Dominoes::Scoring ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 38 our $VERSION = '0.05';
11 38 our @EXPORT_OK = qw(candidates can_play best_arm);
12  
13 352195 ▶sub candidates {
Subroutine candidates: called CC=8 SCAR=21.0
Pod documented
14 352195 my ($layout, $hand) = @_;
15 352195 ▶ die 'Game::Dominoes::Rules: candidates wants a layout and a hand'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $layout and ref $hand 0 352195 352195
Condition33%1/3
ref $layout and ref $hand
!ll&&!rl&&r
00352195
MC/DC0%0/2
ref $layout and ref $hand
ref $layout ref $hand
Truth table33%1/3
A and B
A= ref $layoutB= ref $hand
ABresult
0X0
100
111
16 unless ref $layout && ref $hand;
17  
18 352195 my @arms = $layout->arms_open;
19 352195 my @out;
20  
21 352195 ▶ if ($layout->is_empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($layout->is_empty) 1342 350853 352195
22 1342 push @out, { tile => $_, arm => $arms[0] } for @{ $hand->sorted };
23 1342 return \@out;
24 }
25  
26 350853 for my $tile (@{ $hand->sorted }) {
27 1797332 for my $arm (@arms) {
28 5248620 ▶ next unless $layout->can_place($tile, $arm);
Branch: 1 branch
BranchTrueFalseTotal
unless $layout->can_place($tile, $arm) 4248618 1000002 5248620
29 1000002 push @out, { tile => $tile, arm => $arm };
30 }
31 }
32 350853 return \@out;
33 }
34  
35 24613 ▶sub can_play {
Subroutine can_play: called CC=2 SCAR=6.9
Pod documented
36 24613 my ($layout, $hand) = @_;
37 24613 ▶ return scalar @{ candidates($layout, $hand) } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @{candidates($layout, $hand);} ? : 20129 4484 24613
38 }
39  
40 948926 ▶sub score_of {
Subroutine score_of: called CC=1 SCAR=0.0
Pod documented
41 948926 my ($layout, $tile, $arm, $scale) = @_;
42 948926 my $trial = $layout->clone;
43 948926 $trial->place($tile, $arm);
44 948926 return Game::Dominoes::Scoring::score_for(
45 Game::Dominoes::Scoring::count($trial), $scale
46 );
47 }
48  
49 38 1;
50  
51 __END__
« blib/lib/Game/Dominoes/Notation.pm ↑ Summary blib/lib/Game/Dominoes/Tile.pm »