| 1 | package Game::Mahjong::Tiles; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 34 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 34 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 34 | ▶ | use constant KINDS => 34; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 34 | ▶ | use constant BONUS => 8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 34 | ▶ | use constant PATTERNS => 42; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 34 | ▶ | use constant PER_KIND => 4; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 34 | ▶ | use constant TILES => 144; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 34 | my @RANK = qw(one two three four five six seven eight nine); | |||||||||||||||||||||||||||||||
| 16 | 34 | my %SUIT = (m => 'characters', p => 'dots', s => 'bamboo'); | |||||||||||||||||||||||||||||||
| 17 | 34 | my @WIND = qw(east south west north); | |||||||||||||||||||||||||||||||
| 18 | 34 | my @DRAGON = qw(red green white); | |||||||||||||||||||||||||||||||
| 19 | 34 | my @FLOWER = qw(plum orchid bamboo chrysanthemum); | |||||||||||||||||||||||||||||||
| 20 | 34 | my @SEASON = qw(spring summer autumn winter); | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 316 | ▶ | sub set { | ||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 23 | 316 | my @set; | |||||||||||||||||||||||||||||||
| 24 | 316 | for my $kind (1 .. KINDS) { | |||||||||||||||||||||||||||||||
| 25 | 10744 | push @set, ($kind) x PER_KIND; | |||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | 316 | push @set, (KINDS + 1) .. PATTERNS; | |||||||||||||||||||||||||||||||
| 28 | 316 | return @set; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub kinds { return (1 .. KINDS) } | ||||||||||||||||||||||||||||||
|
Subroutine
kinds: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub patterns { return (1 .. PATTERNS) } | ||||||||||||||||||||||||||||||
|
Subroutine
patterns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 51 | ▶ | sub name_of { | ||||||||||||||||||||||||||||||
|
Subroutine
name_of: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 36 | 51 | my ($kind) = @_; | |||||||||||||||||||||||||||||||
| 37 | 51 | my $code = code_of($kind); | |||||||||||||||||||||||||||||||
| 38 | 51 | ▶ | if (my $suit = suit_of($kind)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 30 | return $RANK[ rank_of($kind) - 1 ] . ' of ' . $SUIT{$suit}; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | 21 | ▶ | return $WIND[ wind_index($kind) ] . ' wind' if is_wind($kind); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 16 | ▶ | return $DRAGON[ dragon_index($kind) ] . ' dragon' if is_dragon($kind); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | 12 | ▶ | return $FLOWER[ bonus_index($kind) ] if is_flower($kind); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 5 | return $SEASON[ bonus_index($kind) ]; | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | sub suit_name { | ||||||||||||||||||||||||||||||
|
Subroutine
suit_name: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 48 | 2 | my ($letter) = @_; | |||||||||||||||||||||||||||||||
| 49 | die "Game::Mahjong::Tiles: there is no suit '" . (defined $letter ? $letter : 'undef') . "'" | ||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | unless defined $letter && $SUIT{$letter}; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $letter and $SUIT{$letter}
MC/DC50%1/2
defined $letter and $SUIT{$letter}
defined $letter
$SUIT{$letter}
Truth table66%2/3
A and B
A= defined $letterB= $SUIT{$letter}
| |||||||||||||||||||||||||||||||||
| 51 | 1 | return $SUIT{$letter}; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | sub next_in_suit { | ||||||||||||||||||||||||||||||
|
Subroutine
next_in_suit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 55 | 4 | my ($kind) = @_; | |||||||||||||||||||||||||||||||
| 56 | 4 | my $rank = rank_of($kind); | |||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | return undef unless defined $rank && $rank < 9; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $rank and $rank < 9
MC/DC100%2/2
defined $rank and $rank < 9
defined $rank
$rank < 9
Truth table100%3/3
A and B
A= defined $rankB= $rank < 9
| |||||||||||||||||||||||||||||||||
| 58 | 1 | return $kind + 1; | |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 34 | 1; | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||||||