Skip to main content

Python bindings for xiangting

Project description

xiangting-py

Python bindings for xiangting.

See also xiangting for more information.

Documentation:

Installation

There are 3 options to install this library:

Option 1: Install from PyPI

pip install xiangting

Option 2: Install from wheel

  1. Download the wheel file for your platform from the releases page.
  2. Run the following command:
pip install PATH/TO/xiangting-{version}-{python tag}-{abitag}-{platform tag}.whl

Replace PATH/TO/xiangting-{version}-{python tag}-{abitag}-{platform tag}.whl with the actual path to the wheel file on your system.

Option 3: Build from source

Requires cargo:

xiangting-py$ pip install .

Usage

The hand is represented as an array of list[int], where each element represents the count of a specific tile. The correspondence between the index and the tile is shown in the table below.

Index 0 1 2 3 4 5 6 7 8
Tile 1m 2m 3m 4m 5m 6m 7m 8m 9m
Index 9 10 11 12 13 14 15 16 17
Tile 1p 2p 3p 4p 5p 6p 7p 8p 9p
Index 18 19 20 21 22 23 24 25 26
Tile 1s 2s 3s 4s 5s 6s 7s 8s 9s
Index 27 28 29 30 31 32 33
Tile East (1z) South (2z) West (3z) North (4z) White (5z) Green (6z) Red (7z)

Calculates the replacement number, which is equal to the deficiency number (a.k.a. xiangting number, 向聴数) + 1.

from xiangting import calculate_replacement_number

# 123m456p789s11222z
hand_14 = [
    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
]

replacement_number = calculate_replacement_number(hand_14, None)
assert replacement_number == 0

In the calculation for a hand with melds (副露), the melded tiles can be included or excluded when counting tiles to determine if a hand contains four identical ones.

If melds are excluded (e.g., 天鳳 (Tenhou), 雀魂 (Mahjong Soul)), specify None for fulu_mianzi_list.

If melds are included (e.g., World Riichi Championship, M.LEAGUE), the melds should be included in the fulu_mianzi_list.

from xiangting import (
    ClaimedTilePosition,
    FuluMianzi,
    calculate_replacement_number,
)

# 123m1z (3 melds)
hand_4 = [
    1, 1, 1, 0, 0, 0, 0, 0, 0, # m
    0, 0, 0, 0, 0, 0, 0, 0, 0, # p
    0, 0, 0, 0, 0, 0, 0, 0, 0, # s
    1, 0, 0, 0, 0, 0, 0, # z
]

# 456p 7777s 111z
melds = [
    FuluMianzi.Shunzi(12, ClaimedTilePosition.LOW),
    FuluMianzi.Gangzi(24),
    FuluMianzi.Kezi(27),
    None,
]

replacement_number_wo_melds = calculate_replacement_number(hand_4, None)
assert replacement_number_wo_melds == 1

replacement_number_w_melds = calculate_replacement_number(hand_4, melds)
assert replacement_number_w_melds == 2

In three-player mahjong, the tiles from 2m (二萬) to 8m (八萬) are not used. Additionally, melded sequences (明順子) are not allowed.

from xiangting import (
    calculate_replacement_number,
    calculate_replacement_number_3_player,
)

# 1111m111122233z
hand_13 = [
    4, 0, 0, 0, 0, 0, 0, 0, 0, # m
    0, 0, 0, 0, 0, 0, 0, 0, 0, # p
    0, 0, 0, 0, 0, 0, 0, 0, 0, # s
    4, 3, 2, 0, 0, 0, 0, # z
]

replacement_number_4p = calculate_replacement_number(hand_13, None)
assert replacement_number_4p == 2

replacement_number_3p = calculate_replacement_number_3_player(hand_13, None)
assert replacement_number_3p == 3

License

Copyright (c) Apricot S. All rights reserved.

Licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xiangting-3.0.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

xiangting-3.0.0-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

xiangting-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

xiangting-3.0.0-cp313-cp313-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

xiangting-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

xiangting-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

xiangting-3.0.0-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

xiangting-3.0.0-cp313-cp313-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

xiangting-3.0.0-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

xiangting-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

xiangting-3.0.0-cp312-cp312-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

xiangting-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

xiangting-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

xiangting-3.0.0-cp312-cp312-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

xiangting-3.0.0-cp312-cp312-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file xiangting-3.0.0.tar.gz.

File metadata

  • Download URL: xiangting-3.0.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.1

File hashes

