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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

xiangting-3.1.0-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

xiangting-3.1.0-cp312-cp312-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

xiangting-3.1.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.1.0.tar.gz.

File metadata

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

File hashes

Hashes for xiangting-3.1.0.tar.gz
Algorithm Hash digest
SHA256 6ba3e6c9a470d29dbdb9cbce24c3e318bc8afb54a440495a6c488dd0b6e53a5a
MD5 3884214ab4dc84d8614c61748fbc8253
BLAKE2b-256 41de8f8754b5d8aa20ce75c43be90c8c244cb6820d2b7adcde75e697223c5103

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 653a2a449fb0e62b6f764929a4bd57978d6fbea6b758fa939b191ed5bf5c5e6a
MD5 8b037f7eac95cfa24bc7085fe3202cab
BLAKE2b-256 46aa394d6d97fa96126bd7bd86528964d21273369c3fd87c1bcea7b9bba3ecf8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 84d62f0bc62d9f5a625e543d856c3016df26768aaf7769e618d6814a98620e0d
MD5 a03400ba65c8a9e6fd9c0a5c31a1aaa7
BLAKE2b-256 19d7d141d7a254948b657c4dcf30b702223e568bc8567ed503d5395c55eda487

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b7dcddf0de2bbd5f97346e61fcc9190366424ff387c31b72ac7e06b77753be6b
MD5 ae9325ae1b0affcfbb1a5e9afde753c0
BLAKE2b-256 c408fa7d510c7a83ecc14cc4b0c0dbfd6dcfa31134d41bafa9773b1aa1d15a18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 98a84dccc0259229def57b6658623e7f7cad7d3138773b714da87149d019ce21
MD5 f0d35d0316de4d24a3b557f0fa6a63d9
BLAKE2b-256 9913754f0ca2408d7adc9dae3d0388ad14612476dff8d49382e563b060bb8c08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b7ee118a029fa190d8eddc49a83de1d22b7a1bfcd8fdacaa381f9e995af110b2
MD5 fb1c8da4ebb286cd4e15c19fa8152ae3
BLAKE2b-256 be4c5e57898ef0a1dd9a68ea7e2f8795738c51c9738f5d21ac8382857f1ceb75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7df06d2f925e7145fd3e261e5fae27995cf39bea8e949e00672e1757cd5659c4
MD5 c47d7655dc575ffabccb35da95f8b99a
BLAKE2b-256 c6bd15093ae9af3652ebbdbeb170fe1a5e8c0489f8b7d04aef62d7fcdd3bc69f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af2cbb4a8fd2d4b7b37bbe85ef0e7d5334404a74e597dd8da8819346f98bd88a
MD5 edea666e60da105bbf2eb13ba2280b34
BLAKE2b-256 274676d87cc971ed040b1fdafc462f22e8c69603d2fc25c93ed15ec2456552a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 595c34338650596d60ef7b436d842a7807cd9b9d7fbcb90e4d8550755eadeddf
MD5 ac09bee90280d0d3bf32750807a80529
BLAKE2b-256 48e0ec2f8417909ecfd6bd1a30ef7214347a06f339ecca3c561a33125b2efac4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 abaf22c8b349dc443e602761627f071356fb308a862ef273c872f67b177e94fd
MD5 59679485a29e43be84c7624cd400791e
BLAKE2b-256 eaa250f31427c8c19a3427b261c25624b82b053a405c400af6be1385c3e4bfc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 dacc34a848226b87beaba8c1bde0d04db9e68839206317018c266324fcb9b7ea
MD5 835439a5c248775493a183fa483386db
BLAKE2b-256 3b79d848c1a6e1826757475101b87ca3fb0e4c6d741766ed880c3ea58b2326f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d55a1f6a99315054b9c7a1849d924aa65882d9379a4ca46839be5110d018c83c
MD5 97e42c4b8f1014d5dcd6d423db48cf81
BLAKE2b-256 91a012aab6358f2fdd719134b360a7d5673984fd18c2669efd1d031bd3335889

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 81ef5fabb6f60edc91b8fc370da82b4b3559c90801ecbd4e73666ecfef6e5c1c
MD5 e5e3bd0a3e5baecbaa0d1575ba51cfaf
BLAKE2b-256 c5119bb31e7637be38c651a2d622a656e2812df91503a7953fffc11789124a85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d502b4c1992ab4ca9adbf2e033565079ba59e404874a25b7c83d02e4aad63582
MD5 e75e7a65258317f5d4437fe096ddffa0
BLAKE2b-256 9d2009579cc4f64f8a1674bafdbb67b2fc3c027bd5c3535a056031eaccc33bae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xiangting-3.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 06163dad5ed84bdbb60091acd45a563fa658d0a9b79906e116370d08eca5f4d5
MD5 34d4ef0eaa1edc9ad4b054471ae66e87
BLAKE2b-256 b25851505a57b6d2b3af4ab180ac1170076a6823151269818b16f190980687ac

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