MahjongRepository / tenhou-python-bot

Bot for tenhou.net riichi mahjong server written in Python
MIT License
200 stars 53 forks source link

Support AI plugins #30

Closed Nihisil closed 7 years ago

Nihisil commented 7 years ago

Allow to easily integrate new AI (from other developers) to the project. Need to think about some kind of plugins system

0xrgb commented 7 years ago

How about using MJAI protocol to communicate between AI <--> Program? It has some advantages.

  1. There are mahjong AI using MJAI protocol. You can use it, or refer it to make new AI.
  2. Also, you can use maujong AI plugin (Akagi, Sigma, etc) via transmau.
  3. Ruleset of MJAI server and tenhou.net are very similar.
    • You can debug your AI at local MJAI server. (without access to tenhou.net)
  4. Protocol is simple JSON. It is easy to read (+ easy to debug).

And some disadvantages,

  1. There are no English manual.
  2. Source codes and libraries about MJAI are written as in ruby.
mthrok commented 7 years ago

@0xrgb That does not help.

The point is that AI/AI developer does not need to understand whatever the underlying protocol the game server uses.

Instead, the connector should expose simple and easy-to-understand methods to retrieve the current state of the game.

So the connector should handle communication to server (here I/O with tenhou.ai) and AI should be referring connector to see the current state of the game, and to give a move back to connector.

Nihisil commented 7 years ago

Thank you for MJAI, I tried to implement my own implementation of mahjong server in earlier versions of the bot, but abandoned this idea because it took too much time to support it.

I think it is a good idea to add another client (https://github.com/MahjongRepository/tenhou-python-bot/blob/master/project/mahjong/client.py) that will work with MJAI (like current client that is working with tenhou).

For AI developer it will mean that he had to run bot with another console attribute and in terms of AI plugin it will be no difference to work with tenhou or MJAI.

Soon I will have time to finish refactoring and do release with 0.3 version which will include stable AI API (it means that current AI will be changed most likely). I think it is had to be done, because people starting to use this bot code to build their own AI.

Nihisil commented 7 years ago

@0xrgb @mthrok Hi there.

New version 0.3.0 was released and I tried to simplify new AI development as much as I could. All what you need is create a new package inside game.ai with main.py file that will contains class:

class ImplementationAI(InterfaceAI):
    version = 'my ai'

    def discard_tile(self, discard_tile):
          # your code here
          pass

You can find more details here: https://github.com/MahjongRepository/tenhou-python-bot#implement-your-own-ai

Please, let me know if I missed something that will be useful for you.

Nihisil commented 7 years ago

This interface contains all available AI methods: https://github.com/MahjongRepository/tenhou-python-bot/blob/master/project/game/ai/base/main.py

Nihisil commented 7 years ago

Meantime I will work on the mjai client integration, because it will allow to run bots locally. If you have any thoughts how to run it (maybe you already have a script how to run mjai) I will be happy to hear them.