smly / mjai.app

Mahjong game simulator for RiichiLab https://mjai.app
https://github.com/smly/mjai.app/discussions
GNU Affero General Public License v3.0
59 stars 7 forks source link

High-level API & Refactoring #30

Closed smly closed 1 year ago

smly commented 1 year ago

Many components are still under development. Below is an example implementation using the new high-level API.

import sys
from mjai.bot import Bot

class RiichiBot(Bot):
    def think(self) -> str:
        if self.can_tsumo_agari:
            return self.action_tsumo_agari()
        elif self.can_ron_agari:
            return self.action_ron_agari()
        elif self.can_riichi:
            return self.action_riichi()
        elif self.can_discard:
            candidates = self.find_improving_tiles()
            for discard_tile, improving_tiles in candidates:
                return self.action_discard(discard_tile)
            return self.action_discard(self.last_self_tsumo)
        else:
            # Response toward start_game, ryukyoku, etc
            return self.action_nothing()

if __name__ == "__main__":
    RiichiBot(player_id=sys.argv[1]).start()
smly commented 1 year ago

Basic API implemented. Still not implemented kan actions, etc. Will be addressed in the following days.