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.2.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.2-cp312-cp312-win_amd64.whl (425.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pymahjong-1.1.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (492.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.9+ x86-64

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

Uploaded CPython 3.11Windows x86-64

pymahjong-1.1.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (490.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

pymahjong-1.1.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (488.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pymahjong-1.1.2-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.2.tar.gz.

File metadata

  • Download URL: pymahjong-1.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b863bffa95826714d0f6539ea87265dd91af3786b6ee628aa63ef5a8ec236c82
MD5 8002a6efd0b2b9f61fd81312a5b8fad3
BLAKE2b-256 a2ae3c2fdd5a629ac715e5898d56faa5055fbf82137b54e00c6fe642f961e920

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2.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.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pymahjong-1.1.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3c025190d12ceb97b44406e86add4eadf079c3df56abd6ee0706273128eca143
MD5 79b0c7486a542b115314dcda0472cc18
BLAKE2b-256 7a730466bbb88b1ac1ed2513e9009bbaa0a638681cb5c07b4bb63cfa215f5c3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5f0eda02d0c88224f7cf1aa0d59c3397693f438174b6206526b5e04980ffbbd
MD5 37f2b9d3b643c4b82f8ee7afcb57235d
BLAKE2b-256 12f0eb4b1e9ae74d181d2277992d8f3711b4c8f66dd3c6495ce49bc830bf7d19

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0bf470b8959d6aa5a339aeccfd4a31428a17d2593a4048df834af846d043052a
MD5 604cd2588ec01d9bd353f843166eb2b9
BLAKE2b-256 de89e738ac879b5eb8ec5a85e544d28a4db83c09f9e292eaf5a9324f495824be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a4e4556136745a38e6a84b3d232c9a448d888cd0a0dd5c86f7922f0b3c5e765f
MD5 7b0e51a70fff668b377709c10c3a20ef
BLAKE2b-256 2ceca71362dcd051080e77d81e2199e8e8ae6149fb841e738883221e5abbae8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pymahjong-1.1.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 be5163b4020521a0a93fa8cdc93cf99bcb556b9cdb6bc761d67dfc63a095a181
MD5 868660cc9f738fe61cfc828b9a04d2b3
BLAKE2b-256 ba09e1e14ce26bf449455bc71f979a7857d17938ffdfa8da2728f5999873e580

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a08e467c381fd5b63fb4ab42ebfa0237b2a3f6f413e6c027f5f1efa8dc4f4f41
MD5 6e385cb83ea7aea4dd51245efb4e3bf8
BLAKE2b-256 329eb46cc7fe3bdccbb4741f6875b457ce55b77018e6fedbadfa2565eab768e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e150c2afb3c61aa7f22988f4e25d90d042df234402f3d27b54985cbf8d1afc12
MD5 38e81808738cf8c5f28fc46c15dae3fe
BLAKE2b-256 16e401de4aae0f240c1d42337cdea6954864e2c43d592a6408e0a9d48adc50d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b1d57b23cdcee826d01f9a45ecd7d6b0090995e18b6c101c59e118e41174b1e5
MD5 639638afc51371e676c75b4e586ab5d0
BLAKE2b-256 941577e5dc1fe648f7f080866197b312094d4f1ec9acd1cf4b001e3763a6b151

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pymahjong-1.1.2-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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 35b6b54f33e5644eefbd2941c5e799c4a8ed41a0acd7f7cd047a9f436f3c6215
MD5 7deb6c6d442f60b9deb003858610c37a
BLAKE2b-256 0c24b34035e149383ad75617f073fc48b871377aa2397f058ed5e97e33b4ccc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7dd85f571be1e5df8b1b1fb1af143b815b5f7457b96e3b29c31575d8d61a164a
MD5 c67ac9faa85910f6a09291b8ce58d6c1
BLAKE2b-256 ea42bfbba1e3625be63e8fd81706ecdcb97be9ad6390ad1283144338551c6aa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e023bfbb94550939d3978f1b375beccfe1852b41a7f5f09b69f5053be77ef87
MD5 f0649c97ab00f74f059ae50be5fe89bd
BLAKE2b-256 ff43137e035ed7b1d2667f6697edb2af04446555276cde6318d3d99e3f6d3b8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymahjong-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c61ac898f0c05779d227258dc9202fea23f43ef3b3a7f7056eb72cbf2dd7c694
MD5 dfc94c22f1623de9bac9b09b37525130
BLAKE2b-256 67c0968ab7128cf86fca299b42382d5c7ea59dbee6e79bd56130934c87c0c03a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymahjong-1.1.2-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