Giter Site home page Giter Site logo

vincentzyx / mjx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sacckey/mjx

0.0 0.0 0.0 28.07 MB

Mjx: A framework for Mahjong AI research

Home Page: https://colab.research.google.com/drive/1m1wOT_K2YFtuV6IO7VgWk4ilVhTKqRFU?usp=sharing

License: MIT License

Shell 0.01% C++ 99.36% Python 0.57% C 0.01% Rust 0.01% Makefile 0.01% CMake 0.04% Dockerfile 0.01%

mjx's Introduction

ci

mjx

Mjx

Mjx is a Japanese Mahjong (riichi Mahjong) simulator. Mjx works as a game server as Mjai, a popular Mahjong simulator, to evaluate Mahjong AIs but have additional features:

  • Fast (100x faster than Mjai)
  • Exact Tenhou compatibility (Mjx is validated with numerous Tenhou game logs)
  • Gym-like API
  • Easy distributed computing (available for large-scale RL and evaluation thanks to gRPC)
  • Mjai compatible (mjx_mjai_translater)
  • Beautiful visualization

mjx

Quick start

Google colab

Install

$ pip install mjx

Requirements. Mjx supports Python3.7 or later in Linux and macOS Intel (10.15 or later). Currently Windows and macOS Apple Silicon are NOT supported. Contributions for supporting Windows and macOS Apple Silicon are more than welcome!

Example

import mjx
from mjx.agents import RandomAgent

agent = RandomAgent()
env = mjx.MjxEnv()
obs_dict = env.reset()
while not env.done():
  actions = {player_id: agent.act(obs)
    for player_id, obs in obs_dict.items()}
  obs_dict = env.step(actions)
returns = env.rewards()

Sever Usage

ServerClient
import random
import mjx

class RandomAgent(mjx.Agent):
  def __init__(self):
    super().__init__()

  # When you use neural network models
  # you may want to infer actions by batch
  def act_batch(self, observations):
    return [random.choice(obs.legal_actions()) 
            for obs in observations]


agent = RandomAgent()
# act_batch is called instead of act
agent.serve("127.0.0.1:8080", batch_size=8)
import mjx

host="127.0.0.1:8080"

mjx.run(
  {f"player_{i}": host for i in range(4)},
  num_games=1000,
  num_parallels=16
)

This sever usage uses gRPC. Thus, actually any programming language is available to develop your own Mahjong AI. For Python, we provide a convinent wrapper mjx.Agent.serve().

Notes

Mjx is still under active development. APIs might change without notice before v1.0. Especially,

  • Default behavior of env.rewards(reward_type)and env.done(done_type)
  • Protobuf schema
  • Feature extraction APIs (currently, provided by Observation.to_features())

How to develop

We recommend you to develop Mjx inside a container. Easiest way is open this repository from VsCode. Feel free to mention to @sotetsuk if you have any questions.

License

MIT

mjx's People

Contributors

github-actions[bot] avatar habara-k avatar mugenen avatar n0n0a avatar nissymori avatar okanoshinri avatar sotetsuk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.