| 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
Condition0%0/3
ref $layout and ref $hand
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||