Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit ac0d57d

Browse files
committed
Final changes with AI refactoring
1 parent d8cba6c commit ac0d57d

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ __pycache__
66
.DS_Store
77
logs
88
project/settings_local.py
9-
old_version.py
9+
project/game/ai/common
1010

1111
tests_validate_hand.py
1212
loader.py

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ For the next version I have a plan to improve win rate, probably bot should push
6060

6161
## How to run it?
6262

63-
Run `pythone main.py` it will connect to the tenhou.net and will play a match.
64-
After the end of the match it will close connection to the server
63+
1. `pip install -r requirements.txt`
64+
2. Run `pythone main.py` it will connect to the tenhou.net and will play a game
6565

6666
## Configuration instructions
6767

@@ -70,6 +70,21 @@ They will override settings from default `settings.py` file
7070
2. Also you can override some default settings with command argument.
7171
Use `python main.py -h` to check all available commands
7272

73+
## Implement your own AI
74+
75+
We tried to isolate default AI from the project as much as we could.
76+
77+
There is `game.ai.base.InterfaceAI` with one required method `discard_tile` that had to be implemented by your AI.
78+
79+
### Start with your AI
80+
81+
This command will make a copy of the simple bot (it is discarding random tiles from the hand)
82+
1. `cd project`
83+
2. `cp -a game/ai/random game/ai/common`
84+
3. You can run new AI with command: `python main.py -a common` (or change `AI_PACKAGE` in settings)
85+
86+
After that you can change all what you want in `game.ai.common` package and test it in real games.
87+
7388
## Round reproducer
7489

7590
We built the way to reproduce already played round.

project/game/ai/base/main.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def __init__(self, player):
1616

1717
def discard_tile(self, discard_tile):
1818
"""
19-
Simple tile discard (after draw)
20-
:param discard_tile: 136 tile format
19+
AI should decide what tile had to be discarded from the hand on bot turn
20+
:param discard_tile: 136 tile format. Sometimes we want to discard specific tile
2121
:return: 136 tile format
2222
"""
2323
raise NotImplemented()
2424

25-
def init_state(self):
25+
def init_hand(self):
2626
"""
27-
Method will be called after bot hand initialization
27+
Method will be called after bot hand initialization (when tiles will be set to the player)
2828
:return:
2929
"""
3030

@@ -43,23 +43,22 @@ def draw_tile(self, tile):
4343

4444
def should_call_win(self, tile, enemy_seat):
4545
"""
46-
When we can call win by other player discard
47-
this methid will be called
46+
When we can call win by other player discard this method will be called
4847
:return: boolean
4948
"""
5049
return True
5150

5251
def should_call_riichi(self):
5352
"""
54-
When bot in tempai this method will be run
53+
When bot can call riichi this method will be called.
5554
You can check additional params here to decide should be riichi called or not
5655
:return: boolean
5756
"""
5857
return False
5958

6059
def should_call_kan(self, tile, is_open_kan):
6160
"""
62-
Method will decide should we call a kan or upgrade pon to kan (chankan)
61+
When bot can call kan or chankan this method will be called
6362
:param tile: 136 tile format
6463
:param is_open_kan: boolean
6564
:return: kan type (Meld.KAN, Meld.CHANKAN) or None
@@ -68,7 +67,7 @@ def should_call_kan(self, tile, is_open_kan):
6867

6968
def try_to_call_meld(self, tile, is_kamicha_discard):
7069
"""
71-
Determine should we call a meld or not.
70+
When bot can open hand with a set (chi or pon/kan) this method will be called
7271
:param tile: 136 format tile
7372
:param is_kamicha_discard: boolean
7473
:return: Meld and DiscardOption objects or None, None

project/game/ai/first_version/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, player):
5151
self.in_defence = False
5252
self.last_discard_option = None
5353

54-
def init_state(self):
54+
def init_hand(self):
5555
"""
5656
Let's decide what we will do with our hand (like open for tanyao and etc.)
5757
"""

project/game/player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def erase_state(self):
133133
def init_hand(self, tiles):
134134
self.tiles = tiles
135135

136-
self.ai.init_state()
136+
self.ai.init_hand()
137137

138138
def draw_tile(self, tile):
139139
self.last_draw = tile

0 commit comments

Comments
 (0)