def __init__(self, league_round=None): if not league_round: league_round = utils.get_current_round() self._league_round = league_round self._examiner = TeamExaminer()
class MyTeam2(Team): def initialize(self): for i in range(10): unit = Defender1(self, "A-Unit%02d" % (i + 1), i) self.units.append(unit) def arrange(self, enemy: Team): pass class MyTeam3(Team): def initialize(self): for i in range(10): unit = Defender3(self, "A-Unit%02d" % (i + 1), i) self.units.append(unit) def arrange(self, enemy: Team): pass if __name__ == "__main__": team1 = MyTeam1("Team#1") team2 = MyTeam2("Team#2") team3 = MyTeam3("Team#3") examiner = TeamExaminer() examiner.check(team1, "ROUND-02") examiner.check(team2, "ROUND-02") examiner.check(team3, "ROUND-02")
def test_team(self): team = get_team() examiner = TeamExaminer() self.assertTrue(examiner.check(team, "ROUND-03"))
def test_team(self): team = MyTeam("👑") examiner = TeamExaminer() examiner.check(team) examiner.check(team)
def __init__(self): self._league_round = utils.get_current_round() self._examiner = TeamExaminer()
class Simulator: def __init__(self): self._league_round = utils.get_current_round() self._examiner = TeamExaminer() def play(self, team1: Team, team2: Team, num_turns: int = 10, num_repeats: int =10): utils.check_type("team1", team1, Team) utils.check_type("team2", team2, Team) if len(team1) != len(team2): err_msg = "The sizes of team1 and team2 dost not match!" write_log(err_msg) raise ValueError(err_msg) num_wins_team1 = 0 num_wins_team2 = 0 num_draws = 0 for i in range(num_repeats): team1_cpy = copy.deepcopy(team1) team2_cpy = copy.deepcopy(team2) if i % 2 == 0: offense, defense = team1_cpy, team2_cpy else: offense, defense = team2_cpy, team1_cpy for t in range(num_turns): write_log("[%s vs %s - Repeat #%d Turn #%d]"%(team1.name, team2.name, i+1, t+1)) self._examiner.check_play(offense, defense, self._league_round) # Arrange defense_cpy = copy.deepcopy(defense) offense.arrange(defense_cpy) # Attack self._apply_attack(offense, defense) self._clear_dead_units(offense) self._clear_dead_units(defense) write_log("#Units in %s=%d, #Units in %s=%d"%(team1.name, len(team1), team2.name, len(team2))) if len(offense) == 0 or len(defense) == 0: break offense, defense = defense, offense # end of for if len(team1_cpy) > len(team2_cpy): # Team #1 wins. num_wins_team1 += 1 elif len(team1_cpy) < len(team2_cpy): num_wins_team2 += 1 else: # Draw num_draws += 1 # end of for return num_wins_team1, num_wins_team2, num_draws def _try_evasion(self, target): evsr = target.evs / 100. # Evasion Rate (EVSR) rn = random.uniform(0, 1) if rn <= evsr: write_log("%s evades with %.4f! (RN: %.4f)."%(target.name, evsr, rn)) return True return False def _apply_attack(self, offense: Team, defense: Team): for i, unit in enumerate(offense): target = defense[i] if unit and target: if self._try_evasion(target): continue unit_cpy = copy.deepcopy(unit) target_cpy = copy.deepcopy(defense[i]) unit.attack(target) # Check consistency utils.attack(unit_cpy, target_cpy, Unit) if unit_cpy != unit: err_msg = "%s.attack() performs "\ "illegal behaviors!"%(unit.__class__) write_log(err_msg) raise RuntimeError(err_msg) def _clear_dead_units(self, team: Team): for i, unit in enumerate(team): if not unit: continue if unit.hp <= 0: team[i] = None write_log("%s.%s has been dead..."%(unit.team.name, unit.name))
def test_team(self): team = RAKSTeam("RAKSTeam") examiner = TeamExaminer() examiner.check(team, "ROUND-02") examiner.check(team, "ROUND-02")
def test_team(self): team = hunsu("MyTeam") examiner = TeamExaminer() examiner.check(team) examiner.check(team)
def test_team(self): team = NoobTeam("Hello LOA") examiner = TeamExaminer() examiner.check(team)
class Simulator: def __init__(self, league_round=None): if not league_round: league_round = utils.get_current_round() self._league_round = league_round self._examiner = TeamExaminer() def play(self, team1: Team, team2: Team, num_turns: int = 10, num_repeats: int =10, judge: Judge = None): utils.check_type("team1", team1, Team) utils.check_type("team2", team2, Team) utils.check_type("judge", judge, Judge, allow_none=True) if not judge: judge = MaxSurvivalJudge() if len(team1) != len(team2): err_msg = "The sizes of team1 and team2 dost not match!" write_log(err_msg) raise ValueError(err_msg) num_wins_team1 = 0 num_wins_team2 = 0 num_draws = 0 for i in range(num_repeats): team1_cpy = copy.deepcopy(team1) team2_cpy = copy.deepcopy(team2) if i % 2 == 0: offense, defense = team1_cpy, team2_cpy else: offense, defense = team2_cpy, team1_cpy judge.initialize() for t in range(num_turns): write_log("[%s vs %s - Repeat #%d Turn #%d]"%(team1.name, team2.name, i+1, t+1)) self._examiner.check_play(offense, defense, self._league_round) # Arrange defense_cpy = copy.deepcopy(defense) offense.arrange(defense_cpy) # Attack self._apply_attack(offense, defense) self._clear_dead_units(offense) self._clear_dead_units(defense) write_log("#Units in %s=%d, #Units in %s=%d"%(team1.name, len(team1_cpy), team2.name, len(team2_cpy))) judge.update(t, team1_cpy, team2_cpy) if len(offense) == 0 or len(defense) == 0: break offense, defense = defense, offense # end of for winner = judge.decide(team1_cpy, team2_cpy) if winner == team1.name: num_wins_team1 += 1 elif winner == team2_cpy.name: num_wins_team2 += 1 else: # Draw num_draws += 1 # end of for return num_wins_team1, num_wins_team2, num_draws def _apply_attack(self, offense: Team, defense: Team): raise NotImplementedError() def _clear_dead_units(self, team: Team): for i, unit in enumerate(team): if not unit: continue if unit.hp <= 0: team[i] = None write_log("%s.%s has been dead..."%(unit.team.name, unit.name))