| 1 | package Game::Dominoes::Set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Game::Dominoes::Tile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | our @EXPORT_OK = qw(tiles tile_of order_for PIPS SIZE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use constant SIZE => 28; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use constant PIPS => 168; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | my @TILE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | $TILE[$_] = Game::Dominoes::Tile->from_id($_) for 1 .. SIZE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5177 | ▶ | sub tiles { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tiles: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5177 | return [ @TILE[ 1 .. SIZE ] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 57754 | ▶ | sub tile_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tile_of: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 57754 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 57754 | ▶ | die 'Game::Dominoes::Set: no tile has id ' . (defined $id ? $id : 'undef') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%6/9
defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28
defined $id and $id =~ /\A\d+\z/ and $id >= 1
defined $id and $id =~ /\A\d+\z/
MC/DC50%2/4
defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28
defined $id
$id =~ /\A\d+\z/
$id >= 1
$id <= 28
Truth table60%3/5
A and B and C and D
A= defined $idB= $id =~ /\A\d+\z/C= $id >= 1D= $id <= 28
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | unless defined $id && $id =~ /\A\d+\z/ && $id >= 1 && $id <= SIZE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 57752 | return $TILE[$id]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2079 | ▶ | sub order_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
order_for: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2079 | my ($seed, $hand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2079 | ▶ | die 'order_for wants a 32-byte seed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $seed and length $seed == 32
MC/DC100%2/2
defined $seed and length $seed == 32
defined $seed
length $seed == 32
Truth table100%3/3
A and B
A= defined $seedB= length $seed == 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | unless defined $seed && length $seed == 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2077 | ▶ | die 'order_for wants a hand number from 1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $hand and $hand =~ /\A[1-9]\d*\z/
MC/DC50%1/2
defined $hand and $hand =~ /\A[1-9]\d*\z/
defined $hand
$hand =~ /\A[1-9]\d*\z/
Truth table66%2/3
A and B
A= defined $handB= $hand =~ /\A[1-9]\d*\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | unless defined $hand && $hand =~ /\A[1-9]\d*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2074 | my ($counter, @words) = (0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 55998 | ▶ | my $next = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 55998 | ▶ | unless (@words) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8296 | my $digest = Digest::SHA::sha256($seed . "hand:$hand:" . $counter++); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8296 | @words = unpack 'N8', $digest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 55998 | return shift @words; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2074 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2074 | my @order = (1 .. SIZE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2074 | ▶ | for (my $i = SIZE - 1; $i > 0; $i--) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 55998 | my $n = $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 55998 | my $limit = int(4294967296 / $n) * $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 55998 | my $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 55998 | ▶ | do { $word = $next->() } while $word >= $limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 55998 | my $j = $word % $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 55998 | @order[$i, $j] = @order[$j, $i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2074 | return \@order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||