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

Commit

Permalink
Fix a bug with wrong tsumo logic for bots runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihisil committed Jun 25, 2016
1 parent da7fd09 commit 5f1b4cd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
34 changes: 17 additions & 17 deletions project/game/game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

class GameManager(object):
"""
Draft of bots runner.
Is not completed yet
Allow to play bots between each other
To have a metrics how new version plays agains old versions
"""

tiles = []
Expand Down Expand Up @@ -123,15 +123,28 @@ def play_round(self):

while continue_to_play:
client = self._get_current_client()
in_tempai = client.player.in_tempai

tile, in_tempai, is_win = self.draw_tile(client)
tile = self._cut_tiles(1)[0]

# we don't need to add tile to the hand when we are in riichi
if client.player.in_riichi:
tiles = client.player.tiles + [tile]
else:
client.draw_tile(tile)
tiles = client.player.tiles

is_win = self.agari.is_agari(TilesConverter.to_34_array(tiles))

# win by tsumo after tile draw
if is_win:
result = self.process_the_end_of_the_round(client.player.tiles, client, None, True)
return result

tile = self.discard_tile(client)
# if not in riichi, let's decide what tile to discard
if not client.player.in_riichi:
tile = client.discard_tile()
in_tempai = client.player.in_tempai

# after tile discard let's check all other players can they win or not
# at this tile
Expand Down Expand Up @@ -198,19 +211,6 @@ def play_game(self, total_results):

return {'played_rounds': played_rounds}

def draw_tile(self, client):
tile = self._cut_tiles(1)[0]
client.draw_tile(tile)

in_tempai = client.player.in_tempai
is_win = self.agari.is_agari(TilesConverter.to_34_array(client.player.tiles))

return tile, in_tempai, is_win

def discard_tile(self, client):
tile = client.discard_tile()
return tile

def can_call_ron(self, client, win_tile):
if not client.player.in_tempai or not client.player.in_riichi:
return False
Expand Down
2 changes: 1 addition & 1 deletion project/game/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_call_riichi(self):
self.assertEqual(client.player.in_riichi, True)

def test_play_round_and_win_by_tsumo(self):
game.game_manager.shuffle_seed = lambda : 0.05
game.game_manager.shuffle_seed = lambda : 0.7662959679647414

clients = [Client() for _ in range(0, 4)]
manager = GameManager(clients)
Expand Down
1 change: 0 additions & 1 deletion project/tenhou/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def start_the_game(self):
result = self.statistics.send_statistics()
logger.info('Statistics sent: {0}'.format(result))


def end_the_game(self):
self.game_is_continue = False
self._send_message('<BYE />')
Expand Down

0 comments on commit 5f1b4cd

Please sign in to comment.