Beispiel #1
0
def test_team_updates_traits_on_tik_end():
    s_warrior = pd.Series([90, 90, 90, "衝鋒,名將,氣勢,才貌雙全,不屈"],
                          index=["統率", "武勇", "智略", "類型戰鬥特性"])
    team = Team(s_warrior, 10000)
    team.traits.loc[team.traits["name"].isin(["名將", "才貌雙全", "不屈"]),
                    ["activated", "activated_until"]] = [True, 1]
    team.traits.loc[team.traits["name"].isin(["不屈"]),
                    ["activated", "activated_until"]] = [True, 9]

    expected = team.traits.copy()
    expected.loc[expected["name"].isin(["名將", "才貌雙全", "不屈"]),
                 ["activated", "activated_until"]] = [False, 10]
    expected.loc[expected["name"].isin(["不屈"]),
                 ["activated", "activated_until"]] = [True, 8]

    team.update_traits_on_tik_end()

    pd.set_option('display.max_columns', None)
    pd.set_option('display.max_rows', None)
    print(team.traits)
    print(expected)
    print(team.traits.dtypes)
    print(expected.dtypes)

    assert pd.DataFrame.equals(team.traits, expected)
Beispiel #2
0
def run_evaluation():
    log = init_log()
    total = df_candidates.shape[0]

    for idx, candidate in df_candidates.iterrows():
        idx = idx + 1
        msg = f"{idx}/{total}"
        for battle in range(1, 101):
            team = Team([candidate], 5000)
            opponent = Team([s_opponent], 5000)
            team.set_opponent(opponent)
            opponent.set_opponent(team)

            tik = 1
            while team.troops > 0 and opponent.troops > 0:
                team.update_traits_on_tik_start()
                opponent.update_traits_on_tik_start()
                if tik % 3 == 0:
                    team.update_traits_on_battle_start()
                    opponent.update_traits_on_battle_start()
                    team.update_team_factors()
                    opponent.update_team_factors()

                    kills = team.calculate_kills()
                    killed = opponent.calculate_kills()
                    team.take_damage(killed)
                    opponent.take_damage(kills)

                    log = battle_log(log, battle, tik, team, opponent, kills,
                                     killed, msg)

                    team.update_traits_on_battle_end()
                    opponent.update_traits_on_battle_end()

                team.update_traits_on_tik_end()
                opponent.update_traits_on_tik_end()

                tik = tik + 1

            log.to_excel("battle_log.xlsx", index=False)
def test_battle():
    log = init_log()

    team = Team([s_wutianxinxuan], 10000)
    opponent = Team([s_shangshanqianxin], 10000)

    team.set_opponent(opponent)
    opponent.set_opponent(team)

    tik = 1
    while team.troops > 0 and opponent.troops > 0:
        team.update_traits_on_tik_start()
        opponent.update_traits_on_tik_start()
        if tik % 3 == 0:
            team.update_traits_on_battle_start()
            opponent.update_traits_on_battle_start()

            team.update_team_factors()
            opponent.update_team_factors()

            kills = team.calculate_kills()
            killed = opponent.calculate_kills()

            team.take_damage(killed)
            opponent.take_damage(kills)

            log = battle_log(log, tik, team, opponent, kills, killed)

            team.update_traits_on_battle_end()
            opponent.update_traits_on_battle_end()

        team.update_traits_on_tik_end()
        opponent.update_traits_on_tik_end()

        tik = tik + 1

    log.to_excel("battle_log.xlsx", index=False)

    assert True