コード例 #1
0
def test_should_activate_strategy_and_chitoitsu_like_hand():
    table = _make_table()
    strategy = TanyaoStrategy(BaseStrategy.TANYAO, table.player)

    tiles = string_to_136_array(sou="223388", man="2244", pin="6687")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is True
コード例 #2
0
def test_suitable_tiles():
    table = _make_table()
    strategy = TanyaoStrategy(BaseStrategy.TANYAO, table.player)

    tile = string_to_136_tile(man="1")
    assert strategy.is_tile_suitable(tile) is False

    tile = string_to_136_tile(pin="1")
    assert strategy.is_tile_suitable(tile) is False

    tile = string_to_136_tile(sou="9")
    assert strategy.is_tile_suitable(tile) is False

    tile = string_to_136_tile(honors="1")
    assert strategy.is_tile_suitable(tile) is False

    tile = string_to_136_tile(honors="6")
    assert strategy.is_tile_suitable(tile) is False

    tile = string_to_136_tile(man="2")
    assert strategy.is_tile_suitable(tile) is True

    tile = string_to_136_tile(pin="5")
    assert strategy.is_tile_suitable(tile) is True

    tile = string_to_136_tile(sou="8")
    assert strategy.is_tile_suitable(tile) is True
コード例 #3
0
def test_should_activate_strategy_and_already_completed_sided_set():
    table = _make_table()
    strategy = TanyaoStrategy(BaseStrategy.TANYAO, table.player)

    tiles = string_to_136_array(sou="123234", man="2349", pin="234")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(sou="234789", man="2349", pin="234")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(sou="234", man="1233459", pin="234")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(sou="234", man="2227899", pin="234")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(sou="234", man="2229", pin="122334")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(sou="234", man="2229", pin="234789")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(sou="223344", man="2229", pin="234")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is True
コード例 #4
0
def test_should_activate_strategy_and_valued_pair():
    table = _make_table()
    strategy = TanyaoStrategy(BaseStrategy.TANYAO, table.player)

    tiles = string_to_136_array(man="23446679", sou="222", honors="55")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(man="23446679", sou="222", honors="22")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is True
コード例 #5
0
def test_should_activate_strategy_and_terminal_pairs():
    table = _make_table()
    strategy = TanyaoStrategy(BaseStrategy.TANYAO, table.player)

    tiles = string_to_136_array(sou="222", man="3459", pin="2399", honors="11")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is False

    tiles = string_to_136_array(sou="22258", man="3566", pin="2399")
    table.player.init_hand(tiles)
    assert strategy.should_activate_strategy(table.player.tiles) is True
コード例 #6
0
def test_calculate_suit_tiles_value_and_tanyao_hand():
    table = Table()
    player = table.player
    table.has_aka_dora = False
    player.ai.current_strategy = TanyaoStrategy(BaseStrategy.TANYAO, player)

    # 0 - 8   man
    # 9 - 17  pin
    # 18 - 26 sou
    results = [
        [0, 110],
        [9, 110],
        [18, 110],
        [1, 120],
        [10, 120],
        [19, 120],
        [2, 130],
        [11, 130],
        [20, 130],
        [3, 150],
        [12, 150],
        [21, 150],
        [4, 140],
        [13, 140],
        [22, 140],
        [5, 150],
        [14, 150],
        [23, 150],
        [6, 130],
        [15, 130],
        [24, 130],
        [7, 120],
        [16, 120],
        [25, 120],
        [8, 110],
        [17, 110],
        [26, 110],
    ]

    for item in results:
        tile = item[0]
        value = item[1]
        assert DiscardOption(player, tile * 4, 0, [], 0).valuation == value
        assert DiscardOption(player, tile * 4 + 1, 0, [], 0).valuation == value
        assert DiscardOption(player, tile * 4 + 2, 0, [], 0).valuation == value
        assert DiscardOption(player, tile * 4 + 3, 0, [], 0).valuation == value
コード例 #7
0
    def determine_strategy(self, tiles_136, meld_tile=None):
        # 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(
            FormalTempaiStrategy(BaseStrategy.FORMAL_TEMPAI, self.player))
        strategies.append(
            CommonOpenTempaiStrategy(BaseStrategy.COMMON_OPEN_TEMPAI,
                                     self.player))

        for strategy in strategies:
            if strategy.should_activate_strategy(tiles_136,
                                                 meld_tile=meld_tile):
                self.current_strategy = strategy
                break

        if self.current_strategy and (
                not old_strategy
                or self.current_strategy.type != old_strategy.type):
            self.player.logger.debug(
                log.STRATEGY_ACTIVATE,
                context=self.current_strategy,
            )

        if not self.current_strategy and old_strategy:
            self.player.logger.debug(log.STRATEGY_DROP, context=old_strategy)

        return self.current_strategy and True or False
コード例 #8
0
def test_kuikae_advanced():
    # case 0: sanity check
    table = _make_table()
    table.add_dora_indicator(string_to_136_tile(pin="2"))
    tiles = string_to_136_array(man="234", sou="23456", pin="33359")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.CHI, man="234"))
    # just force tanyao for the test
    table.player.ai.current_strategy = TanyaoStrategy(BaseStrategy.TANYAO,
                                                      table.player)
    _assert_tanyao(table.player)

    tile = string_to_136_array(sou="4444")[1]
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is not None

    # case 1: allowed chi
    table = _make_table()
    table.add_dora_indicator(string_to_136_tile(pin="2"))
    tiles = string_to_136_array(man="234", sou="123456", pin="3335")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.CHI, man="234"))
    # just force tanyao for the test
    table.player.ai.current_strategy = TanyaoStrategy(BaseStrategy.TANYAO,
                                                      table.player)
    _assert_tanyao(table.player)

    tile = string_to_136_array(sou="4444")[1]
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is not None

    # case 2: another allowed chi
    table = _make_table()
    table.add_dora_indicator(string_to_136_tile(pin="2"))
    tiles = string_to_136_array(man="234", sou="123345", pin="3335")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.CHI, man="234"))
    # just force tanyao for the test
    table.player.ai.current_strategy = TanyaoStrategy(BaseStrategy.TANYAO,
                                                      table.player)
    _assert_tanyao(table.player)

    tile = string_to_136_array(sou="4444")[1]
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is not None

    # case 3: another allowed chi
    table = _make_table()
    table.add_dora_indicator(string_to_136_tile(pin="2"))
    tiles = string_to_136_array(man="234", sou="12345", pin="33355")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.CHI, man="234"))
    # just force tanyao for the test
    table.player.ai.current_strategy = TanyaoStrategy(BaseStrategy.TANYAO,
                                                      table.player)
    _assert_tanyao(table.player)

    tile = string_to_136_array(sou="4444")[1]
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is not None

    # case 4: useless chi, don't do that
    table = _make_table()
    table.add_dora_indicator(string_to_136_tile(pin="2"))
    tiles = string_to_136_array(man="234", sou="234567", pin="3335")
    table.player.init_hand(tiles)
    table.player.add_called_meld(make_meld(MeldPrint.CHI, man="234"))
    # just force tanyao for the test
    table.player.ai.current_strategy = TanyaoStrategy(BaseStrategy.TANYAO,
                                                      table.player)
    _assert_tanyao(table.player)

    tile = string_to_136_array(sou="2222")[2]
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is None

    tile = string_to_136_array(sou="5555")[2]
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is None

    tile = string_to_136_array(sou="8888")[2]
    meld, _ = table.player.try_to_call_meld(tile, True)
    assert meld is None