| 1 | package Game::Mahjong::Shanten; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use Game::Mahjong::Tiles; | ||
| 8 | |||
| 9 | our $VERSION = '0.04'; | ||
| 10 | |||
| 11 | our @FORMS = qw(standard seven_pairs thirteen_orphans honours_knitted); | ||
| 12 | |||
| 13 | sub shanten { | ||
| 14 | my ($hand) = @_; | ||
| 15 | return _shanten($hand->counts, $hand->meld_count); | ||
| 16 | } | ||
| 17 | |||
| 18 | sub forms { | ||
| 19 | my ($hand) = @_; | ||
| 20 | my $f = _forms($hand->counts, $hand->meld_count); | ||
| 21 | return { map { $FORMS[$_] => $f->[$_] } 0 .. $#FORMS }; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub ukeire { | ||
| 25 | my ($hand) = @_; | ||
| 26 | return @{ _ukeire($hand->counts, $hand->meld_count) }; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub after_discard { | ||
| 30 | my ($hand, $kind) = @_; | ||
| 31 | my $counts = [ @{ $hand->counts } ]; | ||
| 32 | die 'Game::Mahjong::Shanten: the hand does not hold ' . Game::Mahjong::Tiles::code_of($kind) | ||
| 33 | unless $counts->[$kind]; | ||
| 34 | $counts->[$kind]--; | ||
| 35 | return _shanten($counts, $hand->meld_count); | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |