Skip to main content

A Japanese Mahjong environment for decision AI research.

Project description

pymahjong

PyPI version Python versions License Documentation Build Status

A Japanese Riichi Mahjong environment for decision AI research, featuring a high-performance C++ backend with Python bindings.

Features

  • Complete Rule Implementation - Full Japanese Riichi Mahjong rules including all standard yaku
  • Gymnasium Compatible - Ready-to-use single-agent environment with pretrained opponents
  • Multi-agent Support - 4-player environment for multi-agent research
  • Oracle Observation - Access to hidden information (opponents' hands) for oracle-guided learning
  • High Performance - C++ game engine with efficient Python bindings via pybind11
  • Cross-platform - Pre-built wheels for Linux, macOS, and Windows (Python 3.10-3.14)

Installation

pip install pymahjong

Verify the installation:

import pymahjong
pymahjong.test()

Quick Start

Single-Agent Environment

Play against 3 opponents with a gym-like interface:

import pymahjong
import numpy as np

env = pymahjong.SingleAgentMahjongEnv(opponent_agent="random")
obs = env.reset()

while True:
    valid_actions = env.get_valid_actions()
    action = np.random.choice(valid_actions)
    obs, reward, done, _ = env.step(action)
    
    if done:
        print(f"Game over! Payoff: {reward}")
        break

Multi-Agent Environment

4 agents compete in a full game:

import pymahjong
import numpy as np

env = pymahjong.MahjongEnv()

for game in range(10):
    env.reset()
    
    while not env.is_over():
        pid = env.get_curr_player_id()
        valid_actions = env.get_valid_actions()
        obs = env.get_obs(pid)
        
        action = np.random.choice(valid_actions)
        env.step(pid, action)
    
    print(f"Game {game}: payoffs = {env.get_payoffs()}")

Documentation

Full documentation is available at https://agony5757.github.io/mahjong/

Pretrained Models

Pretrained opponent models are available from the GitHub releases:

env = pymahjong.SingleAgentMahjongEnv(opponent_agent="path/to/model.pth")

Offline Dataset

Human demonstration data from Tenhou.net (6 dan+ players) is available for offline RL research. Download from releases.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Citing

If you use pymahjong in your research, please cite:

@inproceedings{han2022variational,
  title     = {Variational Oracle Guiding for Reinforcement Learning},
  author    = {Dongqi Han and Tadashi Kozuno and Xufang Luo and Zhao-Yun Chen 
               and Kenji Doya and Yuqing Yang and Dongsheng Li},
  booktitle = {International Conference on Learning Representations},
  year      = {2022},
  url       = {https://openreview.net/forum?id=pjqqxepwoMy}
}

License

This project is licensed under the Apache License 2.0.

Contact

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

pymahjong-1.1.0.tar.gz (2.4 MB view details)

Uploaded Source

Built Distributions

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

pymahjong-1.1.0-cp312-cp312-win_amd64.whl (425.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pymahjong-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (602.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pymahjong-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (492.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pymahjong-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl (540.5 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

pymahjong-1.1.0-cp311-cp311-win_amd64.whl (423.1 kB view details)

Uploaded CPython 3.11Windows x86-64

pymahjong-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (602.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pymahjong-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (490.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pymahjong-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl (533.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

pymahjong-1.1.0-cp310-cp310-win_amd64.whl (422.3 kB view details)

Uploaded CPython 3.10Windows x86-64

pymahjong-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (600.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pymahjong-1.1.0-cp310-cp310-macosx_11_0_arm64.whl (488.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pymahjong-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl (532.2 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file pymahjong-1.1.0.tar.gz.

File metadata

  • Download URL: pymahjong-1.1.0.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymahjong-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c619c592538b01dba8366f3841f8dd92f7a9432c756b5e879de99cb016fd9450
MD5 5ecc6046861a620b4d4cd19dfeeb7b22
BLAKE2b-256 a3e795c0d839d136c1b6cce032ae43c99958e4706eaff2790b814dd1439f2068

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0.tar.gz:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pymahjong-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 425.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymahjong-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a7a47ff0521245119940f293a5af7186fe41946d61a79819edadb8d834ccde3b
MD5 08645b0232c2bb86b2929dda8584f04b
BLAKE2b-256 1c9ebac01e7b0f4bcd6eb95184ddde402ceb66d79ef03ac992d00f273fda4e32

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp312-cp312-win_amd64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a07736b907787ec6038c26bf41fe116b71eef84dd0027cd9e0aa4afcd843a3c4
MD5 a71ebb6f936799708b80f02e735ce3eb
BLAKE2b-256 5e519e4b6282d6b22255ec0d467dc084dff6e33c28750985efe7f603212578b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 814a839e970e261b6733b006127d9ca63c2fc7a374d4142cddc57286699f0b7d
MD5 ae02bf63fac66888b8e0c39fa4c3f2d5
BLAKE2b-256 0f2ac2089e858a968d0af0cee17d355e1cb0320c3e577f863ab04029782471ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2905f4bb5839218b3f8b4084e42876539b97d476135e5b01cc82228fc7daa631
MD5 9b389917bcb769ca139f42a4ef7214ea
BLAKE2b-256 2bf5137fc3aa31331a3907794855b00b3a6d4e5a59fadf8b0017a94b8a524554

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pymahjong-1.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 423.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymahjong-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f7d68c6ac425a22c149ca15306423a761f37ea179d5edab3915c202231e0e7dc
MD5 be6b046621a76c958e9dd2c541a4c335
BLAKE2b-256 ecc9310e9b12bca796c556a748294d58bd361ec96355342b5c32a45b6087d994

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp311-cp311-win_amd64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 02a8865a145ff65c3e1fa42deb2f463e89a8f70cb7469a186a77a3c1454b6b74
MD5 2171ed079d8fc31777fbab3482e62b43
BLAKE2b-256 e0a727cb24acf512fda5f6925f04de5ededf5c5ab8768fb929e8b3f726eee6b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 314eaacd22aa6d6d0aa08623a87e22f9eafed072ebf14b2d635571e02b0a88fd
MD5 e36d27a075425c82b7411c355c779d7b
BLAKE2b-256 d603223f0668cff421e6840bc0af8e3c1ceb33c914baf3883b4a3d2b9adf1e26

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e9f01eb53877823d8d97cffed43da99305d1d36c7cf3ab7b838df6ebf59de653
MD5 fa32c33d04755bbbfc0c2cd59bcde7ea
BLAKE2b-256 0e5e6b9fc6096393726046dbf250f5bbaf7ee9e2990dd1f5e505641b895e504f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pymahjong-1.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 422.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymahjong-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e6af344360b9efb4a912734c89ada7e265b426456c0f0db7c6f3b4f95c49fdae
MD5 f6c38ae9e6b2ceb0d25ab260df112041
BLAKE2b-256 3a50ab9ccc7a5fc089c861ff6f597c3e1768b5e99d703c2692b409052ff63841

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp310-cp310-win_amd64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55b8b2d9372f1d0d77b25e9534d6708c0905cc0bf2fbf475ae62f1f4b517f332
MD5 422bf58c53a251305650388d08c03817
BLAKE2b-256 d2c0b6a82bf95eea699b529bada68b4fe27a5abc2c3cc2f50cd33f961e61434b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 36a47a553fd2a764f1aa230325e3edd247055923a8b5330fd22b95ebdd307031
MD5 3a31e3a8348f4cf658906e226dd06901
BLAKE2b-256 cbaf9c4de366b1073352d56ae0ff568668a964542173cf77c4a99193d6d9ec96

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymahjong-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 59925797b6444baf567ceeaddede3d5512ef4e6a700b99ec4b4bf31fc363aac6
MD5 28f372eeabdb4f854c61f86c795ad618
BLAKE2b-256 aab348f6080ae44bb35243bb568339d5fa7eb1d208ac13f4fac6f8f28f4bb8ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: build-wheels.yml on Agony5757/mahjong

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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