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