def test_dont_call_riichi_with_tanki_wait(self):
        table = Table()
        table.count_of_remaining_tiles = 60
        player = table.player
        player.scores = 25000

        tiles = self._string_to_136_array(sou='123456', pin='123456', man='3')
        player.init_hand(tiles)

        player.draw_tile(self._string_to_136_tile(man='4'))
        player.discard_tile()

        self.assertEqual(player.can_call_riichi(), False)

        table = Table()
        table.count_of_remaining_tiles = 60
        player = table.player
        player.scores = 25000

        tiles = self._string_to_136_array(sou='1133557799', pin='113')
        tile = self._string_to_136_tile(pin='6')
        player.init_hand(tiles)
        player.draw_tile(tile)
        player.discard_tile()

        # for chitoitsu it is ok to have a pair wait
        self.assertEqual(player.can_call_riichi(), True)
Example #2
0
def test_opened_kan_and_threatening_riichi():
    table = Table()
    table.count_of_remaining_tiles = 10

    enemy_seat = 2
    table.add_called_riichi_step_one(enemy_seat)

    threatening_players = table.player.ai.defence.get_threatening_players()
    assert len(threatening_players) == 1
    assert threatening_players[0].enemy.seat == enemy_seat
    assert threatening_players[0].threat_reason[
        "id"] == EnemyDanger.THREAT_RIICHI["id"]

    tiles = string_to_136_array(man="2399", sou="111456", honors="111")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.PON, honors="111"))

    # to rebuild all caches
    table.player.draw_tile(string_to_136_tile(pin="9"))
    table.player.discard_tile()

    # our hand is open, in tempai and with a good wait but there is a riichi so calling open kan is a bad idea
    tile = string_to_136_tile(sou="1")
    assert table.player.should_call_kan(tile, True) is None
    assert table.player.try_to_call_meld(tile, True) == (None, None)
Example #3
0
    def test_call_shouminkan(self):
        table = Table()
        table.count_of_remaining_tiles = 10

        tiles = self._string_to_136_array(man='3455567', sou='222', honors='666')
        table.player.init_hand(tiles)
        table.player.add_called_meld(self._make_meld(Meld.PON, honors='666'))

        tile = self._string_to_136_tile(honors='6')

        self.assertEqual(table.player.should_call_kan(tile, False), Meld.CHANKAN)
Example #4
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
    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')
Example #6
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"
Example #7
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
Example #8
0
def test_discard_not_effective_tiles_first_not_honitsu():
    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="23")
    player.init_hand(tiles)
    player.draw_tile(string_to_136_tile(honors="6"))
    tile_to_discard, _ = player.discard_tile()

    # this is not really a honitsu
    assert tiles_to_string([tile_to_discard]) == "2z" or tiles_to_string([tile_to_discard]) == "3z"
Example #9
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
    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)
Example #11
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
Example #12
0
def test_closed_kan_in_riichi():
    table = Table()
    table.count_of_remaining_tiles = 10

    tiles = string_to_136_array(man="456", pin="78999", sou="666", honors="33")
    table.player.init_hand(tiles)

    # to rebuild all caches
    table.player.draw_tile(string_to_136_tile(honors="6"))
    table.player.discard_tile()

    tile = string_to_136_tile(sou="6")
    table.player.draw_tile(tile)
    assert table.player.should_call_kan(tile, open_kan=False, from_riichi=True) == MeldPrint.KAN
Example #13
0
    def test_kan_crash(self):
        """
        This was a crash in real game
        related with open kan logic and agari without yaku state
        """
        table = Table()
        table.count_of_remaining_tiles = 10

        tiles = self._string_to_136_array(man='456', pin='78999', sou='666', honors='33')
        table.player.init_hand(tiles)
        table.player.add_called_meld(self._make_meld(Meld.PON, sou='666'))
        tile = self._string_to_136_tile(pin='9')

        self.assertEqual(table.player.should_call_kan(tile, False), None)
    def test_riichi_and_tiles_from_another_suit_in_the_hand(self):
        table = Table()
        player = table.player
        player.scores = 25000
        table.count_of_remaining_tiles = 100

        tiles = self._string_to_136_array(man='33345678', pin='22', honors='155')
        player.init_hand(tiles)

        player.draw_tile(self._string_to_136_tile(man='9'))
        tile_to_discard = player.discard_tile()

        # we don't need to go for honitsu here
        # we already in tempai
        self.assertEqual(self._to_string([tile_to_discard]), '1z')
Example #15
0
    def test_opened_kan_second_case(self):
        table = Table()
        table.count_of_remaining_tiles = 10

        tiles = self._string_to_136_array(man='2399', sou='111456', honors='111')
        table.player.init_hand(tiles)
        table.player.add_called_meld(self._make_meld(Meld.PON, honors='111'))

        # to rebuild all caches
        table.player.draw_tile(self._string_to_136_tile(pin='9'))
        table.player.discard_tile()

        # our hand is open, in tempai and with a good wait
        tile = self._string_to_136_tile(sou='1')
        self.assertEqual(table.player.should_call_kan(tile, True), Meld.KAN)
