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

Commit bb9a19d

Browse files
committed
Fix a bug with yakuhai strategy and tempai
1 parent 1704d6b commit bb9a19d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

project/game/ai/first_version/strategies/yakuhai.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ def determine_what_to_discard(self, discard_options, hand, open_melds):
101101
tiles_34 = TilesConverter.to_34_array(hand)
102102

103103
valued_pairs = [x for x in self.player.valued_honors if tiles_34[x] == 2]
104+
105+
# closed pon sets
104106
valued_pons = [x for x in self.player.valued_honors if tiles_34[x] == 3]
107+
# open pon sets
108+
valued_pons += [x for x in open_melds if x.type == Meld.PON and x.tiles[0] // 4 in self.player.valued_honors]
105109

106110
acceptable_options = []
107111
for item in discard_options:

project/game/ai/first_version/tests/strategies/tests_yakuhai.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,22 @@ def test_atodzuke_choose_hidden_syanpon(self):
524524
player.draw_tile(self._string_to_136_tile(man='6'))
525525
discarded_tile = player.discard_tile()
526526
self.assertNotEqual(self._to_string([discarded_tile]), '6m')
527+
528+
def test_tempai_with_open_yakuhai_meld_and_yakuhai_pair_in_the_hand(self):
529+
"""
530+
there was a bug where bot didn't handle tempai properly
531+
with opened yakuhai pon and pair in the hand
532+
56m555p6678s55z + [777z]
533+
"""
534+
table = Table()
535+
player = table.player
536+
537+
tiles = self._string_to_136_array(man='56', pin='555', sou='667', honors='55777')
538+
player.init_hand(tiles)
539+
player.add_called_meld(self._make_meld(Meld.PON, honors='777'))
540+
player.draw_tile(self._string_to_136_tile(sou='8'))
541+
542+
player.ai.current_strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player)
543+
544+
discarded_tile = player.discard_tile()
545+
self.assertEqual(self._to_string([discarded_tile]), '6s')

0 commit comments

Comments
 (0)