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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

File metadata

  • Download URL: xiangting-3.2.0.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.2.0.tar.gz
Algorithm Hash digest
SHA256 ac57e8c89fa03cbaa9157e296a62fb381d37e68adc3fef5dce2958693e25b81f
MD5 98d83fadf5b98d31307332fdb620dfb4
BLAKE2b-256 0ea0b9433dd834dc09a88c4297df6634659c7af1e22d47d5d711ebf02db33bae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7d198792e0ad2514d8ce098903efc0b7e34feb7762860a1a4f5e3fbfaa1cd45c
MD5 a6366ddc196fb34924dfa0fd318bd512
BLAKE2b-256 68b2967085a67c2018550fd2a3f44e05d53c801d96622812e6a16c2254d548cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2fd83f829e6a549d7c32535360884be4b99ff4b6e156a7972596fd9eba7aea7d
MD5 d3c881ad6ec10eda6764666d48a33a5c
BLAKE2b-256 dd40a1d9ed424d68e315f00994eb65802f1ecba1e3b0953e226bb2edec37a458

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3010230a97a294e52b909897488db3822370c7d7717f100239372c022ef49d00
MD5 d09caf9f88efd0406512bb8439bd7521
BLAKE2b-256 98f2ebdb17f670fe8bc91c60ac097c0da7392faa055929c083f45836e0a8f3c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ce541251164366ff6268b440e05c21b01e6ed62b868336d2b7e5dc2ba6cf5c7
MD5 338ab0856dd411afa1b54716c20d8045
BLAKE2b-256 200d1e01dc80ed50e3102c3798d36e429c2e794de2f2ce7a5106c4442ac33a77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1387006a5dbb14cd03d261b1f4e871522ec8f4277b6333b8bc0e38c080bde14b
MD5 39363a317ec64f5558390feda4d693bd
BLAKE2b-256 1b3fac6168ec3c6835ea2f1bce9885f0cd08ac1136367f7109a1fb394807d4ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0113d886ed07eebaed469bc46fba4e6621e5e85ca5a1109001daa549322045f9
MD5 340a9d504b9b3f596f91be32a7d94f40
BLAKE2b-256 46373c2d9b9f287573818ac71c817a75302b875d21a0f309fd3aaffae43db850

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b5d328e99c70aeaad71e48a05000c60fee2961d07b4c7d857b7f515a518f5d88
MD5 ca8bb74e8f3ca157f23eb064a9d13a11
BLAKE2b-256 40cb40c756e2fe58714940e58bf3b33594642159d4af31fd4b73c1ba4dd36c68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0e8c7f0756aa86817e4ac44481bb20ce96bd1a4e80fed7fd8c57100a8fd55e6c
MD5 5347ac2994ac1ae6fecbc4dab3f5c5dc
BLAKE2b-256 8e55cd097936bcc9867eb6d33ce211f86a73f0724e622bd9cdc2329b41f50795

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aeadd297d8255c15aa352bc5e02829e7f2f3689cfb95c77b835f30247a1dc845
MD5 1c0a10407dc80e603f63981093be336b
BLAKE2b-256 212375a31b7479d5f060d3896bd2e530aaf274880f22c6a982a31daecb6d4af3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f5f691c1e471517c3ed6bd941c2feffb419ac1cb6079b5dda3ba25908f7308c0
MD5 a6a9576b6afbc084d7e6d861fb250b4c
BLAKE2b-256 af31db0f6db55eea93029ba345d2a00a3a7f1c5c0574dc5295ce44055e8013ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1769c15358d9b0d673d56caccbf39071dd76f965e6970d0b5e8a5fd8c5a07ead
MD5 2c46a22afe61ad6b261bd62ca8425b41
BLAKE2b-256 85faf40e0a4314b95d042738e73b60f36cb6908ef1b11d8613a8259554c59549

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0173891006ec071b54d44901eb28b991ffe7616ef544c02fb4745916acc994b8
MD5 88d0513f5082633e529e7d47233f82ff
BLAKE2b-256 5d02924117de064982f12dc0bc509a5504026dcb3ba1e2f7b26c1870cafea2e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9883f8d4f17377cd6365f8c9ca53da7e2fd50584bf59e17d0465e4a3c1cb7e95
MD5 ff943e0ea4673dfc2ca8924390ffd020
BLAKE2b-256 87e29ae87ea13e2eb5f517632bb5e2d4cf236ff0b84c6825ce05faadf6bd2eba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8dfbc13ed0c168d415d9506b4dabe887e88dbc579ca41484d697173bdd07966e
MD5 0856f8709de66a3e2724b1587ea75672
BLAKE2b-256 8fdc33391cf6c8ba0e137392d335e9609d04431e1a4c153cc07a815c099f6fc7

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