| 1 | package Game::Senet::Sticks; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 68 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 68 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 68 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 68 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 68 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 68 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 68 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 68 | our @EXPORT_OK = qw(throw_for light_of roll_of roll_for extra_throw); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 68 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1678334 | ▶ | sub throw_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_for: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1678334 | my ($seed, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 1678334 | ▶ | Carp::croak('Game::Senet::Sticks: throw_for wants a seed') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $seed and length $seed
MC/DC100%2/2
defined $seed and length $seed
defined $seed
length $seed
Truth table100%3/3
A and B
A= defined $seedB= length $seed
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | unless defined $seed && length $seed; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 1678332 | ▶ | Carp::croak('Game::Senet::Sticks: a throw number is a non-negative integer') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $n and $n =~ /\A\d+\z/
MC/DC100%2/2
defined $n and $n =~ /\A\d+\z/
defined $n
$n =~ /\A\d+\z/
Truth table100%3/3
A and B
A= defined $nB= $n =~ /\A\d+\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | unless defined $n && $n =~ /\A\d+\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 1678329 | my $bytes = "$seed"; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1678329 | ▶ | Carp::croak('Game::Senet::Sticks: a seed is bytes, and that one holds a character above 255') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | unless utf8::downgrade($bytes, 1); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 1678328 | my $byte = unpack 'C', Digest::SHA::sha256($bytes . "throw:$n"); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 1678328 | return [ map { ($byte >> $_) & 1 } 0 .. 3 ]; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1677632 | ▶ | sub light_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
light_of: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1677632 | my ($sticks) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1677632 | ▶ | Carp::croak('Game::Senet::Sticks: light_of wants the four sticks') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $sticks eq "ARRAY" and @$sticks == 4
MC/DC100%2/2
ref $sticks eq "ARRAY" and @$sticks == 4
ref $sticks eq "ARRAY"
@$sticks == 4
Truth table100%3/3
A and B
A= ref $sticks eq "ARRAY"B= @$sticks == 4
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | unless ref $sticks eq 'ARRAY' && @$sticks == 4; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1677630 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1677630 | $count += $_ for @$sticks; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1677630 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2220511 | ▶ | sub roll_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
roll_of: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2220511 | my ($throw) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 2220511 | ▶ | Carp::croak('Game::Senet::Sticks: a throw is a count of light faces, 0 to 4') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $throw and $throw =~ /\A[0-4]\z/
MC/DC50%1/2
defined $throw and $throw =~ /\A[0-4]\z/
defined $throw
$throw =~ /\A[0-4]\z/
Truth table66%2/3
A and B
A= defined $throwB= $throw =~ /\A[0-4]\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | unless defined $throw && $throw =~ /\A[0-4]\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 2220510 | ▶ | return $throw == 0 ? 5 : $throw + 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 354142 | ▶ | sub roll_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
roll_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 354142 | my ($seed, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 354142 | return roll_of(light_of(throw_for($seed, $n))); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 818373 | ▶ | sub extra_throw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extra_throw: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 818373 | my ($roll) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 818373 | ▶ | Carp::croak('Game::Senet::Sticks: a roll is a number of houses, 1 to 5') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $roll and $roll =~ /\A[1-5]\z/
MC/DC50%1/2
defined $roll and $roll =~ /\A[1-5]\z/
defined $roll
$roll =~ /\A[1-5]\z/
Truth table66%2/3
A and B
A= defined $rollB= $roll =~ /\A[1-5]\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | unless defined $roll && $roll =~ /\A[1-5]\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 818372 | ▶ | return ($roll == 1 || $roll == 4 || $roll == 5) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$roll == 1 or $roll == 4 or $roll == 5
$roll == 1 or $roll == 4
MC/DC100%3/3
$roll == 1 or $roll == 4 or $roll == 5
$roll == 1
$roll == 4
$roll == 5
Truth table100%4/4
A or B or C
A= $roll == 1B= $roll == 4C= $roll == 5
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 68 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||||||||||||||||