Exemplo n.º 1
0
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)
Exemplo n.º 2
0
    def test_discard_not_valuable_honor_first(self):
        table = Table()
        player = table.player

        tiles = self._string_to_136_array(sou='123456',
                                          pin='123455',
                                          man='9',
                                          honors='2')
        player.init_hand(tiles)

        discarded_tile = player.discard_tile()
        self.assertEqual(self._to_string([discarded_tile]), '2z')
    def test_dont_call_meld(self):
        table = Table()
        player = table.player
        strategy = ChiitoitsuStrategy(BaseStrategy.CHIITOITSU, player)

        tiles = self._string_to_136_array(sou='112234', man='2334499')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), True)

        tile = self._string_to_136_tile(man='9')
        meld, _ = player.try_to_call_meld(tile, True)
        self.assertEqual(meld, None)
Exemplo n.º 4
0
    def test_should_activate_strategy(self):
        table = Table()
        player = table.player
        strategy = HonitsuStrategy(BaseStrategy.HONITSU, player)

        table.add_dora_indicator(self._string_to_136_tile(pin='1'))
        table.add_dora_indicator(self._string_to_136_tile(honors='5'))

        tiles = self._string_to_136_array(sou='12355', man='12389', honors='123')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)

        # many tiles in one suit and yakuhai pair, but still many useless winds
        tiles = self._string_to_136_array(sou='12355', man='23', pin='68', honors='2355')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)

        # many tiles in one suit and yakuhai pair and another honor pair, so
        # now this is honitsu
        tiles = self._string_to_136_array(sou='12355', man='238', honors='22355')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), True)

        # same conditions, but ready suit with dora in another suit, so no honitsu
        tiles = self._string_to_136_array(sou='12355', pin='234', honors='22355')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)

        # same conditions, but we have a pon of yakuhai doras, we shouldn't
        # force honitsu with this hand
        tiles = self._string_to_136_array(sou='12355', pin='238', honors='22666')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)

        # if we have a complete set with dora, we shouldn't go for honitsu
        tiles = self._string_to_136_array(sou='11123688', pin='123', honors='55')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)

        # even if the set may be interpreted as two forms
        tiles = self._string_to_136_array(sou='1223688', pin='2334', honors='55')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)

        # even if the set may be interpreted as two forms v2
        tiles = self._string_to_136_array(sou='1223688', pin='2345', honors='55')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)

        # if we have a long form with dora, we shouldn't go for honitsu
        tiles = self._string_to_136_array(sou='1223688', pin='2333', honors='55')
        player.init_hand(tiles)
        self.assertEqual(strategy.should_activate_strategy(player.tiles), False)
Exemplo n.º 5
0
    def test_discard_not_effective_tiles_first(self):
        table = Table()
        player = table.player
        player.scores = 25000
        table.count_of_remaining_tiles = 100

        tiles = self._string_to_136_array(man='33', pin='12788999', sou='5', honors='23')
        player.init_hand(tiles)
        player.draw_tile(self._string_to_136_tile(honors='6'))
        tile_to_discard = player.discard_tile()

        self.assertEqual(self._to_string([tile_to_discard]), '5s')
Exemplo n.º 6
0
def test_get_common_tempai_sandoko():
    table = Table()

    table.add_dora_indicator(string_to_136_tile(man="1"))

    tiles = string_to_136_array(man="222", sou="2278", pin="222899")
    table.player.init_hand(tiles)

    tile = string_to_136_tile(sou="2")
    meld, _ = table.player.try_to_call_meld(tile, False)
    assert meld is not None
    assert tiles_to_string(meld.tiles) == "222s"
Exemplo n.º 7
0
def test_get_common_tempai_sanshoku():
    table = Table()

    table.add_dora_indicator(string_to_136_tile(man="8"))

    tiles = string_to_136_array(man="13999", sou="123", pin="12899")
    table.player.init_hand(tiles)

    tile = string_to_136_tile(pin="3")
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is not None
    assert tiles_to_string(meld.tiles) == "123p"
Exemplo n.º 8
0
    def test_player_called_meld_and_closed_hand(self):
        table = Table()
        player = table.player

        tiles = self._string_to_136_array(sou='123678', pin='3599', honors='555')
        player.init_hand(tiles)

        self.assertEqual(len(player.closed_hand), 13)

        player.add_called_meld(self._make_meld(Meld.PON, honors='555'))

        self.assertEqual(len(player.closed_hand), 10)
def test_tempai_without_yaku():
    table = Table()
    tiles = string_to_136_array(sou="678", pin="12355", man="456", honors="77")
    table.player.init_hand(tiles)

    tile = string_to_136_tile(pin="5")
    table.player.draw_tile(tile)
    meld = make_meld(MeldPrint.CHI, sou="678")
    table.player.add_called_meld(meld)

    discard, _ = table.player.discard_tile()
    assert tiles_to_string([discard]) != "7z"
Exemplo n.º 10
0
def test_call_shouminkan():
    table = Table()
    table.count_of_remaining_tiles = 10

    tiles = string_to_136_array(man="3455567", sou="222", honors="666")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.PON, honors="666"))

    tile = string_to_136_array(honors="6666")[3]
    table.player.draw_tile(tile)

    assert table.player.should_call_kan(tile, False) == MeldPrint.SHOUMINKAN
