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
« Dominoes/Notation.pm ↑ Summary Dominoes/Tile.pm »
1 package Game::Dominoes::Rules;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Game::Dominoes::Scoring ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 our $VERSION = '0.03';
11 12 our @EXPORT_OK = qw(candidates can_play best_arm);
12  
13 255634 ▶sub candidates {
Subroutine candidates: called CC=8 SCAR=21.0
Pod documented
14 255634 my ($layout, $hand) = @_;
15 255634 ▶ die 'Game::Dominoes::Rules: candidates wants a layout and a hand'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $layout and ref $hand 0 255634 255634
Condition33%1/3
ref $layout and ref $hand
!ll&&!rl&&r
00255634
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 255634 my @arms = $layout->arms_open;
19 255634 my @out;
20  
21 255634 ▶ if ($layout->is_empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($layout->is_empty) 1283 254351 255634
22 1283 push @out, { tile => $_, arm => $arms[0] } for @{ $hand->sorted };
23 1283 return \@out;
24 }
25  
26 254351 for my $tile (@{ $hand->sorted }) {
27 1340674 for my $arm (@arms) {
28 3784306 ▶ next unless $layout->can_place($tile, $arm);
Branch: 1 branch
BranchTrueFalseTotal
unless $layout->can_place($tile, $arm) 3061405 722901 3784306
29 722901 push @out, { tile => $tile, arm => $arm };
30 }
31 }
32 254351 return \@out;
33 }
34  
35 23372 ▶sub can_play {
Subroutine can_play: called CC=2 SCAR=6.9
Pod documented
36 23372 my ($layout, $hand) = @_;
37 23372 ▶ return scalar @{ candidates($layout, $hand) } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @{candidates($layout, $hand);} ? : 19187 4185 23372
38 }
39  
40 673971 ▶sub score_of {
Subroutine score_of: called CC=1 SCAR=0.0
Pod documented
41 673971 my ($layout, $tile, $arm, $scale) = @_;
42 673971 my $trial = $layout->clone;
43 673971 $trial->place($tile, $arm);
44 673971 return Game::Dominoes::Scoring::score_for(
45 Game::Dominoes::Scoring::count($trial), $scale
46 );
47 }
48  
49 12 1;
50  
51 __END__
« Dominoes/Notation.pm ↑ Summary Dominoes/Tile.pm »