Japanese Riichi Mahjong Waiting Hand Decomposition
In Japanese Riichi Mahjong, a closed hand with 3N+1 tiles is considered "waiting" (1 tile away from winning) if it matches any of the following:
- One or more regular / standard waiting pattern(s) --- the hand is decomposed into three-tile groups and a pair (either complete or waiting).
- An irregular waiting pattern --- the hand matches Seven Pairs or Thirteen Orphans.
This crate can be used to analyze a 3N+1 closed hand and determine all possible waiting patterns for it. For each pattern, the waiting tile, pattern kind, and details of decomposition (for regular patterns) are calculated.
Important note: The algorithm depends on lookup tables that must be generated before a hand can be analyzed.
If feature static-lut is enabled, this will be done during compile time using
build.rs. Otherwise, the tables will be lazily generated when a [Decomposer] is first instantiated
during runtime.
Example
The included CLI (src/main.rs) prints all possible waiting patterns for the hands supplied through command-line
arguments or the standard input. It can be invoked using cargo run.
It basically does the following (using the classic Pure Nine Gates example):
use *;
use *;
let mut decomposer = new;
let tile_set = from_iter;
let result = from_tile_set;
assert_eq!;
assert_eq!;
assert_eq!;
Note that a [Decomposer] instance can be reused to analyze different hands.
Optional Features
serde (default: enabled)
Provides serialization for all results. Deserialization is not implemented as these are intended to be generated internally only.
static-lut (default: enabled)
Generates lookup tables required for computations during compile time (instead of lazily during runtime).