Exemplo n.º 11
0
    def test_detect_enemy_tempai_and_riichi(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_riichi(1)

        self.assertEqual(EnemyAnalyzer(table.get_player(1)).in_tempai, True)
        self.assertEqual(
            EnemyAnalyzer(table.get_player(1)).is_threatening, True)
Exemplo n.º 12
0
    def test_not_open_hand_in_defence_mode(self):
        table = Table()
        player = table.player

        tiles = self._string_to_136_array(sou='12368', pin='2358', honors='4455')
        player.init_hand(tiles)

        table.add_called_riichi(1)

        tile = self._string_to_136_tile(honors='5')
        meld, _ = player.try_to_call_meld(tile, False)
        self.assertEqual(meld, None)
Exemplo n.º 13
0
def test_discard_not_effective_tiles_first():
    table = Table()
    player = table.player
    player.scores = 25000
    table.count_of_remaining_tiles = 100

    tiles = string_to_136_array(man="33", pin="12788999", sou="5", honors="77")
    player.init_hand(tiles)
    player.draw_tile(string_to_136_tile(honors="6"))
    tile_to_discard = player.discard_tile()

    assert tiles_to_string([tile_to_discard]) == "5s"
Exemplo n.º 14
0
def test_shouminkan_and_weak_hand():
    table = Table()
    table.count_of_remaining_tiles = 40

    tiles = string_to_136_array(man="135567", sou="248", pin="5", honors="666")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.PON, honors="666"))

    tile = string_to_136_array(honors="6666")[3]
    table.player.draw_tile(tile)

    assert table.player.should_call_kan(tile, False) is None
Exemplo n.º 15
0
def test_player_called_meld_and_closed_hand():
    table = Table()
    player = table.player

    tiles = string_to_136_array(sou="123678", pin="3599", honors="555")
    player.init_hand(tiles)

    assert len(player.closed_hand) == 13

    player.add_called_meld(make_meld(MeldPrint.PON, honors="555"))

    assert len(player.closed_hand) == 10
Exemplo n.º 16
0
def test_discard_not_valuable_honor_first():
    table = Table()
    player = table.player

    tiles = string_to_136_array(sou="123456",
                                pin="123455",
                                man="9",
                                honors="2")
    player.init_hand(tiles)

    discarded_tile = player.discard_tile()
    assert tiles_to_string([discarded_tile]) == "2z"
Exemplo n.º 17
0
    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))
Exemplo n.º 18
0
    def test_closed_kan_and_not_necessary_call(self):
        """
        Bot tried to call closed kan with 568m669p1478999s + 9s hand
        """
        table = Table()
        player = table.player

        tiles = self._string_to_136_array(man='568', sou='1478999', pin='669')
        player.init_hand(tiles)
        tile = self._string_to_136_tile(sou='9')

        self.assertEqual(player.should_call_kan(tile, False), None)
Exemplo n.º 19
0
def test_should_activate_strategy():
    table = Table()
    player = table.player
    strategy = HonitsuStrategy(BaseStrategy.HONITSU, player)

    table.add_dora_indicator(string_to_136_tile(pin="1"))
    table.add_dora_indicator(string_to_136_tile(honors="5"))

    tiles = string_to_136_array(sou="12355", man="12389", honors="123")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False

    # many tiles in one suit and yakuhai pair, but still many useless winds
    tiles = string_to_136_array(sou="12355", man="23", pin="68", honors="2355")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False

    # many tiles in one suit and yakuhai pair and another honor pair, so
    # now this is honitsu
    tiles = string_to_136_array(sou="12355", man="238", honors="22355")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is True

    # same conditions, but ready suit with dora in another suit, so no honitsu
    tiles = string_to_136_array(sou="12355", pin="234", honors="22355")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False

    # same conditions, but we have a pon of yakuhai doras, we shouldn't
    # force honitsu with this hand
    tiles = string_to_136_array(sou="12355", pin="238", honors="22666")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False

    # if we have a complete set with dora, we shouldn't go for honitsu
    tiles = string_to_136_array(sou="11123688", pin="123", honors="55")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False

    # even if the set may be interpreted as two forms
    tiles = string_to_136_array(sou="1223688", pin="2334", honors="55")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False

    # even if the set may be interpreted as two forms v2
    tiles = string_to_136_array(sou="1223688", pin="2345", honors="55")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False

    # if we have a long form with dora, we shouldn't go for honitsu
    tiles = string_to_136_array(sou="1223688", pin="2333", honors="55")
    player.init_hand(tiles)
    assert strategy.should_activate_strategy(player.tiles) is False