Example #16
0
def test_riichi_and_tiles_from_another_suit_in_the_hand():
    table = Table()
    player = table.player
    player.scores = 25000
    table.count_of_remaining_tiles = 100

    tiles = string_to_136_array(man="33345678", pin="22", honors="155")
    player.init_hand(tiles)

    player.draw_tile(string_to_136_tile(man="9"))
    tile_to_discard = player.discard_tile()

    # we don't need to go for honitsu here
    # we already in tempai
    assert tiles_to_string([tile_to_discard]) == "1z"
    def test_call_riichi_with_bad_wait_against_other_player_riichi(self):
        table = Table()
        table.count_of_remaining_tiles = 60
        table.player.scores = 25000

        tiles = self._string_to_136_array(sou='11223', pin='234678', man='55')
        table.player.init_hand(tiles)
        table.player.draw_tile(self._string_to_136_tile(man='9'))

        table.add_called_riichi(3)

        discard = table.player.discard_tile()
        self.assertEqual(self._to_string([discard]), '9m')
        self.assertEqual(table.player.ai.in_defence, True)
        self.assertEqual(table.player.can_call_riichi(), False)
Example #18
0
def test_call_shouminkan_and_bad_ukeire_after_call():
    table = Table()
    table.count_of_remaining_tiles = 10

    tiles = string_to_136_array(man="34445", sou="123456", pin="89")
    table.player.init_hand(tiles)
    tile = string_to_136_array(man="4444")[3]
    table.player.draw_tile(tile)

    assert table.player.should_call_kan(tile, False) is None

    table.player.add_called_meld(make_meld(MeldPrint.PON, man="444"))

    assert len(table.player.melds) == 1
    assert table.player.should_call_kan(tile, False) is None
Example #19
0
def test_opened_kan_second_case():
    table = Table()
    table.count_of_remaining_tiles = 10

    tiles = string_to_136_array(man="2399", sou="111456", honors="111")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.PON, honors="111"))

    # to rebuild all caches
    table.player.draw_tile(string_to_136_tile(pin="9"))
    table.player.discard_tile()

    # our hand is open, in tempai and with a good wait
    tile = string_to_136_tile(sou="1")
    assert table.player.should_call_kan(tile, True) == MeldPrint.KAN
Example #20
0
    def test_call_upgrade_pon_and_bad_ukeire_after_call(self):
        table = Table()
        table.count_of_remaining_tiles = 10

        tiles = self._string_to_136_array(man='34445', sou='123456', pin='89')
        table.player.init_hand(tiles)
        tile = self._string_to_136_tile(man='4')

        self.assertEqual(table.player.should_call_kan(tile, False), None)

        table.player.add_called_meld(self._make_meld(Meld.PON, man='444'))

        self.assertEqual(len(table.player.melds), 1)
        self.assertEqual(len(table.player.tiles), 13)
        self.assertEqual(table.player.should_call_kan(tile, False), None)
Example #21
0
def test_kan_crash():
    """
    This was a crash in real game
    related with open kan logic and agari without yaku state
    """
    table = Table()
    table.count_of_remaining_tiles = 10

    tiles = string_to_136_array(man="456", pin="78999", sou="666", honors="33")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.PON, sou="666"))
    tile = string_to_136_tile(pin="9")
    table.player.draw_tile(tile)

    assert table.player.should_call_kan(tile, False) is None
Example #22
0
def test_call_shouminkan_and_bad_ukeire_after_call_second_case():
    table = Table()
    table.add_dora_indicator(string_to_136_tile(honors="5"))
    table.count_of_remaining_tiles = 10
    player = table.player

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

    tile = string_to_136_array(man="5555")[3]
    player.draw_tile(tile)

    assert player.should_call_kan(tile, False) is None
Example #23
0
    def test_closed_kan_same_shanten_same_ukeire(self):
        table = Table()
        player = table.player

        table.add_dora_indicator(self._string_to_136_tile(honors='2'))
        table.add_dora_indicator(self._string_to_136_tile(honors='4'))

        table.count_of_remaining_tiles = 10

        tiles = self._string_to_136_array(man='3334557889', honors='333')
        player.init_hand(tiles)
        player.melds.append(self._make_meld(Meld.PON, man='333'))

        tile = self._string_to_136_tile(honors='3')

        self.assertEqual(player.should_call_kan(tile, False), Meld.KAN)
