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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

File metadata

  • Download URL: xiangting-3.1.3.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.1.3.tar.gz
Algorithm Hash digest
SHA256 d937e136181c8a1f36c9d31fa2133a3be2bf4013bef5f28cbba346cfe331a06f
MD5 a4896d10736a8193029ed2fc994d67bc
BLAKE2b-256 b7187f3a0a2e1d75c8dd7f00b88a4f35a569363bb56a02e20844b8c723a85580

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7010ffd1e46a44c6fa939a5162bb99ab4debc2a2b2f8ccfab93e8ede3c17bab4
MD5 295ddc812ab3eb45bf051d9f66af6415
BLAKE2b-256 bae8c70b396120d606a08f62aeb4198d9b696cccf4f2c2bc85feb594bbd7e112

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 defc94f800a5051231e32bb06e1aa2e30d67e04b51ea9d737ddb40471fe37c7a
MD5 9096e3af5bcc551ed01ff21515b67eb1
BLAKE2b-256 dc932da02810abaf31591efba144902c17fe3bf5a6483996d705c00454e6c817

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 efd4625876ca4c909420ae54ca416f51c3e69d699876079e228d167f625d0869
MD5 ffcdb079ce41281ffa62a2200cdaef6f
BLAKE2b-256 8ec64b7f07f0e4d04365708e3279cae215c329b553d02a42d03c6886cdd65456

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9bb8647009465b466564a2f18468038bb6cf42c4ef5d8b7be2b09d8c034bbb4f
MD5 f69756aa2a0d75777a9092db3d26163d
BLAKE2b-256 52393d0b50fc9cbe9f7f1ab9b9fca73096c028a474b138ee97fc3b1c0306309b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 773bdb12e594224095c328f570770c825f0b422b3212a07da66c96bcfcaf66ec
MD5 1dc3fb7c6435b166572465840ced80e5
BLAKE2b-256 e6158e7fb53b9a1d7ed6b85cbb3e4cccb90aa372a2cedf3f974267d5e5ea2db4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b4faf3b3e856c6c5d062c15cd5bcb363e8bb21815e0d62fa7d52d95cad077de3
MD5 679d6dfcdf95bdf837105ec2a23a840c
BLAKE2b-256 5d7851192f3aefa23ff6a623c27797c196380617252842a6b406ecb4ce94d535

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0b1b9961dda25eb75735cb87a6600f743f96196e51b2813eee8461f7ff4f9793
MD5 b2eab49f8c94a7d26da1a1d33e7a81e1
BLAKE2b-256 83fd01734e04a56ddd9935080a9b227e39736c4a82cd04973dedb3385d4c2c93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 879f561afc52b2010c3aefa30b4c86a8dfa3666efecc71660b10641dce1d9c10
MD5 312b71b49321fc24a89de7e68df38660
BLAKE2b-256 b97a127a327d5b8a6c1a4faea867e577fff2eceac986a80a7dc2a857c781e76f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 41b6e51e2565f6d861a4163ddee1a2122e322511122d4baca7aa06007be114a6
MD5 9cd052487caa06ef5c791c8a72eaa8c5
BLAKE2b-256 dd45950e25497cd8518775c8bf53dc113c68dd0818561200217a6c8313a6ee7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 105dc8ebf0a801571d34d794398e267d7a17e20bf14ce9da7d46cb7aa6c8f73a
MD5 f8b19577f0c4a43589423acf57c471bc
BLAKE2b-256 4eba3fee33c92d078cc779abaa5fa1689b370f31a3f2a49847a2ed838ea68a75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bcb4a428956cebaf5caa4e0c89bc5cea50d85543fb56c0006a4a7b18e217cbc7
MD5 2fa76857f2824b975a08250eb67f467f
BLAKE2b-256 cbb0bbaa955cf08291ef306a35efa0f2137b492318ec713a895242e31370241b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eb8e0a90be39cf1b2c804ecfdbe0700604ac6bacd82921c0385804bf65dc1edb
MD5 6fc6a72d9815d6c00bb32e304bfb01d9
BLAKE2b-256 daeb34f157d85f19f87455c4e9d28508ddaaaf7b8814fefce504b6e039889960

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 712e4137d36c68db202715e3c3217e7665b3cad09e833a74de32f0dc89c6a1bb
MD5 e1a60f21b1807f6ade98cb3e797a4387
BLAKE2b-256 d77d2e18f72476baad4a7760a2be021f1d66d58d301269ed71810ddc23d1dc34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ffe37dadd0b069b514ac3610fed40a7549fb5a31c461f4a60fdd4f1b945a1f69
MD5 3274e849a3b6b5dfc00806aa77c08080
BLAKE2b-256 8bfd06d42507f14fa850be3ac1bcf53a833b85b3f0380b6687c89d21757d8c58

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