| 1 | package Game::Gin::Deck; | ||||||||||||||||||||||||||||
| 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 Digest::SHA (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Game::Gin::Card (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 12 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 12 | 12 | our @EXPORT_OK = qw(order_for deal_for HAND_SIZE UPCARD_AT STOCK_AT); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use constant HAND_SIZE => 10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use constant UPCARD_AT => 20; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use constant STOCK_AT => 21; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 24900 | ▶ | sub order_for { | ||||||||||||||||||||||||||
|
Subroutine
order_for: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 24900 | my ($seed, $hand) = @_; | |||||||||||||||||||||||||||
| 20 | 24900 | ▶ | die "order_for wants a 32-byte seed\n" unless defined $seed && length $seed == 32; | ||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||
| 21 | 24898 | ▶ | die "order_for wants a hand number from 1\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $hand and $hand =~ /\A[1-9][0-9]*\z/
MC/DC50%1/2
defined $hand and $hand =~ /\A[1-9][0-9]*\z/
defined $hand
$hand =~ /\A[1-9][0-9]*\z/
Truth table66%2/3
A and B
A= defined $handB= $hand =~ /\A[1-9][0-9]*\z/
| |||||||||||||||||||||||||||||
| 22 | unless defined $hand && $hand =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 24895 | my ($counter, @words) = (0); | |||||||||||||||||||||||||||
| 25 | 1269645 | ▶ | my $next = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 26 | 1269645 | ▶ | unless (@words) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 174265 | @words = unpack 'N8', Digest::SHA::sha256($seed . "hand:$hand:" . $counter++); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 1269645 | return shift @words; | |||||||||||||||||||||||||||
| 30 | 24895 | }; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 24895 | my @order = (1 .. Game::Gin::Card::CARDS); | |||||||||||||||||||||||||||
| 33 | 24895 | ▶ | for (my $i = $#order; $i > 0; $i--) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 1269645 | my $n = $i + 1; | |||||||||||||||||||||||||||
| 35 | 1269645 | my $limit = int(4294967296 / $n) * $n; | |||||||||||||||||||||||||||
| 36 | 1269645 | my $word; | |||||||||||||||||||||||||||
| 37 | 1269645 | ▶ | do { $word = $next->() } while $word >= $limit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1269645 | my $j = $word % $n; | |||||||||||||||||||||||||||
| 39 | 1269645 | @order[ $i, $j ] = @order[ $j, $i ]; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 24895 | return \@order; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2070 | ▶ | sub deal_for { | ||||||||||||||||||||||||||
|
Subroutine
deal_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 2070 | my ($seed, $hand) = @_; | |||||||||||||||||||||||||||
| 46 | 2070 | my $order = order_for($seed, $hand); | |||||||||||||||||||||||||||
| 47 | return { | ||||||||||||||||||||||||||||
| 48 | 2070 | non_dealer => [ @{$order}[ 0 .. HAND_SIZE - 1 ] ], | |||||||||||||||||||||||||||
| 49 | 2070 | dealer => [ @{$order}[ HAND_SIZE .. 2 * HAND_SIZE - 1 ] ], | |||||||||||||||||||||||||||
| 50 | upcard => $order->[UPCARD_AT], | ||||||||||||||||||||||||||||
| 51 | 2070 | stock => [ @{$order}[ STOCK_AT .. $#$order ] ], | |||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 12 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||