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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

File metadata

  • Download URL: xiangting-2.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 5b638651a0d7039ab21973b895608837de2bce333cb58be71961fc1b80ac1a75
MD5 7fc79c090a2fcb9a7ad3b72bbd459635
BLAKE2b-256 ab102b065983d7cd9e841473b8f3f54fb4acef8ea66593d7948dc58e675a61f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 73f474a3304e99a0b93a83cdbecdb207a618db22412a27cb22bc52604e6ca979
MD5 a172ecbe7a03e372509d5aec3bac164f
BLAKE2b-256 3ae0e8ae769fbb43ff7df9b79319b3e45dbc0391a5cc346d5523c13c9cd245c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 412e509c0999a474a8f0054fb9055af87a18ea173a236cca8af7ac9156a2144b
MD5 2aa8879d7064963ac41e37b3b65a5a65
BLAKE2b-256 3e86b492db18f141661501af5c7a8a1b67d386495a3b55a5acfc889bc88de27d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 87a4d52f3a4751a79f077aeabb0d3059e8e5af2aea57d390a72df8ed74e88745
MD5 ea39a53cf66a6b1635ce8c7e548545cd
BLAKE2b-256 c53229d7baca7635006c6b009f0e7273c8a72bd429a65cd26085f9c7870522e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85a13920e7a02d2951e03fb52b780ac224fd298a439298da35aeaadcd4bc1ff4
MD5 61ccf8e118166ab64b7865200b78128f
BLAKE2b-256 e033fe66c6b11956a9d4c4ba96c228db00fbdad84f08742a148d48e388eeeb03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 140f2cba77ec0d3d1b52640287b69ca33f5957aacb064b4e78f7795d40a96041
MD5 39f0082da45beb3f964287b91401e151
BLAKE2b-256 5718d9f8d5f44ede349a6616bec98e4d3cace504326e6272a477c1e3a5a8d538

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4e3542231afb2b0f697d01d7402b1f38fb3c31b91ba8343c9458bf16cf46db36
MD5 21382a31c69933710482f39620f37d6f
BLAKE2b-256 69b90cb37ccc4248bb48fdca99ef4d189297c4f658798204ca7b0ef91cda6e3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 196ec9ba2bf2cfa63025ec8a31254cbff3b95e840a8ff0befca98ebb7cef515d
MD5 008afd9b4ac4d7b1239ceea0af935750
BLAKE2b-256 e6fe521a11e4aeaad8156c8c9827b615cd82d4b494cd04a079cc8b3c8c6211b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 df8227038d02ac32613eff0693d565609162615be4dcdba7444cb74f1fbe702e
MD5 63e0c67fa5c6a5d31b4497d29b31a545
BLAKE2b-256 e15d36467ff3af1984d2302ddbffea36b9c09f66e35c7d09c021e4deb3c69493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 373d4732bdc44a7c3027b66e4f2f83a19e2509e8216aa4e0edc6d0649f4badb0
MD5 b807296927cce7c23ca07a7efb66b071
BLAKE2b-256 a012a7243ac1728f1ce0899a9ce17329ff55580486c16a38cdf393038e55dc3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 01d3dcc020733b3a44912146a03fc545931a86e4c89afbe8cbd1e89f29073e43
MD5 55502ae64833df830a69c496452b8514
BLAKE2b-256 78d6eb70d828ad2fea12f4883454374f73506017854aa3ef8d7861d6b057e415

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0130452b432b2fc1576f5f0717f7289f2e65242fb189ee0b1f97d2ec8726b14
MD5 0738c2663d89529802fa7804262333b2
BLAKE2b-256 2bdf3766a81ead601fbb6590ae232627caaf144300bf6503d9e36812eb1e6dcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 be9da1aa65976bd61cb73a49cab9085b7e5fffe059b130ed40c99e7cfcc58dcb
MD5 454f308cf7093e5b18f781dfac00ab25
BLAKE2b-256 9796166a2d0ef03075c4121251f513d98c1080b67569fd61dc1aaf4cc70e43ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c155ff30990fff697dccfd87675ca7d2b78d5840a54a63f768b6899aea01ab4
MD5 6545a53a02978bc62377e475d87ab951
BLAKE2b-256 eebd0602e7b81fbe5cb100715bdbd6b9b06499b7d0a46511295e28079642f454

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-2.0.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b18fa2beb2f2ea03f6cebc4e9bcf86e2ce94c94f457581fa210549c818239bc5
MD5 2ffe21834e49938157b53b2242325165
BLAKE2b-256 89314b1568d0e4e9f05b8943813d6dc050007d135e65b86d638c2a9adf0b2650

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