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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

File metadata

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

File hashes

Hashes for xiangting-2.0.6.tar.gz
Algorithm Hash digest
SHA256 65f5ee479a827717bdc26644d6d7f25732fd45f90ba606aa4623c82d9cc35ab2
MD5 1647d498c05ec8b627c162b3d73ce66c
BLAKE2b-256 967504ef519154a91e9dd93f3581f7bd0dbb59cb2518e23093bcc2e78787ea44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3fdb827fd4e2907b6223b10e028d5978020a745d1aacd4e611347c49df22eadc
MD5 8c383c38be6c21f8b5028c2e4035ce41
BLAKE2b-256 fc7d4d10684c4f43a85ba34a1f807c38ae4d905495e7376a76dda3889ed003e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dc5978ccf4e58f2b3a9fad3d3cb79228997853b9e28279d2c564793c212a4c07
MD5 7421764f0d4b79fa7760a826c767f860
BLAKE2b-256 1f1657ef686eed7594bd98435922f855261f7368fb2dd5c54fa4c046254ebc26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 90c13f45519c34bd96450298a797a4f80386a696d8ea09b7e0c4199feece5add
MD5 8f8eed3d7d6889ba49bbe5f659f9701f
BLAKE2b-256 1d7139f9e7dd3503e0c2a3327f470f66016fbb47fb9fed7243a9dd4e648d9544

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1592b94a9ea81d81999376897325968c14334248ef537d1531c4079ee6b94d7a
MD5 ed48509bf1b6a0b768e74b596c1b08a2
BLAKE2b-256 5979e2a7dd362d9d0b99b75810bab59cd565509357a3196cb46a634e41fa5ea3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6a36ee9195216c1f2e44a7cc72397ae313b817e5ea4b15a66ea7c5d03883cdb7
MD5 7b8f1537098bc9f6110d70d2fc4877fd
BLAKE2b-256 f22141919c112db669b0bf695396e53425a283d9aa4bc95b32aacb9c6157dd09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18d346c47d2d0b6092b24dea17b400a4ec89384f11333804d46e77d01da60554
MD5 9cd17bd53f6479e9047c37baf3e0163d
BLAKE2b-256 3d82e2e4f90e95308159d8c211e24fef8edf06768388d2f2a0c3a89ee8143e23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2a924f315c1371acb0d67b87e39eba5e1b1670d42de04e69b1151961d78fc86a
MD5 7b22935f4b413073d88f9559d1ab1010
BLAKE2b-256 ebe5871baa7fe3c609407a8c12f2b1c1ee019812ad2f895ea46075955daa2a0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e0d3ed380ca9e056e0238120e1f8569c8cf911aca87117ea13f507583be4b224
MD5 76b98b7ee10b84c6f948e2afccb839f6
BLAKE2b-256 ccb474098e224f548eafc395026ca9157ee0913e47b4ca351d8967c41ebff207

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 335cb318e78263e244c3d54f8dd8160de1bb31eba6210a1fa1153bf6b3df0218
MD5 7a5bb35a04d683dc675b0422223b0336
BLAKE2b-256 b7dc0b680ae7f84f34a9d8193652b0afc60b2c971531a5fb18f97c7fffad9edf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1cdd844a25f11cb5a966d214c064ba2e85a66689d37ab78ae87e46636c71db0b
MD5 712aff521e7b246f57f27445c1b08905
BLAKE2b-256 dd2f1a560a7b0372c6eab713f98f19cdb86bde5f4ff35a4749849adaccd5472c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64e38d3b341efbb909d05dc35ccf190bcdf54e9c5eabb87640633f01c9157781
MD5 cd689f3dc78840dd076b31dccf6a6c26
BLAKE2b-256 8b26a98940516aff65aa7daa84a58528dd4df0d6fd85922f10fc034b42de9a14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f082c737a95e5b38c04f165772549977435b395bc6027ab6fd26963333f8f5ad
MD5 83a7adb5842b5a4b8c7205add0f4934f
BLAKE2b-256 97fb2a609b0f6b9df89df2d759b39b578c7f5d01ded60987dd6869d100699dbf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6d4fea6848f6463f5eaaf0bbce78220a44ecf65e96669f94735a9d0f27b7a9a
MD5 69efb42365c815854e58481c34b59996
BLAKE2b-256 c872288d460c23621aee5564929a505fb67a23554cbe754fd2935a20f8e32d90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.6-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 99c11b040a357cee6e73cac3ed5b68ca17bffc3381d4776ead02e91233a5fcff
MD5 bdbd35423563f060bba5c0c4d639b197
BLAKE2b-256 f18fef6d39b2312a753b179adfbaad2acd6f130860845b6c5d6e7faa1954169c

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