Hashes for xiangting-3.0.0.tar.gz
Algorithm Hash digest
SHA256 0e3e565afcd9638a09d98565fba866a227482d2454d728479ef32ca03d91e494
MD5 74c7946b2afcae18bd7a12cbc083bae3
BLAKE2b-256 014de4768fa93398f0779bae5a59a7e5ba6c335f8f07973d674eb2d1776ca67e

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8fe8a8cd05b368a1032b609c9794ec186c881d434a95d00b2e12a1ab7d7c38d1
MD5 212b00bc7425de2773dba929f5630cee
BLAKE2b-256 1907410b4195e15dc05e03ebec3436767f8a3a17a9bef967d81ccb5cf1a47be7

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9d9afaae5d1f3a3f8e83f0ccdddd1907bfd3521cc74aadf70cd6db1b463e6a3c
MD5 6ab09ae5ff5ae0a4e79c3a9fbab58ed8
BLAKE2b-256 06eb67f13b279614fa33842d9af6254cf7522eb8c9fac3bda71cf4065519905d

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2ae47d3a5f64c3894150986d0699bf2a2eb2ac6edfd172227d384c710edb61e1
MD5 bd9e0511d061c706c2aeb247a94fa2cc
BLAKE2b-256 9b1ee0e875fb02182c81d31267d55c9f61828260e33cc83a090fa9450c1a3dfd

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54696a9d318a148623f311b7578e1fa6f5f3871d0be22e59ec30902dbb607cc6
MD5 7e79cd204888f9d27051be16546315ac
BLAKE2b-256 0b5cf1738ffed6226e75da5060426d286131428f9486d470ab617848d46bf1d1

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c28bd360f9f80e61b2ea04e4b780e3596440892ea36a3730d5e3efe3e58dcd63
MD5 17735648bce9dcb024faf2fd73a7aa04
BLAKE2b-256 87ac1d7826df7dc8569d085bb720fb1981260cb04fe7c55b0d46514aac993b8a

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e121cbe18bdeba762e90f97b3151bf1a5910120aaf04aed24884b722ff1072f9
MD5 33ce210ce7bdf1b8ddfc581f43910e7c
BLAKE2b-256 04b6b0005cb9cb08351fee19d426d8eb0d742181099012d8c6e535b89f4d7714

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 517bc7cda1fa99a7cfa20e39202667690ad00ff681c06da03acc10cbae57aa87
MD5 5e61bcde2508947b5740120753553098
BLAKE2b-256 504fba31cc76e9ae681c4bd87258a81502d84b780d7ffa7f71eda8726e09868f

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b6ec99c7a0ea4b6c1a022b7dc3013dd9b7e47731699feb418898af96dd8aafc2
MD5 f73a12a44b4d0c1947e2523539f8061f
BLAKE2b-256 ed473111d2c7e364aec2ed3fd5d6d96427504ae859e00728e31ec9f642d485ad

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9e0918b4d7b3c70acb3b9fd90594903ab0b3407db8ec7d533af48f2d1ed7ba2a
MD5 c638dcae1aa766df5cd818c27c0ccbe0
BLAKE2b-256 34dd817a8a1200241c61cbad021a1da2638dca6d5e3d500726b7e2d636c46bd7

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3102200f25d823b920cd5b1b214dafa64f487823a73a8170d2e49327159280ff
MD5 a885e7b3dfb69a21f2903b0398f782ef
BLAKE2b-256 8106342bbc796f92ccf13f6fbad42afb7221ae4c48d84409ea585bdcd768b282

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 968fe09771fc3996e333a56eb2a3ade12a2680e9ceedca6a50483fad92ff14c6
MD5 dec327cb765e0f7d90e3ff8e8ba4f831
BLAKE2b-256 54d41cb85658d6a354d8c3f82b99307994199f9c395962ab7ea26be297a28d71

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 140781e03f48cba968dca349404bd6acf0b9e132a5d4e4c97460f45f67794926
MD5 ab611d3e4f253daf5f81f6dde2053be0
BLAKE2b-256 86c525922bea48a6fe899f5aa26f104790b87f833fbc8de9b7746d0e60f5042f

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 acec2fd7153c3ad9c18700791e7a9e1d1f998489a026f71a2492018a5dd99ad4
MD5 6410ab30a23e49972ee9a67a5518ceaf
BLAKE2b-256 5a456e4555f96adc0f45a9f32327a41f70f08e91a56ce3041384124bcdf94924

See more details on using hashes here.

File details

Details for the file xiangting-3.0.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for xiangting-3.0.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 27ac4bc65c1c8d9ba3d6138fbbace8471707d4eabe03b12ec83717f1b4933fbf
MD5 e547ad89c8a118e63b14c0c33635620e
BLAKE2b-256 035841c907b9fb72d62472eaa3feddc929fcdec3f3682fff1b4d209a9b00d1e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page