Crates.io | riichi-decomp |
lib.rs | riichi-decomp |
version | 0.1.0 |
source | src |
created_at | 2022-10-08 08:39:41.499717 |
updated_at | 2022-10-08 08:39:41.499717 |
description | Japanese Riichi Mahjong Waiting Hand Decomposition |
homepage | |
repository | https://github.com/summivox/riichi-rs |
max_upload_size | |
id | 683408 |
size | 52,722 |
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:
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.
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 riichi_decomp::*;
use riichi_elements::prelude::*;
let mut decomposer = Decomposer::new();
let tile_set = TileSet34::from_iter(tiles_from_str("1112345678999m"));
let result = WaitSet::from_tile_set(&mut decomposer, &tile_set);
assert_eq!(result.waiting_tiles.0, 0b111111111);
assert_eq!(result.regular.len(), 15);
assert_eq!(result.irregular, None);
Note that a [Decomposer
] instance can be reused to analyze different hands.
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).