Exemplo n.º 20
0
    def test_get_more_yakuhai_sets_in_hand(self):
        table = Table()

        tiles = self._string_to_136_array(sou='1378',
                                          pin='67',
                                          man='68',
                                          honors='5566')
        table.player.init_hand(tiles)

        tile = self._string_to_136_tile(honors='5')
        meld, discard_option = table.player.try_to_call_meld(tile, False)
        self.assertNotEqual(meld, None, "Should call meld in this situation.")

        table.add_called_meld(0, meld)
        table.player.tiles.append(tile)
        table.player.discard_tile(discard_option)

        tile = self._string_to_136_tile(honors='6')
        meld, _ = table.player.try_to_call_meld(tile, False)
        self.assertNotEqual(meld, None)

        table = Table()

        tiles = self._string_to_136_array(sou='234',
                                          pin='788',
                                          man='567',
                                          honors='5566')
        table.player.init_hand(tiles)

        tile = self._string_to_136_tile(honors='5')
        meld, discard_option = table.player.try_to_call_meld(tile, False)
        self.assertNotEqual(meld, None)

        table.add_called_meld(0, meld)
        table.player.tiles.append(tile)
        table.player.discard_tile(discard_option)

        tile = self._string_to_136_tile(honors='6')
        meld, _ = table.player.try_to_call_meld(tile, False)
        self.assertEqual(meld, None)
Exemplo n.º 21
0
    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
        """
        table = Table()
        player = table.player

        tiles = self._string_to_136_array(sou='123',
                                          pin='678',
                                          man='34468',
                                          honors='66')
        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, _ = 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, _ = 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')

        table = Table()
        player = table.player

        # we can open hand in that case
        tiles = self._string_to_136_array(man='44556',
                                          sou='366789',
                                          honors='77')
        player.init_hand(tiles)

        tile = self._string_to_136_tile(honors='7')
        meld, _ = player.try_to_call_meld(tile, True)
        self.assertNotEqual(meld, None)
        self.assertEqual(self._to_string(meld.tiles), '777z')
Exemplo n.º 22
0
    def test_call_riichi_and_penchan_wait(self):
        table = Table()
        table.count_of_remaining_tiles = 60
        player = table.player
        player.scores = 25000

        tiles = self._string_to_136_array(sou='11223', pin='234567', man='66')
        tile = self._string_to_136_tile(man='9')
        player.init_hand(tiles)
        player.draw_tile(tile)
        player.discard_tile()

        self.assertEqual(player.can_call_riichi(), True)
Exemplo n.º 23
0
def test_threatening_riichi_player_and_not_early_hand_bonus():
    table = Table()
    enemy_seat = 2
    discards = string_to_136_array(sou="111122")
    for discard in discards:
        table.add_discarded_tile(enemy_seat, discard, False)
    enemy_called_riichi_helper(table, enemy_seat)

    # +1 scale for riichi on 6+ turn
    threatening_player = table.player.ai.defence.get_threatening_players()[0]
    assert threatening_player.enemy.seat == enemy_seat
    assert threatening_player.get_assumed_hand_cost(
        string_to_136_tile(man="2")) == 3900
Exemplo n.º 24
0
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"
Exemplo n.º 25
0
def chiitoitsu_tanyao_tempai():
    table = Table()
    player = table.player

    tiles = string_to_136_array(sou="223344", pin="788", man="4577")
    player.init_hand(tiles)

    player.draw_tile(string_to_136_tile(man="4"))

    discard = player.discard_tile()
    discard_correct = tiles_to_string([discard]) == "7p" or tiles_to_string(
        [discard]) == "5m"
    assert discard_correct is True
Exemplo n.º 26
0
def test_closed_kan_and_not_necessary_call():
    """
    Bot tried to call closed kan with 568m669p1478999s + 9s hand
    """
    table = Table()
    player = table.player

    tiles = string_to_136_array(man="568", sou="1478999", pin="669")
    player.init_hand(tiles)
    tile = string_to_136_tile(sou="9")
    player.draw_tile(tile)

    assert player.should_call_kan(tile, False) is None
Exemplo n.º 27
0
def _make_table(dora_indicators=None):
    table = Table()
    table.count_of_remaining_tiles = 60
    table.player.scores = 25000

    # with that we don't have daburi anymore
    table.player.round_step = 1

    if dora_indicators:
        for x in dora_indicators:
            table.add_dora_indicator(x)

    return table
Exemplo n.º 28
0
def test_open_hand_and_not_go_for_atodzuke_yakuhai():
    table = Table()
    # dora here to activate honitsu strategy
    table.add_dora_indicator(string_to_136_tile(sou="9"))
    player = table.player
    player.seat = 1

    tiles = string_to_136_array(sou="1112345678", honors="557")
    player.init_hand(tiles)
    tile = string_to_136_array(sou="1111")[3]
    meld, _ = player.try_to_call_meld(tile, False)
    assert meld is not None
    assert tiles_to_string(meld.tiles) == "111s"
Exemplo n.º 29
0
def test_call_shouminkan_and_bad_ukeire_after_call_third_case():
    table = Table()
    table.count_of_remaining_tiles = 10

    tiles = string_to_136_array(man="67", pin="6", sou="1344478999")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.PON, sou="444"))

    tile = string_to_136_array(sou="4444")[3]
    table.player.draw_tile(tile)

    # we don't want to call shouminkan here
    assert table.player.should_call_kan(tile, False) is None
Exemplo n.º 30
0
    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')