def test_calculate_suit_tiles_value_and_dora(self): table = Table() table.dora_indicators = [self._string_to_136_tile(sou='9')] player = table.player tile = self._string_to_34_tile(sou='1') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_VALUE + 110) # double dora table.dora_indicators = [self._string_to_136_tile(sou='9'), self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(sou='1') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_VALUE * 2 + 110) # tile close to dora table.dora_indicators = [self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(sou='2') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_FIRST_NEIGHBOUR + 120) # tile not far away from dora table.dora_indicators = [self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(sou='3') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_SECOND_NEIGHBOUR + 140) # tile from other suit table.dora_indicators = [self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(man='3') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, 140)
def test_calculate_suit_tiles_value_and_dora(self): table = Table() table.dora_indicators = [self._string_to_136_tile(sou='9')] player = table.player tile = self._string_to_34_tile(sou='1') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, 160) # double dora table.dora_indicators = [self._string_to_136_tile(sou='9'), self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(sou='1') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, 210)
def test_slide_set_to_keep_dora_in_hand(): table = Table() table.dora_indicators = [string_to_136_tile(pin="9")] player = table.player tiles = string_to_136_array(sou="123456", pin="23478", man="99") tile = string_to_136_tile(pin="1") player.init_hand(tiles) player.draw_tile(tile) # 2p is a dora, we had to keep it discarded_tile, _ = player.discard_tile() assert tiles_to_string([discarded_tile]) == "4p"
def test_slide_set_to_keep_dora_in_hand(self): table = Table() table.dora_indicators = [self._string_to_136_tile(pin='9')] player = table.player tiles = self._string_to_136_array(sou='123456', pin='23478', man='99') tile = self._string_to_136_tile(pin='1') player.init_hand(tiles) player.draw_tile(tile) # 2p is a dora, we had to keep it discarded_tile = player.discard_tile() self.assertEqual(self._to_string([discarded_tile]), '4p')
def test_calculate_suit_tiles_value_and_dora(self): table = Table() table.dora_indicators = [self._string_to_136_tile(sou='9')] player = table.player tile = self._string_to_34_tile(sou='1') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_VALUE + 110) # double dora table.dora_indicators = [ self._string_to_136_tile(sou='9'), self._string_to_136_tile(sou='9') ] tile = self._string_to_34_tile(sou='1') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_VALUE * 2 + 110) # tile close to dora table.dora_indicators = [self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(sou='2') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_FIRST_NEIGHBOUR + 120) # tile not far away from dora table.dora_indicators = [self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(sou='3') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, DiscardOption.DORA_SECOND_NEIGHBOUR + 140) # tile from other suit table.dora_indicators = [self._string_to_136_tile(sou='9')] tile = self._string_to_34_tile(man='3') option = DiscardOption(player, tile, 0, [], 0) self.assertEqual(option.valuation, 140)
def test_keep_aka_dora_in_hand(): table = Table() table.dora_indicators = [string_to_136_tile(pin="1")] table.has_aka_dora = True player = table.player tiles = string_to_136_array(sou="12346", pin="34578", man="99") # five sou, we can't get it from string (because from string it is always aka dora) tiles += [89] player.init_hand(tiles) player.draw_tile(FIVE_RED_SOU) # we had to keep red five and discard just 5s discarded_tile, _ = player.discard_tile() assert discarded_tile != FIVE_RED_SOU
def test_calculate_suit_tiles_value_and_dora(): table = Table() table.dora_indicators = [string_to_136_tile(sou="9")] player = table.player table.has_aka_dora = False tile = string_to_136_tile(sou="1") option = DiscardOption(player, tile, 0, [], 0) assert option.valuation == (DiscardOption.DORA_VALUE + 110) # double dora table.dora_indicators = [ string_to_136_tile(sou="9"), string_to_136_tile(sou="9") ] tile = string_to_136_tile(sou="1") option = DiscardOption(player, tile, 0, [], 0) assert option.valuation == ((DiscardOption.DORA_VALUE * 2) + 110) # tile close to dora table.dora_indicators = [string_to_136_tile(sou="9")] tile = string_to_136_tile(sou="2") option = DiscardOption(player, tile, 0, [], 0) assert option.valuation == (DiscardOption.DORA_FIRST_NEIGHBOUR + 120) # tile not far away from dora table.dora_indicators = [string_to_136_tile(sou="9")] tile = string_to_136_tile(sou="3") option = DiscardOption(player, tile, 0, [], 0) assert option.valuation == (DiscardOption.DORA_SECOND_NEIGHBOUR + 140) # tile from other suit table.dora_indicators = [string_to_136_tile(sou="9")] tile = string_to_136_tile(man="3") option = DiscardOption(player, tile, 0, [], 0) assert option.valuation == 140
def test_keep_aka_dora_in_hand(self): table = Table() table.dora_indicators = [self._string_to_136_tile(pin='1')] table.has_aka_dora = True player = table.player tiles = self._string_to_136_array(sou='12346', pin='34578', man='99') # five sou, we can't get it from string (because from string it is always aka dora) tiles += [89] player.init_hand(tiles) player.draw_tile(FIVE_RED_SOU) # we had to keep red five and discard just 5s discarded_tile = player.discard_tile() self.assertNotEqual(discarded_tile, FIVE_RED_SOU)
def test_detect_enemy_tempai_and_opened_sets(self): table = Table() self.assertEqual(EnemyAnalyzer(table.get_player(1)).in_tempai, False) self.assertEqual(EnemyAnalyzer(table.get_player(1)).is_threatening, False) table.add_called_meld(1, self._make_meld(Meld.CHI, sou='567')) table.add_called_meld(1, self._make_meld(Meld.CHI, pin='123')) table.add_called_meld(1, self._make_meld(Meld.CHI, man='345')) table.add_called_meld(1, self._make_meld(Meld.PON, man='777')) self.assertEqual(EnemyAnalyzer(table.get_player(1)).in_tempai, True) self.assertEqual(EnemyAnalyzer(table.get_player(1)).is_threatening, False) table.dora_indicators = [self._string_to_136_tile(man='6')] # enemy opened the pon of dor, so better to fold against him self.assertEqual(EnemyAnalyzer(table.get_player(1)).in_tempai, True) self.assertEqual(EnemyAnalyzer(table.get_player(1)).is_threatening, True)
def test_detect_enemy_tempai_and_opened_sets(self): table = Table() self.assertEqual(EnemyAnalyzer(table.get_player(1)).in_tempai, False) self.assertEqual( EnemyAnalyzer(table.get_player(1)).is_threatening, False) table.add_called_meld(1, self._make_meld(Meld.CHI, sou='567')) table.add_called_meld(1, self._make_meld(Meld.CHI, pin='123')) table.add_called_meld(1, self._make_meld(Meld.CHI, man='345')) table.add_called_meld(1, self._make_meld(Meld.PON, man='777')) self.assertEqual(EnemyAnalyzer(table.get_player(1)).in_tempai, True) self.assertEqual( EnemyAnalyzer(table.get_player(1)).is_threatening, False) table.dora_indicators = [self._string_to_136_tile(man='6')] # enemy opened the pon of dor, so better to fold against him self.assertEqual(EnemyAnalyzer(table.get_player(1)).in_tempai, True) self.assertEqual( EnemyAnalyzer(table.get_player(1)).is_threatening, True)
def test_is_dora(self): table = Table() table.init_round(0, 0, 0, 0, 0, []) table.dora_indicators = [self._string_to_136_tile(sou='1')] self.assertTrue(table.is_dora(self._string_to_136_tile(sou='2'))) table.dora_indicators = [self._string_to_136_tile(sou='9')] self.assertTrue(table.is_dora(self._string_to_136_tile(sou='1'))) table.dora_indicators = [self._string_to_136_tile(pin='9')] self.assertTrue(table.is_dora(self._string_to_136_tile(pin='1'))) table.dora_indicators = [self._string_to_136_tile(man='9')] self.assertTrue(table.is_dora(self._string_to_136_tile(man='1'))) table.dora_indicators = [self._string_to_136_tile(man='5')] self.assertTrue(table.is_dora(self._string_to_136_tile(man='6'))) table.dora_indicators = [self._string_to_136_tile(honors='1')] self.assertTrue(table.is_dora(self._string_to_136_tile(honors='2'))) table.dora_indicators = [self._string_to_136_tile(honors='2')] self.assertTrue(table.is_dora(self._string_to_136_tile(honors='3'))) table.dora_indicators = [self._string_to_136_tile(honors='3')] self.assertTrue(table.is_dora(self._string_to_136_tile(honors='4'))) table.dora_indicators = [self._string_to_136_tile(honors='4')] self.assertTrue(table.is_dora(self._string_to_136_tile(honors='1'))) table.dora_indicators = [self._string_to_136_tile(honors='5')] self.assertTrue(table.is_dora(self._string_to_136_tile(honors='6'))) table.dora_indicators = [self._string_to_136_tile(honors='6')] self.assertTrue(table.is_dora(self._string_to_136_tile(honors='7'))) table.dora_indicators = [self._string_to_136_tile(honors='7')] self.assertTrue(table.is_dora(self._string_to_136_tile(honors='5'))) table.dora_indicators = [self._string_to_136_tile(pin='1')] self.assertFalse(table.is_dora(self._string_to_136_tile(sou='2'))) table.has_open_tanyao = True # red five man self.assertTrue(table.is_dora(FIVE_RED_MAN)) # red five pin self.assertTrue(table.is_dora(FIVE_RED_PIN)) # red five sou self.assertTrue(table.is_dora(FIVE_RED_SOU))
def test_is_dora(): table = Table() table.init_round(0, 0, 0, 0, 0, []) table.dora_indicators = [string_to_136_tile(sou="1")] assert table.is_dora(string_to_136_tile(sou="2")) table.dora_indicators = [string_to_136_tile(sou="9")] assert table.is_dora(string_to_136_tile(sou="1")) table.dora_indicators = [string_to_136_tile(pin="9")] assert table.is_dora(string_to_136_tile(pin="1")) table.dora_indicators = [string_to_136_tile(man="9")] assert table.is_dora(string_to_136_tile(man="1")) table.dora_indicators = [string_to_136_tile(man="5")] assert table.is_dora(string_to_136_tile(man="6")) table.dora_indicators = [string_to_136_tile(honors="1")] assert table.is_dora(string_to_136_tile(honors="2")) table.dora_indicators = [string_to_136_tile(honors="2")] assert table.is_dora(string_to_136_tile(honors="3")) table.dora_indicators = [string_to_136_tile(honors="3")] assert table.is_dora(string_to_136_tile(honors="4")) table.dora_indicators = [string_to_136_tile(honors="4")] assert table.is_dora(string_to_136_tile(honors="1")) table.dora_indicators = [string_to_136_tile(honors="5")] assert table.is_dora(string_to_136_tile(honors="6")) table.dora_indicators = [string_to_136_tile(honors="6")] assert table.is_dora(string_to_136_tile(honors="7")) table.dora_indicators = [string_to_136_tile(honors="7")] assert table.is_dora(string_to_136_tile(honors="5")) table.dora_indicators = [string_to_136_tile(pin="1")] assert not table.is_dora(string_to_136_tile(sou="2")) table.has_open_tanyao = True # red five man assert table.is_dora(FIVE_RED_MAN) # red five pin assert table.is_dora(FIVE_RED_PIN) # red five sou assert table.is_dora(FIVE_RED_SOU)