| 1 | package Game::Sternhalma::Layout; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 31 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 31 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 31 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 31 | our @EXPORT_OK = qw(seat_counts points home_of pieces_ok why_not); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # W's layouts. Points are 0 to 5 clockwise from the top tip; seat order is | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # turn order, which is clockwise too. t/24-layout.t holds this table to the | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # engine's own. | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 31 | my %POINTS = ( | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 => [0], | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 => [0, 3], | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 => [0, 2, 4], | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 => [0, 1, 3, 4], | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 => [0, 1, 2, 3, 4, 5], | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub seat_counts { (2, 3, 4, 6) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seat_counts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 23161 | ▶ | sub points { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
points: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 23161 | my ($seats) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 23161 | ▶ | my $p = defined $seats ? $POINTS{$seats} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 23161 | ▶ | return $p ? @$p : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1718 | ▶ | sub home_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
home_of: called CC=4 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1718 | my ($seats, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1718 | my @p = points($seats); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1718 | ▶ | return undef unless defined $seat && $seat =~ /\A[0-9]+\z/ && $seat < @p; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < @p
defined $seat and $seat =~ /\A[0-9]+\z/u
MC/DC0%0/3
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < @p
defined $seat
$seat =~ /\A[0-9]+\z/u
$seat < @p
Truth table25%1/4
A and B and C
A= defined $seatB= $seat =~ /\A[0-9]+\z/uC= $seat < @p
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1718 | return ($p[$seat] + 3) % 6; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 15 | ▶ | sub pieces_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pieces_ok: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 15 | my ($seats, $pieces) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 15 | ▶ | return defined why_not($seats, $pieces) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Why a game of that many seats and pieces cannot be, or undef when it can. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # One seat is a crossing alone, which a game is not; it is built only on | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # request (Game::Sternhalma's `solo`). | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 265 | ▶ | sub why_not { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
why_not: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 265 | my ($seats, $pieces, $solo) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 265 | ▶ | return 'the seat count must be a number' unless defined $seats && $seats =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $seats and $seats =~ /\A[0-9]+\z/u
MC/DC50%1/2
defined $seats and $seats =~ /\A[0-9]+\z/u
defined $seats
$seats =~ /\A[0-9]+\z/u
Truth table66%2/3
A and B
A= defined $seatsB= $seats =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 262 | ▶ | return 'the piece count must be a number' unless defined $pieces && $pieces =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pieces and $pieces =~ /\A[0-9]+\z/u
MC/DC0%0/2
defined $pieces and $pieces =~ /\A[0-9]+\z/u
defined $pieces
$pieces =~ /\A[0-9]+\z/u
Truth table33%1/3
A and B
A= defined $piecesB= $pieces =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 262 | ▶ | return 'five cannot play: one seat would have nobody opposite' if $seats == 5; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 255 | ▶ | return 'one seat is a crossing alone, not a game' if $seats == 1 && !$solo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$seats == 1 and not $solo
MC/DC100%2/2
$seats == 1 and not $solo
$seats == 1
not $solo
Truth table100%3/3
A and not(B)
A= $seats == 1B= not $solo
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 252 | ▶ | return "sternhalma is for 2, 3, 4 or 6 seats, not $seats" unless $POINTS{$seats}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 249 | ▶ | return "a seat has 10 pieces, or 15, not $pieces" unless $pieces == 10 || $pieces == 15; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pieces == 10 or $pieces == 15
MC/DC100%2/2
$pieces == 10 or $pieces == 15
$pieces == 10
$pieces == 15
Truth table100%3/3
A or B
A= $pieces == 10B= $pieces == 15
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 247 | ▶ | return "fifteen pieces cannot sit at $seats seats: neighbouring points would share a hole" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pieces == 15 and $seats > 3
MC/DC100%2/2
$pieces == 15 and $seats > 3
$pieces == 15
$seats > 3
Truth table100%3/3
A and B
A= $pieces == 15B= $seats > 3
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | if $pieces == 15 && $seats > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 239 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||||||||||||||||