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.1.2.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.1.2-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

xiangting-3.1.2-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.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

xiangting-3.1.2-cp313-cp313-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

xiangting-3.1.2-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.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

xiangting-3.1.2-cp312-cp312-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

xiangting-3.1.2-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.1.2.tar.gz.

File metadata

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

File hashes

Hashes for xiangting-3.1.2.tar.gz
Algorithm Hash digest
SHA256 9fee59eed07dbe5b9fa806f41e147d0cecf5a3dcf3053e6df4727b60e7168c70
MD5 17500e603134799046b4033d511ccb71
BLAKE2b-256 0581b904c398ef9e4c088d6c65f294d21ef0f18cdbbae0b0d7cab7d7f120003f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 71737d1181af118ac94b64ebacfebf3cfd023da1f1bfff8d40eb197c6414ce68
MD5 96c6ce52f3ed1fa8c0e3c81c410ebbdd
BLAKE2b-256 075c0981a75499eec3b2d2efacc410af913c8c6edcef4044d3b58e39c9e80ffc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2e0b07d9d4175ae6d219b21e4829cf03cec41e0fe4f16ce8e4dfd31673212aeb
MD5 350168e2c7cec8cfd647f133bdcfc858
BLAKE2b-256 4173b662a7359a4c09b322e7469df0b913a0e61d131d3b82f660606b50a00d6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 e819f777f5b5f4677f8a3aafed631d53d4a19b03099a3e946998b6f31fee7192
MD5 284c347efe8c51fb5619f34b31c67740
BLAKE2b-256 88a17db9e7f876971a998bf8f3e5bedc52d87eb73b06d20851fdaa887fc8acef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5047f3a951dbe7c4ba1f3dbe9c479afb4c3d9fdcf5a93b880db9308b1056f788
MD5 6da01c24a4effdf55628de5e712dbdd8
BLAKE2b-256 6ef48016820f438215101a2f097ce737786142c6bd6e386e9726ab43d1d34419

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e1b1aba262e37e55dc2609e0d70b587d98491dbcabddcdcc9410cf6c4edd443a
MD5 faf3f001e358b6c1f7fe6202e0157522
BLAKE2b-256 124e9862998299725fe9a1059ac7e51b871dd5813e7a620bc8aefaac965ace31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb845370738d2d0ebd01f122d444b9364deb7dba34bd75a126c3379166801a3e
MD5 0788ef188789191c2232b24872931aba
BLAKE2b-256 fcdf51765e3a9f1aa5fd515ee7638c5d12e12a690dd639026ac990a6d91483ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b51717837c836f484121062a4da6742c3a544d2b11580bbbadb8b5bccb0c4f3c
MD5 6e70bb14345b1e54dc52c1c7f2d81f97
BLAKE2b-256 b6ca914914152313ef88ecd7421abf04e30b024d51caecba0c2514196c4807e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 48ca2045964117c117213cff282f1251ead59d692a698d22b849c106aff9ca34
MD5 90c74b5ab7fe5d4060113c5b8a4a1491
BLAKE2b-256 276d3af9ccbe6b427ade2a38c2eceef2f83a6db43fc55ef29609a0315257a7c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 929550350fa35e2f3b8f752b34125867efcb3bfe8e66de1790a7b3459f8ec37f
MD5 48e65bc67f6e3746745fcbf4ed99e461
BLAKE2b-256 6f70e4539de85a9ab758bafbe424cc38f34e1cdc4cc08b5c01d25de4dc129604

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 8f12087aaab98bb9957664a330f9867ab660cfdfef908c6a4af6ccf4fd14eba5
MD5 3b95329dcea978a68453e2f4b481448d
BLAKE2b-256 56da1cabe2260fe073f560bf09be129d4f0488665836d9bf7e7ae3988b6a264e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64e00f1f12151aab2fd37d5f72b0cc250de7d2bf01e25dd70bbd9d8a1e994a89
MD5 e56221343a1281cfe24e32734ab55072
BLAKE2b-256 caa32b95b6c8009a0e18fb9b92daeec833edb4a7e2e702a4cb71467c04dd6bda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 72966357a7eede3e9e0b3280ae6ff86ab2b486a3d4f10b0256b9aee16162bb14
MD5 52d9c2dd2a20e86898ff31d961692321
BLAKE2b-256 d6243f72895379d14730c42bcd289c2877a0e5b0376f51b17403863964db3153

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0c8899010269de019cdeab32b9a5ae6510c3cd67508d995dc288218db6fc3b5
MD5 12b6a225a680f9ea64ca5fed5b733cf0
BLAKE2b-256 b8820c561208a201f6e05e0d96f3bbc0de96f326d8b253d01856628d5dad7c08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fa476f8544a00bb9907c2ee482d75105e867cbbdc153a046f9e0e9d77066e135
MD5 bb19aade433143358a9a19ac07442189
BLAKE2b-256 396ce21a7df1f8f96271ba56e57cef459b47434a6a68759b7a9b38a42b845c27

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