MahjongRepository / tenhou-python-bot

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

AI crashes when calling chankan #35

Closed 0xrgb closed 7 years ago

0xrgb commented 7 years ago
2017-07-03 00:26:23 INFO: Hand: 23m55z + 8s [888s, 456m, 999s]
2017-07-03 00:26:24 DEBUG: Send: <N type="5" hai="103" />
2017-07-03 00:26:24 INFO: We called a kan set!
2017-07-03 00:26:25 DEBUG: Get: <N who="0" m="38515" /> <T51/> 
2017-07-03 00:26:25 INFO: Meld: Type: chankan, Tiles: 8888s [100, 101, 102, 103] by 0
2017-07-03 00:26:25 INFO: Hand: 23m8s55z + 4p [888s, 456m, 999s]
2017-07-03 00:26:26 ERROR: Unexpected exception
Traceback (most recent call last):
  File "/mnt/d/programming/wsl/tenhou-python-bot-0.2.7/project/tenhou/main.py", line 24, in connect_and_play
    client.start_game()
  File "/mnt/d/programming/wsl/tenhou-python-bot-0.2.7/project/tenhou/client.py", line 277, in start_game
    discarded_tile = self.player.discard_tile()
  File "/mnt/d/programming/wsl/tenhou-python-bot-0.2.7/project/mahjong/player.py", line 157, in discard_tile
    tile_to_discard = self.ai.discard_tile()
  File "/mnt/d/programming/wsl/tenhou-python-bot-0.2.7/project/mahjong/ai/main.py", line 60, in discard_tile
    selected_tile = self.process_discard_options_and_select_tile_to_discard(results, shanten)
  File "/mnt/d/programming/wsl/tenhou-python-bot-0.2.7/project/mahjong/ai/main.py", line 96, in process_discard_options_and_select_tile_to_discard
    return self.chose_tile_to_discard(results)
  File "/mnt/d/programming/wsl/tenhou-python-bot-0.2.7/project/mahjong/ai/main.py", line 211, in chose_tile_to_discard
    temp_tile = results[0]
IndexError: list index out of range
2017-07-03 00:26:26 INFO: Ending the game...
2017-07-03 00:26:26 ERROR: Game was ended without success

Version is 0.2.7.

Here is the link of full log file.
https://app.box.com/s/zj8tos4qcdjcy5f3d4iolacz9dtiz88u

Nihisil commented 7 years ago

Issue was more complex than I thought :) I Will try to fix it in next 2-3 days

Thanks for the report

Nihisil commented 7 years ago

Thanks again for the report :)

Issue was fixes in the 0.2.8 release: https://github.com/MahjongRepository/tenhou-python-bot/releases/tag/v0.2.8

My next plans to this bot (maybe you are interested in them):

  1. Refactoring. Really heavy refactoring. I have a lot of places to improve in terms of code base
  2. Profiling. I want make this bot more faster and make it consume less resources
  3. Improve play strategy (It have a lot of places to improve)
  4. Add AI based on the machine learning functions (from phoenix replays)
0xrgb commented 7 years ago

Thanks for fix :)

ps. I'm interested in this project, because I'm learning about AI(machine learning) at school.

mthrok commented 7 years ago

Hi @Nihisil I am also interested in your next plans, as I am also thinking of building AI. If you have a concrete idea of refactoring, maybe I can help that too.

Nihisil commented 7 years ago

@mthrok @0xrgb Thank you :)

Regarding machine learning AI. I started to collect all phoenix logs with this repo: https://github.com/MahjongRepository/phoenix-logs

And my next step is learning about machine learning, because I don't have experience with this field of knowledge. I know that famous bot ⓝ爆打 was build with Monte Carlo method, so I will start from here.

If you have something suggest to read about methods that can be used for bot, I would like to hear your comments.

mthrok commented 7 years ago

@Nihisil I already downloaded all the logs of tenhou table from 2009 to around 2017 June. If you want to I can share them with you. (It's in AWS s3 storage). I made a simple search engine using these logs for fun https://t.co/05bhyhmixi .

I am thinking to apply Deep Q Learning. So I suggest that we refactor the bot code in the way that different AI functions are pluggable.

A simple approach at top-level is to create a dedicated class which abstracts away the communication to tenhou.net and translate tenhou.net-specific protocol into simpler game state expression, like an array of integers.

tenhou.net <-> Communicator  <-> AI

This way, it is easier to extend the code to run with log files. We can create a new Communicator which actually reads a log file and reproduce the game with the same interface.

Nihisil commented 7 years ago

@mthrok

@Nihisil I already downloaded all the logs of tenhou table from 2009 to around 2017 June. If you want to I can share them with you. (It's in AWS s3 storage). I made a simple search engine using these logs for fun https://t.co/05bhyhmixi .

Thank you, but I almost finish my downloading, so there is no need to share logs.

So I suggest that we refactor the bot code in the way that different AI functions are pluggable.

Yes. I plan to do refactoring for the next a couple of month and my main goal is build pluggable AI. So, anyone can try to implement their own AI and easy run it on the tenhou.net.

Meantime you can try to implement your AI and run it with other copies of your bot with this mahjong-server: https://github.com/mahjong-server/mahjong-server (I didn't try it yet)