-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbattle.py
53 lines (44 loc) · 1.54 KB
/
battle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations
from enum import auto
from typing import Optional
from base_enum import BaseEnum
from team import MonsterTeam
class Battle:
class Action(BaseEnum):
ATTACK = auto()
SWAP = auto()
SPECIAL = auto()
class Result(BaseEnum):
TEAM1 = auto()
TEAM2 = auto()
DRAW = auto()
def __init__(self, verbosity=0) -> None:
self.verbosity = verbosity
def process_turn(self) -> Optional[Battle.Result]:
"""
Process a single turn of the battle. Should:
* process actions chosen by each team
* level and evolve monsters
* remove fainted monsters and retrieve new ones.
* return the battle result if completed.
"""
raise NotImplementedError
def battle(self, team1: MonsterTeam, team2: MonsterTeam) -> Battle.Result:
if self.verbosity > 0:
print(f"Team 1: {team1} vs. Team 2: {team2}")
# Add any pregame logic here.
self.turn_number = 0
self.team1 = team1
self.team2 = team2
self.out1 = team1.retrieve_from_team()
self.out2 = team2.retrieve_from_team()
result = None
while result is None:
result = self.process_turn()
# Add any postgame logic here.
return result
if __name__ == "__main__":
t1 = MonsterTeam(MonsterTeam.TeamMode.BACK, MonsterTeam.SelectionMode.RANDOM)
t2 = MonsterTeam(MonsterTeam.TeamMode.BACK, MonsterTeam.SelectionMode.RANDOM)
b = Battle(verbosity=3)
print(b.battle(t1, t2))