NAME
Game::Mahjong::Shanten - how far a hand is from ready, and what it accepts
VERSION
Version 0.01
SYNOPSIS
my $n = Game::Mahjong::Shanten::shanten($hand); # -1 complete, 0 ready, 1, 2 ...
my %f = %{ Game::Mahjong::Shanten::forms($hand) }; # per form
my @accepts = Game::Mahjong::Shanten::ukeire($hand); # the kinds that lower it
my $after = Game::Mahjong::Shanten::after_discard($hand, $kind);
DESCRIPTION
The distance to ready is C (mahjong_shanten.c, its interface in include/mahjong_shanten.h): the bot asks it for every candidate discard and every accepting tile, which is a few hundred evaluations a move, and a suit's nine counts are reduced once to their groupings and remembered. This module is its Perl face over a Game::Mahjong::Hand.
The number
-1 is complete, 0 is ready, and so on; the minimum over four sets and a pair, seven pairs, thirteen orphans and the honours-and-knitted singles. For a thirteen-tile hand the number is at least 0; for a fourteen it can be -1.
FUNCTIONS
shanten
The number for a hand.
forms
The number for each form, keyed standard, seven_pairs, thirteen_orphans, honours_knitted; a form the hand cannot take is 99.
ukeire
The kinds whose addition lowers the number, ascending.
after_discard
The number the hand would have after discarding a kind it holds.
SEE ALSO
Game::Mahjong::Search, Game::Mahjong::Decompose
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under the Artistic License 2.0.