Exemplo n.º 1
0
def test_dfs_pattern_chitoitsu():
    dfs = Dfs()

    # chitoitsu pattern
    nums = [
        0,
        2,
        0,
        0,
        2,
        0,
        2,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        2,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        2,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        2,
        0,
        0,
        1,
    ]
    dora_ids = [1, 5, 33]
    doras = [p for p in Pai.from_idlist(dora_ids)]
    depth = 3
    _, _, chitoitsu_shanten = shanten.get_shanten_all(nums, 0)
    results = dfs.dfs_with_score_chitoitsu(
        nums,
        furos=[],
        depth=depth,
        shanten_chitoitsu=chitoitsu_shanten,
        doras=doras,
    )
    result = sorted(results, key=lambda x: x.point_info.points)[-1]

    print(f"{nums} \n-> {result}, depth:{depth}, {[d.id for d in doras]}")

    dora_id_contains = False
    for toitsu in result.combination:
        dora_id_contains |= toitsu[0] in dora_ids

    assert dora_id_contains
Exemplo n.º 2
0
def test_dfs_score():
    dfs = Dfs()
    # can add new dora and dora tanki test
    nums = [
        0,
        0,
        2,
        0,
        2,
        0,
        2,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        2,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        2,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        2,
        0,
        0,
        1,
    ]
    dora_ids = [1, 5, 27, 33]
    doras = [p for p in Pai.from_idlist(dora_ids)]
    depth = 9

    _, _, chitoitsu_shanten = shanten.get_shanten_all(nums, 0)

    result = dfs.dfs_with_score_chitoitsu(
        nums,
        furos=[],
        depth=3,
        shanten_chitoitsu=chitoitsu_shanten,
        doras=doras,
    )

    print(f"{nums} \n-> {result}, depth:{depth}, {[d.id for d in doras]}")
    assert len(result) > 0
Exemplo n.º 3
0
def test_dfs_pattern_chitoitsu_toitsu_tanki():
    dfs = Dfs()
    # can add new dora and dora tanki test
    nums = [
        0,
        0,
        2,
        0,
        2,
        0,
        2,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        2,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        2,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        2,
        0,
        0,
        1,
    ]
    dora_ids = [1, 5, 20, 33]
    doras = [p for p in Pai.from_idlist(dora_ids)]
    depth = 3

    _, _, chitoitsu_shanten = shanten.get_shanten_all(nums, 0)
    results = dfs.dfs_with_score_chitoitsu(
        nums,
        furos=[],
        depth=depth,
        shanten_chitoitsu=chitoitsu_shanten,
        doras=doras,
    )
    result = sorted(results, key=lambda x: x.point_info.points)[-1]

    print(f"{nums} \n-> {result}, depth:{depth}, {[d.id for d in doras]}")

    contains_33 = False
    contains_1_5_20 = False

    for toitsu in result.combination:
        if toitsu[0] in [1, 5, 20]:
            contains_1_5_20 = True
        if toitsu[0] == 33:
            contains_33 = True

    assert contains_1_5_20 & contains_33
Exemplo n.º 4
0
def test_dfs_pattern_kokushi():
    dfs = Dfs()
    # can add new dora and dora tanki test
    nums = [
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        2,
    ]
    dora_ids = [1, 5, 27, 33]
    doras = [p for p in Pai.from_idlist(dora_ids)]
    depth = 3
    oya = True

    _, shanten_kokushi, _ = shanten.get_shanten_all(nums, 0)

    results = dfs.dfs_with_score_kokushi(
        nums,
        furos=[],
        depth=3,
        oya=oya,
        shanten_kokushi=shanten_kokushi,
    )

    print(f"{nums} \n-> {results}, depth:{depth}, {[d.id for d in doras]}")
    assert len(results) > 0

    kokushi_exists = False
    for result in results:
        yakus = result.point_info.yakus
        if any([yaku[0] == "kokushimuso" for yaku in yakus]):
            kokushi_exists = True
    assert kokushi_exists
Exemplo n.º 5
0
    def from_already_spliteds(
        cls,
        head, # 9
        mentsus, # ((1,2,3), (4,5,6), (20,20,20), (32,32,32))
        furos, # List[Furo]
        taken, # 20
        oya,
        bakaze,
        jikaze,
        doras,
        uradoras,
        num_akadoras,
    ):
        
        # need before calclate dora
        pais_buffer = Pai.from_idlist([head, head])
         
        for mentsu in mentsus:
            pais_buffer.extend(Pai.from_idlist(list(mentsu)))
        
        free_pais = copy.copy(pais_buffer)

        for furo in furos:
            pais_buffer.extend(furo.pais)
        all_pais = pais_buffer
        is_menzen = len([f for f in furos if f.type != 'ankan']) == 0
        taken = Pai.from_id(taken)

        num_doras = Hora.count_doras(all_pais, doras)
        num_uradoras = Hora.count_doras(all_pais, uradoras)
        # num_akadora need calclate outside.
        
        num_same_as_taken = len([f for f in free_pais if taken.is_same_symbol(f)])
        
        combination = [
            ["toitsu", Pai.from_idlist([head,head])],
        ]
        for mentsu in mentsus:
            if mentsu[0] == mentsu[1]:
                combination.append(["kotsu", Pai.from_idlist(mentsu)])
            else:
                combination.append(["shuntsu", Pai.from_idlist(mentsu)])
        
        hora_yaku_information = HoraYakuInformation(
            taken=taken,
            all_pais=all_pais,
            hora_type="tsumo",
            oya=oya,
            first_turn=False,
            num_doras=num_doras,
            num_uradoras=num_uradoras,
            num_akadoras=num_akadoras,
            reach=is_menzen,
            ippatsu=False,
            rinshan=False,
            chankan=False,
            haitei=False,
            double_reach=False,
            furos=furos,
            jikaze=jikaze,
            bakaze=bakaze,
        )

        candidates = []
        for i in range(num_same_as_taken):
            candidates.append(Candidate(hora_yaku_information, combination, i))
        
        if len(candidates) > 0:
            best_candidate = max(candidates, key=lambda x:(x.fan, x.points))
            if best_candidate.valid:
                return HoraInfo(
                    fu=best_candidate.fu,
                    fan=best_candidate.fan,
                    yakus=best_candidate.yakus,
                    points=best_candidate.points,
                    oya_payment=best_candidate.oya_payment,
                    ko_payment=best_candidate.ko_payment,
                )

            return HoraInfo(
                    fu=0,
                    fan=0,
                    yakus=[],
                    points=0,
                    oya_payment=0,
                    ko_payment=0
                )