| 1 | package Game::Mahjong::Decompose; | ||||||||||||
| 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 | ▶ | use Game::Mahjong::Tiles; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 34 | our $VERSION = '0.03'; | |||||||||||
| 10 | |||||||||||||
| 11 | 34 | our %FORM = ( | |||||||||||
| 12 | 1 => 'standard', | ||||||||||||
| 13 | 2 => 'seven_pairs', | ||||||||||||
| 14 | 3 => 'thirteen_orphans', | ||||||||||||
| 15 | 4 => 'honours_knitted', | ||||||||||||
| 16 | 5 => 'knitted_straight', | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 25080 | ▶ | sub decompose { | ||||||||||
|
Subroutine
decompose: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 20 | 25080 | my ($hand, $winning) = @_; | |||||||||||
| 21 | 25080 | ▶ | my $splits = _decompose($hand->counts, $hand->meld_count, $winning // 0); | ||||||||||
|
Condition100%2/2
$winning // 0
MC/DC100%1/1
$winning // 0
$winning
Truth table100%2/2
A
A= $winning
| |||||||||||||
| 22 | 25080 | ▶ | die 'Game::Mahjong::Decompose: more splits than the table holds' unless defined $splits; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | |||||||||||||
| 24 | my @melded = map { | ||||||||||||
| 25 | { | ||||||||||||
| 26 | kind => $_->kind, | ||||||||||||
| 27 | 7524 | ▶ | tiles => [ @{ $_->tiles } ], | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | concealed => $_->concealed ? 1 : 0, | ||||||||||||
| 29 | melded => 1, | ||||||||||||
| 30 | } | ||||||||||||
| 31 | 25080 | } @{ $hand->melds }; | |||||||||||
| 32 | |||||||||||||
| 33 | 25080 | for my $split (@$splits) { | |||||||||||
| 34 | 2199 | $_->{concealed} = 1, $_->{melded} = 0 for @{ $split->{sets} }; | |||||||||||
| 35 | 2199 | push @{ $split->{sets} }, @melded; | |||||||||||
| 36 | } | ||||||||||||
| 37 | 25080 | return @$splits; | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 18 | ▶ | sub is_complete { | ||||||||||
|
Subroutine
is_complete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 41 | 18 | my ($hand) = @_; | |||||||||||
| 42 | 18 | return _is_complete($hand->counts, $hand->meld_count); | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 38621 | ▶ | sub waits { | ||||||||||
|
Subroutine
waits: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 46 | 38621 | my ($hand) = @_; | |||||||||||
| 47 | 38621 | ▶ | die 'Game::Mahjong::Decompose: waits are asked of a hand between turns, not of one holding a fourteenth' | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | unless $hand->total == 13; | ||||||||||||
| 49 | 38620 | return @{ _waits($hand->counts, $hand->meld_count) }; | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 34 | 1; | |||||||||||
| 53 | |||||||||||||
| 54 | __END__ | ||||||||||||