Skip to main content

Python bindings for xiangting

Project description

xiangting-py

PyPI API

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

Basic 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 = [
    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, None)
assert replacement_number == 0

Handling Melds

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
hand = [
    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),
]

replacement_number_wo_melds = calculate_replacement_number(hand, None)
assert replacement_number_wo_melds == 1

replacement_number_w_melds = calculate_replacement_number(hand, melds)
assert replacement_number_w_melds == 2

Support for Three-Player Mahjong

In three-player mahjong, the tiles from 2m (二萬) to 8m (八萬) are not used. In addition, melded sequences (明順子) are not allowed.

from xiangting import (
    calculate_replacement_number,
    calculate_replacement_number_3_player,
)

# 1111m111122233z
hand = [
    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, None)
assert replacement_number_4p == 2

replacement_number_3p = calculate_replacement_number_3_player(hand, 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-4.0.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

xiangting-4.0.0-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file xiangting-4.0.0.tar.gz.

File metadata

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

File hashes

Hashes for xiangting-4.0.0.tar.gz
Algorithm Hash digest
SHA256 643b0e6d181ed8a699f145077c6ec3d2e508ddde0be9c9ab6cfd375f5ecc56db
MD5 f8133f15b9d62c85d76fb683604b79f5
BLAKE2b-256 15fceac34cadc670a5bc87d800b78b004d9e3ce04a2ca02c2cc9a9b2aba4371d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a86ab1ba9ef3b37fa17834b1e58ed5917c60f3c16a8b67a01259f317cfad00bf
MD5 75d841679d385c6ebfab63c2f0828def
BLAKE2b-256 a9984e8839ab64760b2291b292404c009b7b5fe14910a55beb8eed6eb0913f49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1f986f76ee10d809c5281b8b28e7e6e881b958d670432631aea277900255862a
MD5 bb60440ecd012a206392918a044b8a85
BLAKE2b-256 bc83dcb062b2067db418279a6cf2f34178013ee9d92dcd04149e0eb2d19153ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 8b28785ca1151095a245d0239e3bad3840f79438b72342b739ac77c0a9c4f87f
MD5 3792dca55c5300e540770b41ee5e294a
BLAKE2b-256 cf56e309e25aae8616d979ab972236a13e21d667200f7ef0ceaa959906dff531

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 313ee83986dfa2c0e4663228a69829b72ae87ebc3199fd3376111ab5c8a2e702
MD5 6734c295f3ddc803d8e7f50b5db56a82
BLAKE2b-256 0b131b46fcfaf67ffb28530b2502dfbe539b4ecac5bb6e0b4a060c93f4934f38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5e6d1a034b1800fd2be04094c9071a3f1cb0c534550446c5f76ee1d9ac13cf36
MD5 99f6a7558b59dbe930dcf24e569edb76
BLAKE2b-256 995ecf71c87740a620a83b6877f048092bcc2d419fff053154f901d7d2ee267c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f172cd3368d4957c97e8137d30b82a06b956248f6b408ba9616442cd5a9aaa7a
MD5 920383f91084d577074cf52fa6542d18
BLAKE2b-256 329009797c0fd2b77b5403ef9b4a279e31029279afa0454ab447001d6550476b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 469c3447adc689528d37dbd1edcb9e7b524d43cb2a1abcdea42c91cac2c8fd4a
MD5 e8f0d15d7e25437e0203bb0de557800b
BLAKE2b-256 092c17d88132c645c9fe3c63fe969260f2fa8c9f99af1fe2a5eede2ca32a985a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ce5f881515fa512eda7e4f896066d73a2bd389dcee51fe88188e02664f87cb59
MD5 c278b41d34d58d1df61e05cff4060f98
BLAKE2b-256 972f57418c846ad5cb8d2480aa0b2ed9143369d00664dade8cb1e78502f07bca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4f7401f0733d629b9a03e639e61c2b79cb6a96f475f7408c5bf6ac78502c2acf
MD5 e8bdd79f76ceed142974eba142193e3e
BLAKE2b-256 88665a8a88e9f615771b295c824a34188674a177660a16481a316290331d3fd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6321c83d492c446c7510cf967a59aa82e43b37382a7cb39f4b5a481d7583b530
MD5 27b5b1521dbff9025e6b7d9221288886
BLAKE2b-256 60a53536182af6f0c26a8c91d095038e53b59a457a0403049159318d6545d26e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 feef7509678cfee81a5c4c1a9a94c669c5d430ef8eebc3f52c1048cf2a486ace
MD5 e59910730e15dc203a6cfe92fdce1fdd
BLAKE2b-256 b8b90c838260d3928efb0878eab9af3ba8e7ea06c58d84e21c496e1f40a4e249

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-4.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b855c178d4f97f1010752cdff6830215df9a1f9bb6f2c17e286f4c2f62c2d3c0
MD5 1dbe93f3949644983ce32b78e356c72a
BLAKE2b-256 1996349a4a43a34f43be204cab47a0a467025874fb5bbfecd476cc9d6f5462ef

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