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

Uploaded CPython 3.13Windows x86-64

xiangting-2.0.5-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.5-cp313-cp313-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

xiangting-2.0.5-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.5-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.5-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

xiangting-2.0.5-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.5-cp312-cp312-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

xiangting-2.0.5-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.5-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.5-cp312-cp312-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

File metadata

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

File hashes

Hashes for xiangting-2.0.5.tar.gz
Algorithm Hash digest
SHA256 9af32db3babf27a82dad4b1a0027c74149f54d2b0cee62a5e0f604e72a4c31ba
MD5 9a185462209e73fb51314446dd371732
BLAKE2b-256 aa92afcff7cd4d87247875609e16436b8a9a4e234872aa9c216c198902fec704

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 156eaa65b79cabeaf79d912a64dd7bfb08498ecbf6cbb5868dd6f640b037b10c
MD5 0d18166d28deddb84ffe96571d531d41
BLAKE2b-256 dc7454c454665896780f56c2ac476be63624e2c55719cec9a3499cde8cc54011

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6776b344f344f0996de025cfecc6e3383359fe6b72a5bf138ea94f1890d035b0
MD5 70708b90e8aebfc861a4303bf132d7ad
BLAKE2b-256 22cf2c97adb7856a7ed56c19320f6672fac1c34c76dd07a283c9d366b6d681a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 6966b31678d492ab060770d8d3e1a73246dac96def625649c7d3976c838d2f98
MD5 8e01deb4dc8b88b44fc9898de3f2842b
BLAKE2b-256 c33c754d1f533ba01fe9c4eb17a042e5ba2814f9ac915c101fc9f424b5276dbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ebf2b31e59a451a2377df439552aa4187b753a60de231965b501681cd793763e
MD5 664da8cb22d616f8410ff88f39942dbb
BLAKE2b-256 f024cabad970548d04e5501d1fca14af8a10aa3746f687938de33198c2cd17e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5dac6a5cf830c579e878977ad4433704985f499a347d1de42f9675bddeff9c14
MD5 10f45e03708d3dd189dfeb35f6f4a0ca
BLAKE2b-256 012c928ba0c803778f93fae4d1905c77f85e8736a760c9ffc7631c30ab864909

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 863ff283a5c432b4ae94b960b0dce5432e432d9fd504518e4074c9ab9315bba7
MD5 008b540d8e720ac60dfa34e91b8fd8fd
BLAKE2b-256 cd4070c4feac4761fa461398eeccb23bc658f5bc1908a355dd9ea35e6e6df2d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c234d7339c23fde6ad4daeabac0dae175d797b8a44c43ba8cbe4e16fcad94207
MD5 911dd098ad90383499f7fd04dd0f65b3
BLAKE2b-256 abbd3ce2d09ff88593c89ced1979ea298d4b49e28d93531ed85a0287425b162b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 534db96931e219028b0dc8424f5b0491f626f9c6c8f031bf3581082296ce2897
MD5 1c01ce0619e25c41d709719496f0c5d9
BLAKE2b-256 482f5fa2d52ff9f3eea055761fcc440ec71061c98551a821f8ee6d4679e9d3af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e4db104df9a848001a47d0be7e22720ce0b354abde179c98446a1fa68ab61d9d
MD5 b6f96d91e2a230aab78c92aef58ada9c
BLAKE2b-256 4af90d09582ff13f531166332bab1ccfa102bbc35fb59059ccb4144d9eb7e566

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 058d8bd2ce4326e0787c8a199329552fd11d92e806a661c1f8476eba29e3214b
MD5 6a8942dec5d1bc84e1ae2df8f3053fb3
BLAKE2b-256 8b3a205971a299eeb692df119cdb4ce2a6c46d2312bc1bdf4bdb264007f42b84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82b4afc192ff3f05e8b158a0f0a88f33f50cbe16e4c0d6bdb3926ac3af63d31f
MD5 79df7a20706ad2f7828af8ecd65ccb35
BLAKE2b-256 77921648937943ceb0fc36e3b10b0602a66396f8baac815efc2192ba8328b234

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2edd4eede1fe9b4f4e4fb9e41645027005d40f607c96c3aae44a30f1406def1c
MD5 1e926d26296c8b9a123c4fd80846f726
BLAKE2b-256 4147052c89023dce87f16c1fa30ec48d84ff9b1dcd1633c83618b465450660c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91f5e74147c07665576008ad65a34f86b7c4f9773d8868ad1be7a05d070ec346
MD5 5acff007122c6d98a84864b64a7f0ec8
BLAKE2b-256 efe19a960cb61edb011adfd315dc1d1d52fa1a6f27be9d2fb8c66c80095bd635

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a2b51e90db0438c5ba73a6064a602b0ddeb5774831c108d030b58ccf1c123291
MD5 8833761c8895e6e707eed5a319120823
BLAKE2b-256 5dcd79e52fa183801153875c274aabe53e776f94077ed59459a39a649259d76a

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