def test_keep_only_yakuhai_pair(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) table.add_dora_indicator(self._string_to_136_tile(man='3')) table.add_discarded_tile(1, self._string_to_136_tile(honors='7'), False) tiles = self._string_to_136_array(man='11144', sou='567', pin='156', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) player.draw_tile(self._string_to_136_tile(pin='1')) discarded_tile = player.discard_tile() self.assertNotEqual(self._to_string([discarded_tile]), '7z')
def test_open_hand_and_once_discarded_tile(self): """ If we have valuable pair in the hand, this tile was discarded once and we have 1+ shanten let's open on this valuable pair """ strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) tiles = self._string_to_136_array(sou='678', pin='14689', man='456', honors='77') self.player.init_hand(tiles) # we don't activate strategy yet self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False) # let's skip first yakuhai early in the game tile = self._string_to_136_tile(honors='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertEqual(meld, None) # now one is out self.table.add_discarded_tile(1, tile, False) meld, _ = self.player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) self.assertEqual(self._to_string(meld.tiles), '777z') # but we don't need to open hand for atodzuke here tile = self._string_to_136_tile(pin='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertEqual(meld, None)
def test_atodzuke_keep_yakuhai_wait(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='11144', sou='567', pin='567', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) # two of 4 man tiles are already out, so it would seem our wait is worse, but we know # we must keep two pairs in order to be atodzuke tempai table.add_discarded_tile(1, self._string_to_136_tile(man='4'), False) table.add_discarded_tile(1, self._string_to_136_tile(man='4'), False) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) player.draw_tile(self._string_to_136_tile(man='2')) discarded_tile = player.discard_tile() self.assertEqual(self._to_string([discarded_tile]), '2m')
def test_open_hand_and_once_discarded_tile(self): """ If we have valuable pair in the hand, this tile was discarded once and we have 1+ shanten let's open on this valuable pair """ strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) tiles = self._string_to_136_array(sou='678', pin='14689', man='456', honors='77') self.player.init_hand(tiles) # we don't activate strategy yet self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False) # let's skip first yakuhai early in the game tile = self._string_to_136_tile(honors='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertEqual(meld, None) # now one is out self.table.add_discarded_tile(1, tile, False) meld, _ = self.player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) self.assertEqual(self._to_string(meld.tiles), '777z') # but we don't need to open hand for atodzuke here tile = self._string_to_136_tile(pin='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertEqual(meld, None)
def test_suitable_tiles(self): table = Table() player = table.player strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) # for yakuhai we can use any tile for tile in range(0, 136): self.assertEqual(strategy.is_tile_suitable(tile), True)
def test_dont_activate_strategy_if_we_dont_have_enough_tiles_in_the_wall(self): strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) self.table.dora_indicators.append(self._string_to_136_tile(honors='7')) tiles = self._string_to_136_array(man='59', sou='1235', pin='12789', honors='55') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), True) self.table.add_discarded_tile(3, self._string_to_136_tile(honors='5'), False) self.table.add_discarded_tile(3, self._string_to_136_tile(honors='5'), False) # we can't complete yakuhai, because there is not enough honor tiles self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False)
def test_open_hand_when_yakuhai_already_in_the_hand(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(honors='5')) tiles = self._string_to_136_array(man='46', pin='4679', sou='1348', honors='666') player.init_hand(tiles) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) tile = self._string_to_136_tile(sou='2') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None)
def determine_strategy(self): # for already opened hand we don't need to give up on selected strategy if self.player.is_open_hand and self.current_strategy: return False old_strategy = self.current_strategy self.current_strategy = None # order is important strategies = [ YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player), HonitsuStrategy(BaseStrategy.HONITSU, self.player), ] if self.player.table.has_open_tanyao: strategies.append(TanyaoStrategy(BaseStrategy.TANYAO, self.player)) for strategy in strategies: if strategy.should_activate_strategy(): self.current_strategy = strategy if self.current_strategy: if not old_strategy or self.current_strategy.type != old_strategy.type: message = '{} switched to {} strategy'.format(self.player.name, self.current_strategy) if old_strategy: message += ' from {}'.format(old_strategy) logger.info(message) logger.info('With such a hand: {}'.format(TilesConverter.to_one_line_string(self.player.tiles))) if not self.current_strategy and old_strategy: logger.debug('{} gave up on {}'.format(self.player.name, old_strategy)) return self.current_strategy and True or False
def test_open_hand_when_yakuhai_already_in_the_hand(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(honors='5')) tiles = self._string_to_136_array(man='46', pin='4679', sou='1348', honors='666') player.init_hand(tiles) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) tile = self._string_to_136_tile(sou='2') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None)
def test_keep_only_yakuhai_pon(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) table.add_dora_indicator(self._string_to_136_tile(man='3')) tiles = self._string_to_136_array(man='11144', sou='567', pin='56', honors='777') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) player.draw_tile(self._string_to_136_tile(man='4')) discarded_tile = player.discard_tile() self.assertNotEqual(self._to_string([discarded_tile]), '7z')
def test_force_yakuhai_pair_waiting_for_tempai_hand(self): """ If hand shanten = 1 don't open hand except the situation where is we have tempai on yakuhai tile after open set """ self.table.dora_indicators.append(self._string_to_136_tile(man='3')) tiles = self._string_to_136_array(sou='123', pin='678', man='34468', honors='66') self.player.init_hand(tiles) # we will not get tempai on yakuhai pair with this hand, so let's skip this call tile = self._string_to_136_tile(man='5') meld, _ = self.player.try_to_call_meld(tile, False) self.assertEqual(meld, None) # but here we will have atodzuke tempai tile = self._string_to_136_tile(man='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) self.assertEqual(meld.type, Meld.CHI) self.assertEqual(self._to_string(meld.tiles), '678m') self.table = Table() self.player = self.table.player # we can open hand in that case self.table.dora_indicators.append(self._string_to_136_tile(sou='5')) tiles = self._string_to_136_array(man='44556', sou='366789', honors='77') self.player.init_hand(tiles) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), True) tile = self._string_to_136_tile(honors='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) self.assertEqual(self._to_string(meld.tiles), '777z')
def test_atodzuke_dont_destroy_second_pair(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='111445', sou='468', pin='56', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) # 6 man is bad meld, we lose our second pair and so is 4 man tile = self._string_to_136_tile(man='6') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) tile = self._string_to_136_tile(man='4') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) # but if we have backup pair it's ok tiles = self._string_to_136_array(man='111445', sou='468', pin='88', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) # 6 man is bad meld, we lose our second pair and so is 4 man tile = self._string_to_136_tile(man='6') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) tile = self._string_to_136_tile(man='4') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None)
def test_dont_activate_strategy_if_we_dont_have_enough_tiles_in_the_wall( self): table = Table() player = table.player strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) tiles = self._string_to_136_array(sou='12355689', man='89', honors='44') player.init_hand(tiles) player.dealer_seat = 1 self.assertEqual(strategy.should_activate_strategy(), True) table.add_discarded_tile(3, self._string_to_136_tile(honors='4'), False) table.add_discarded_tile(3, self._string_to_136_tile(honors='4'), False) # we can't complete yakuhai, because there is not enough honor tiles self.assertEqual(strategy.should_activate_strategy(), False)
def test_atodzuke_choose_hidden_syanpon(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='111678', sou='56678', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) for _ in range(0, 4): table.add_discarded_tile(1, self._string_to_136_tile(sou='9'), False) player.draw_tile(self._string_to_136_tile(man='6')) discarded_tile = player.discard_tile() self.assertNotEqual(self._to_string([discarded_tile]), '6m')
def test_atodzuke_dont_open_no_yaku_tempai(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='111445', sou='567', pin='56', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) # 6 man is bad meld, we lose our second pair and so is 4 man tile = self._string_to_136_tile(man='6') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) tile = self._string_to_136_tile(man='4') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) # 7 pin is a good meld, we get to tempai keeping yakuhai wait tile = self._string_to_136_tile(pin='7') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True)
def test_should_activate_strategy(self): strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) tiles = self._string_to_136_array(sou='12355689', man='89', honors='123') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False) self.table.dora_indicators.append(self._string_to_136_tile(honors='7')) tiles = self._string_to_136_array(sou='12355689', man='899', honors='55') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), True) # with chitoitsu-like hand we don't need to go for yakuhai tiles = self._string_to_136_array(sou='1235566', man='8899', honors='66') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False) # don't count tile discarded by other player as our pair tiles = self._string_to_136_array(sou='12355689', man='899', honors='25') self.player.init_hand(tiles) tiles = self._string_to_136_array(sou='12355689', man='899', honors='255') self.assertEqual(strategy.should_activate_strategy(tiles), False)
def test_should_activate_strategy(self): table = Table() player = table.player strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) tiles = self._string_to_136_array(sou='12355689', man='89', honors='123') player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(), False) tiles = self._string_to_136_array(sou='12355689', man='89', honors='44') player.init_hand(tiles) player.dealer_seat = 1 self.assertEqual(strategy.should_activate_strategy(), True) tiles = self._string_to_136_array(sou='12355689', man='89', honors='666') player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(), True) # with chitoitsu-like hand we don't need to go for yakuhai tiles = self._string_to_136_array(sou='1235566', man='8899', honors='66') player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(), False)
def test_dont_activate_strategy_if_we_dont_have_enough_tiles_in_the_wall( self): strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) self.table.dora_indicators.append(self._string_to_136_tile(honors='7')) tiles = self._string_to_136_array(man='59', sou='1235', pin='12789', honors='55') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), True) self.table.add_discarded_tile(3, self._string_to_136_tile(honors='5'), False) self.table.add_discarded_tile(3, self._string_to_136_tile(honors='5'), False) # we can't complete yakuhai, because there is not enough honor tiles self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False)
def test_should_activate_strategy(self): strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) tiles = self._string_to_136_array(sou='12355689', man='89', honors='123') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False) self.table.dora_indicators.append(self._string_to_136_tile(honors='7')) tiles = self._string_to_136_array(sou='12355689', man='899', honors='55') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), True) # with chitoitsu-like hand we don't need to go for yakuhai tiles = self._string_to_136_array(sou='1235566', man='8899', honors='66') self.player.init_hand(tiles) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), False) # don't count tile discarded by other player as our pair tiles = self._string_to_136_array(sou='12355689', man='899', honors='25') self.player.init_hand(tiles) tiles = self._string_to_136_array(sou='12355689', man='899', honors='255') self.assertEqual(strategy.should_activate_strategy(tiles), False)
def test_atodzuke_keep_yakuhai_wait(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='11144', sou='567', pin='567', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) # two of 4 man tiles are already out, so it would seem our wait is worse, but we know # we must keep two pairs in order to be atodzuke tempai table.add_discarded_tile(1, self._string_to_136_tile(man='4'), False) table.add_discarded_tile(1, self._string_to_136_tile(man='4'), False) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) player.draw_tile(self._string_to_136_tile(man='2')) discarded_tile = player.discard_tile() self.assertEqual(self._to_string([discarded_tile]), '2m')
def test_atodzuke_choose_hidden_syanpon(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='111678', sou='56678', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) for _ in range(0, 4): table.add_discarded_tile(1, self._string_to_136_tile(sou='9'), False) player.draw_tile(self._string_to_136_tile(man='6')) discarded_tile = player.discard_tile() self.assertNotEqual(self._to_string([discarded_tile]), '6m')
def test_force_yakuhai_pair_waiting_for_tempai_hand(self): """ If hand shanten = 1 don't open hand except the situation where is we have tempai on yakuhai tile after open set """ self.table.dora_indicators.append(self._string_to_136_tile(man='3')) tiles = self._string_to_136_array(sou='123', pin='678', man='34468', honors='66') self.player.init_hand(tiles) # we will not get tempai on yakuhai pair with this hand, so let's skip this call tile = self._string_to_136_tile(man='5') meld, _ = self.player.try_to_call_meld(tile, False) self.assertEqual(meld, None) # but here we will have atodzuke tempai tile = self._string_to_136_tile(man='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) self.assertEqual(meld.type, Meld.CHI) self.assertEqual(self._to_string(meld.tiles), '678m') self.table = Table() self.player = self.table.player # we can open hand in that case self.table.dora_indicators.append(self._string_to_136_tile(sou='5')) tiles = self._string_to_136_array(man='44556', sou='366789', honors='77') self.player.init_hand(tiles) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) self.assertEqual(strategy.should_activate_strategy(self.player.tiles), True) tile = self._string_to_136_tile(honors='7') meld, _ = self.player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) self.assertEqual(self._to_string(meld.tiles), '777z')
def test_atodzuke_dont_open_no_yaku_tempai(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='111445', sou='567', pin='56', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) # 6 man is bad meld, we lose our second pair and so is 4 man tile = self._string_to_136_tile(man='6') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) tile = self._string_to_136_tile(man='4') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) # 7 pin is a good meld, we get to tempai keeping yakuhai wait tile = self._string_to_136_tile(pin='7') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True)
def test_atodzuke_dont_destroy_second_pair(self): # make sure yakuhai strategy is activated by adding 3 doras to the hand table = Table() player = table.player table.add_dora_indicator(self._string_to_136_tile(man='9')) tiles = self._string_to_136_array(man='111445', sou='468', pin='56', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) # 6 man is bad meld, we lose our second pair and so is 4 man tile = self._string_to_136_tile(man='6') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) tile = self._string_to_136_tile(man='4') meld, _ = player.try_to_call_meld(tile, True) self.assertEqual(meld, None) # but if we have backup pair it's ok tiles = self._string_to_136_array(man='111445', sou='468', pin='88', honors='77') player.init_hand(tiles) meld = self._make_meld(Meld.PON, man='111') player.add_called_meld(meld) strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) self.assertEqual(strategy.should_activate_strategy(player.tiles), True) # 6 man is bad meld, we lose our second pair and so is 4 man tile = self._string_to_136_tile(man='6') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None) tile = self._string_to_136_tile(man='4') meld, _ = player.try_to_call_meld(tile, True) self.assertNotEqual(meld, None)
def test_tempai_with_open_yakuhai_meld_and_yakuhai_pair_in_the_hand(self): """ there was a bug where bot didn't handle tempai properly with opened yakuhai pon and pair in the hand 56m555p6678s55z + [777z] """ table = Table() player = table.player tiles = self._string_to_136_array(man='56', pin='555', sou='667', honors='55777') player.init_hand(tiles) player.add_called_meld(self._make_meld(Meld.PON, honors='777')) player.draw_tile(self._string_to_136_tile(sou='8')) player.ai.current_strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, player) discarded_tile = player.discard_tile() self.assertEqual(self._to_string([discarded_tile]), '6s')
def determine_strategy(self, tiles_136): # for already opened hand we don't need to give up on selected strategy if self.player.is_open_hand and self.current_strategy: return False old_strategy = self.current_strategy self.current_strategy = None # order is important, we add strategies with the highest priority first strategies = [] if self.player.table.has_open_tanyao: strategies.append(TanyaoStrategy(BaseStrategy.TANYAO, self.player)) strategies.append(YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player)) strategies.append(HonitsuStrategy(BaseStrategy.HONITSU, self.player)) strategies.append(ChinitsuStrategy(BaseStrategy.CHINITSU, self.player)) strategies.append(ChiitoitsuStrategy(BaseStrategy.CHIITOITSU, self.player)) strategies.append(FormalTempaiStrategy(BaseStrategy.FORMAL_TEMPAI, self.player)) for strategy in strategies: if strategy.should_activate_strategy(tiles_136): self.current_strategy = strategy break if self.current_strategy: if not old_strategy or self.current_strategy.type != old_strategy.type: DecisionsLogger.debug( log.STRATEGY_ACTIVATE, context=self.current_strategy, ) if not self.current_strategy and old_strategy: DecisionsLogger.debug(log.STRATEGY_DROP, context=old_strategy) return self.current_strategy and True or False
def test_suitable_tiles(self): strategy = YakuhaiStrategy(BaseStrategy.YAKUHAI, self.player) # for yakuhai we can use any tile for tile in range(0, 136): self.assertEqual(strategy.is_tile_suitable(tile), True)