Example #24
0
def test_closed_kan_same_shanten_same_ukeire():
    table = Table()
    player = table.player

    table.add_dora_indicator(string_to_136_tile(honors="2"))
    table.add_dora_indicator(string_to_136_tile(honors="4"))

    table.count_of_remaining_tiles = 10

    tiles = string_to_136_array(man="3334557889", honors="333")
    player.init_hand(tiles)
    player.melds.append(make_meld(MeldPrint.PON, man="333"))

    tile = string_to_136_tile(honors="3")
    player.draw_tile(tile)

    assert player.should_call_kan(tile, False) == MeldPrint.KAN
Example #25
0
    def test_call_closed_kan(self):
        table = Table()
        table.count_of_remaining_tiles = 10

        tiles = self._string_to_136_array(man='12223', sou='111456', pin='12')
        table.player.init_hand(tiles)
        tile = self._string_to_136_tile(man='2')

        # it is pretty stupid to call closed kan with 2m
        self.assertEqual(table.player.should_call_kan(tile, False), None)

        tiles = self._string_to_136_array(man='12223', sou='111456', pin='12')
        table.player.init_hand(tiles)
        tile = self._string_to_136_tile(sou='1')

        # call closed kan with 1s is fine
        self.assertEqual(table.player.should_call_kan(tile, False), Meld.KAN)
Example #26
0
    def test_opened_kan_third_case(self):
        # we are in tempai already and there was a crash on 5s meld suggestion

        table = Table()
        table.count_of_remaining_tiles = 10
        table.add_dora_indicator(self._string_to_136_tile(honors='5'))

        tiles = self._string_to_136_array(man='456', sou='55567678', honors='66')
        table.player.init_hand(tiles)
        table.player.add_called_meld(self._make_meld(Meld.CHI, sou='678'))

        # to rebuild all caches
        table.player.draw_tile(self._string_to_136_tile(pin='9'))
        table.player.discard_tile()

        tile = self._string_to_136_tile(sou='5')
        self.assertEqual(table.player.should_call_kan(tile, True), None)
        self.assertEqual(table.player.try_to_call_meld(tile, True), (None, None))
Example #27
0
def test_discard_not_needed_winds():
    table = Table()
    player = table.player
    player.scores = 25000
    table.count_of_remaining_tiles = 100

    tiles = string_to_136_array(man="24", pin="4", sou="12344668", honors="36")
    player.init_hand(tiles)
    player.draw_tile(string_to_136_tile(sou="5"))

    table.add_discarded_tile(1, string_to_136_tile(honors="3"), False)
    table.add_discarded_tile(1, string_to_136_tile(honors="3"), False)
    table.add_discarded_tile(1, string_to_136_tile(honors="3"), False)

    tile_to_discard = player.discard_tile()

    # west was discarded three times, we don't need it
    assert tiles_to_string([tile_to_discard]) == "3z"
Example #28
0
    def test_call_upgrade_pon_and_bad_ukeire_after_call_third_case(self):
        table = Table()
        table.count_of_remaining_tiles = 10
        player = table.player

        tiles = self._string_to_136_array(man='67', pin='6', sou='1344478999')
        table.player.init_hand(tiles)
        table.player.add_called_meld(self._make_meld(Meld.PON, sou='444'))

        tile = self._string_to_136_tile(sou='4')

        # we don't want to call shouminkan here
        self.assertEqual(table.player.should_call_kan(tile, False), None)

        player.draw_tile(tile)
        discarded_tile = player.discard_tile()

        self.assertEqual(self._to_string([discarded_tile]), '6p')
Example #29
0
def test_opened_kan_third_case():
    # we are in tempai already and there was a crash on 5s meld suggestion

    table = Table()
    table.count_of_remaining_tiles = 10
    table.add_dora_indicator(string_to_136_tile(honors="5"))

    tiles = string_to_136_array(man="456", sou="55567678", honors="66")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.CHI, sou="678"))

    # to rebuild all caches
    table.player.draw_tile(string_to_136_tile(pin="9"))
    table.player.discard_tile()

    tile = string_to_136_array(sou="5555")[3]
    assert table.player.should_call_kan(tile, True) is None
    assert table.player.try_to_call_meld(tile, True) == (None, None)
    def test_dont_discard_safe_tiles_when_call_riichi(self):
        table = Table()
        table.count_of_remaining_tiles = 70
        table.player.scores = 2000

        tiles = self._string_to_136_array(sou='12356789', pin='22678')
        table.player.init_hand(tiles)
        table.player.draw_tile(self._string_to_136_tile(honors='1'))
        table.player.discard_tile()
        table.player.draw_tile(self._string_to_136_tile(honors='1'))

        table.add_discarded_tile(1, self._string_to_136_tile(sou='1'), False)
        table.add_called_riichi(1)

        result = table.player.discard_tile()

        self.assertEqual(table.player.can_call_riichi(), True)
        self.assertEqual(self._to_string([result]), '1z')