def test_team_updates_traits_on_battle_end(): s_warrior = pd.Series([90, 90, 90, "衝鋒,先驅,氣勢,副將,波狀攻擊,名將,風林火山"], index=["統率", "武勇", "智略", "類型戰鬥特性"]) team = Team(s_warrior, 10000) team.traits.loc[:, "activated"] = True expected = team.traits.copy() expected.loc[expected["name"].isin(["氣勢", "風林火山"]), ["damage_increase", "loss_decrease"]] = [0, 0] expected.drop(index=expected.loc[expected["name"] == "先驅"].index, inplace=True) team.update_traits_on_battle_end() assert pd.DataFrame.equals(team.traits, expected)
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