Dominoes/Rules.pm

filter: Statementstmt 41.6% 15 / 36 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 37.2% 22 / 59 CC 9 SCAR 36.8
CC
9
Cov
32%
candidates
72.0
can_play
6.0
score_of
2.0
CRAP 39.6
↑ Summary Dominoes/Scoring.pm »
1 package Game::Dominoes::Rules;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Game::Dominoes::Scoring ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.04';
11 1 our @EXPORT_OK = qw(candidates can_play best_arm);
12  
13 0 ▶sub candidates {
Subroutine candidates: not called CC=8 SCAR=42.8
Pod documented
14 0 my ($layout, $hand) = @_;
15 0 ▶ die 'Game::Dominoes::Rules: candidates wants a layout and a hand'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $layout and ref $hand 0 0 0
Condition0%0/3
ref $layout and ref $hand
!ll&&!rl&&r
000
MC/DC0%0/2
ref $layout and ref $hand
ref $layout ref $hand
Truth table0%0/3
A and B
A= ref $layoutB= ref $hand
ABresult
0X0
100
111
16 unless ref $layout && ref $hand;
17  
18 0 my @arms = $layout->arms_open;
19 0 my @out;
20  
21 0 ▶ if ($layout->is_empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($layout->is_empty) 0 0 0
22 0 push @out, { tile => $_, arm => $arms[0] } for @{ $hand->sorted };
23 0 return \@out;
24 }
25  
26 0 for my $tile (@{ $hand->sorted }) {
27 0 for my $arm (@arms) {
28 0 ▶ next unless $layout->can_place($tile, $arm);
Branch: 1 branch
BranchTrueFalseTotal
unless $layout->can_place($tile, $arm) 0 0 0
29 0 push @out, { tile => $tile, arm => $arm };
30 }
31 }
32 0 return \@out;
33 }
34  
35 0 ▶sub can_play {
Subroutine can_play: not called CC=2 SCAR=17.9
Pod documented
36 0 my ($layout, $hand) = @_;
37 0 ▶ return scalar @{ candidates($layout, $hand) } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @{candidates($layout, $hand);} ? : 0 0 0
38 }
39  
40 0 ▶sub score_of {
Subroutine score_of: not called CC=1 SCAR=6.9
Pod documented
41 0 my ($layout, $tile, $arm, $scale) = @_;
42 0 my $trial = $layout->clone;
43 0 $trial->place($tile, $arm);
44 0 return Game::Dominoes::Scoring::score_for(
45 Game::Dominoes::Scoring::count($trial), $scale
46 );
47 }
48  
49 1 1;
50  
51 __END__
↑ Summary Dominoes/Scoring.pm »