Crate xiangting

Source
Expand description

A library for calculating the deficiency number (a.k.a. xiangting number, 向聴数).

This library is based on the algorithm in Cryolite’s Nyanten.
However, it introduces the following additional features:

  • Supports rules that include and exclude melded tiles when determining if a hand contains four identical tiles.
  • Supports three-player mahjong.

§Example

// 123m456p789s11222z
let hand_14: [u8; 34] = [
    1, 1, 1, 0, 0, 0, 0, 0, 0, // m
    0, 0, 0, 1, 1, 1, 0, 0, 0, // p
    0, 0, 0, 0, 0, 0, 1, 1, 1, // s
    2, 3, 0, 0, 0, 0, 0, // z
];

let replacement_number = calculate_replacement_number(&hand_14, &None);
assert_eq!(replacement_number?, 0u8);

Enums§

ClaimedTilePosition
Position of the claimed tile in the melded sequence. Used in FuluMianzi::Shunzi.
FuluMianzi
副露面子: Meld.
InvalidBingpaiError
Errors that occur when an invalid pure hand (純手牌) is provided.
InvalidFuluMianziError
Errors that occur when an invalid meld is provided.
InvalidShoupaiError
Errors that occur when an invalid hand (手牌) is provided.

Functions§

calculate_replacement_number
Calculates the replacement number (= xiangting number + 1) for a given hand. This function is for 4-player mahjong.
calculate_replacement_number_3_player
Calculates the replacement number (= xiangting number + 1) for a given hand. This function is for 3-player mahjong.

Type Aliases§

Bingpai
兵牌: Hand excluding melds (a.k.a. pure hand, 純手牌).
FuluMianziList
List of melds.
Tile
牌: Tile.