diff --git a/project/mahjong/ai/tests/tests_ai.py b/project/mahjong/ai/tests/tests_ai.py index 9b275535..3161c8c6 100644 --- a/project/mahjong/ai/tests/tests_ai.py +++ b/project/mahjong/ai/tests/tests_ai.py @@ -243,8 +243,18 @@ def test_upgrade_opened_pon_to_kan(self): player.add_called_meld(self._make_meld(Meld.PON, self._string_to_136_array(man='444'))) + self.assertEqual(len(player.melds), 1) + self.assertEqual(len(player.tiles), 14) self.assertEqual(player.can_call_kan(tile, False), Meld.CHANKAN) + player.discard_tile() + player.draw_tile(tile) + player.add_called_meld(self._make_meld(Meld.CHANKAN, self._string_to_136_array(man='4444'))) + + self.assertEqual(len(player.melds), 1) + self.assertEqual(player.melds[0].type, Meld.CHANKAN) + self.assertEqual(len(player.tiles), 13) + def test_call_closed_kan(self): table = Table() player = table.player diff --git a/project/mahjong/player.py b/project/mahjong/player.py index 1dcf3587..16654954 100644 --- a/project/mahjong/player.py +++ b/project/mahjong/player.py @@ -62,7 +62,9 @@ def erase_state(self): def add_called_meld(self, meld: Meld): # we already added chankan as a pon set if meld.type == Meld.CHANKAN: - return + tile_34 = meld.tiles[0] // 4 + pon_set = [x for x in self.melds if x.type == Meld.PON and (x.tiles[0] // 4) == tile_34] + self.melds.remove(pon_set[0]) self.melds.append(meld) @@ -210,7 +212,7 @@ def enemy_called_riichi(self): def add_called_meld(self, meld: Meld): # we had to remove tile from the hand for closed kan set - if (meld.type == Meld.KAN or meld.type == Meld.CHANKAN) and not meld.opened: + if (meld.type == Meld.KAN and not meld.opened) or meld.type == Meld.CHANKAN: self.tiles.remove(meld.called_tile) super().add_called_meld(meld) diff --git a/project/tenhou/client.py b/project/tenhou/client.py index 93103575..9273e219 100644 --- a/project/tenhou/client.py +++ b/project/tenhou/client.py @@ -271,7 +271,7 @@ def start_game(self): else: meld_type = 4 self._send_message(''.format(meld_type, drawn_tile)) - logger.info('We called a kan set!') + logger.info('We called a closed kan\chankan set!') continue discarded_tile = self.player.discard_tile() @@ -374,7 +374,7 @@ def start_game(self): if 't="3"' in message: if self.player.can_call_kan(tile, True): self._send_message('') - logger.info('We called a kan set!') + logger.info('We called an open kan set!') continue # chi or pon