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.2.1.tar.gz (8.7 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.2.1-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

xiangting-3.2.1-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.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

xiangting-3.2.1-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.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

xiangting-3.2.1-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.2.1.tar.gz.

File metadata

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

File hashes

Hashes for xiangting-3.2.1.tar.gz
Algorithm Hash digest
SHA256 c2aefa922b23c090d74323851e371aabead7e63412a3b771ede8a7c101ee84cd
MD5 3cae5ecd817040ebfe39675873e8d09a
BLAKE2b-256 984f3132f132b6aa7990835d37c1e6a79350ff858be24257889d9d4d6e53a1dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c7cae21b288d9ec6967f41ec7e33e6cdebf438639542a6194b77934d7b0bf0a5
MD5 6c547a2722a07848671866af7398cacd
BLAKE2b-256 47deddca44b016e853c8da578aebe34e3bc277a43096c3b62dd0145d6d60350e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7d7cbaaf7807a455a3596433ae12468ce581eda35e9da50b29bc53be07064c21
MD5 50040cdfd2dfedfa8cd77ac361553b66
BLAKE2b-256 441861311079517d477e2a906f0500c0cea1d3f8b7b7ce6bc0a8b92251b33f94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3190dc188ff67ef1bc20b3cb9e8357e4b86fc185794adfe03891f4bb78899d80
MD5 21659bdf62b2f80cb0e2aeb16e3e1528
BLAKE2b-256 df441c050b69f662509ae50c345cd7fba137886183e354c33febfa5614a65b49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34d09de1ab30b2de78710de6b35f3e167177fff862e8bbd32ce871d1463d78d8
MD5 3602f6daa24312433d3b52d24146f41d
BLAKE2b-256 b6f247a1394a8b64465ac5cd57424ebca5e6be516f87dfffbd74f598585811ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3e118ffe0e9f51d65e6f6b41586e257994fd2fdd146586176bae6529ced236ad
MD5 1369182b018ad33dc0854963e59784d8
BLAKE2b-256 9c2a800ea348a0e53b6bc455f08c189baeb552865a5663708e390f22252b47a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 faa360223e3a67c30674ae12e606ef37447f5b61ff8fc4f8d6306cf720a0cc87
MD5 3c973925ae111ec7ebd095a507ae9a71
BLAKE2b-256 36799ce4e6472243c99aebbcef806bf7be840aa174393e208e93e0071fddf99f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ca2dffeedb8a933e82319f884703364e15fada2f876dca08ad3f041db58e3bdf
MD5 3da0b78cab2dc393c1a10977167a1b32
BLAKE2b-256 b18d47e94effd2d36ffd3b1bb6d32e9143a68b2d8acf92d87d94d5dc5a371eb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cc945bd3a7faab6207075891ef8b5ee763759932957abe8dce3f164d1074cb4d
MD5 503752d299b59480db77237770c874e5
BLAKE2b-256 e8b1f1f8e9fa941255f9cad858320e1c50d321223a31cf239d62d46e5b3ccf08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 23043d6f057aaa5a3305e6e2b16dbbac0a7aa84bdac87dc1cd88625d37f79279
MD5 d51daee44d71fe04273a572d0dd6e167
BLAKE2b-256 64b1736aa57ef9c84833068a6fddd6bebdcb5f7f8c8dd6df2ea6f6340e7e9525

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0d8de0899cf54a641f6999bb82cdc4780cf4fb8ab3819fc8c107d59f6832b321
MD5 d728345b063811ffa1296f2017192012
BLAKE2b-256 c2e20d443e0e4962a839fb87b7678c93b027503d902d1c7b9dc69b0bcd75a900

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 165e0e18de5346e5c5b47e605964ee93f1622d64fe44898ca712e39f45c4841d
MD5 cef60744cde6f5bf0e8af01b9b046a7a
BLAKE2b-256 b018062d10f2846e93f9291b93d637b3379c41999c96c64e283b87090f4e3075

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 efc941988893823f3ea8f79c1bcfac5f06cf8bf5d872ae4b96c67cd397d0c725
MD5 6bbaaa6dfa01854e7c476694ecfaffe2
BLAKE2b-256 9624a6858752ee983a91addebd781f1152b56240bc119938c242fc012301ae79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0927c33e6377ce1e1aa243ade7a92731f418e2a1e9be6caba4d1d15284bbb2d4
MD5 779eb640b796541da20acf7f04c21def
BLAKE2b-256 365672e388a0bfcac1dbd9ba8867440cf0a0cb336abc89d0d435c639068965ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5380fc39714e8c5c5a3cc0f77a58758160a79f87119f944413f6a12f7e2e771b
MD5 5d5ed1488c5654788d6cd9d8dd22d125
BLAKE2b-256 3023e3ced5508cc0cbd31df4d473afe8c5ce50b6a0588f97207f0d77d4998e02

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