riichi-decomp

Crates.ioriichi-decomp
lib.rsriichi-decomp
version0.1.0
sourcesrc
created_at2022-10-08 08:39:41.499717
updated_at2022-10-08 08:39:41.499717
descriptionJapanese Riichi Mahjong Waiting Hand Decomposition
homepage
repositoryhttps://github.com/summivox/riichi-rs
max_upload_size
id683408
size52,722
Yin Zhong (summivox)

documentation

README

Japanese Riichi Mahjong Waiting Hand Decomposition

Crates.io docs.rs

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.

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 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.

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).

Commit count: 107

cargo fmt