-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathteam.py
221 lines (193 loc) · 6.97 KB
/
team.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from __future__ import annotations
from enum import auto
from typing import Optional, TYPE_CHECKING
from base_enum import BaseEnum
from monster_base import MonsterBase
from random_gen import RandomGen
from helpers import get_all_monsters
from data_structures.referential_array import ArrayR
if TYPE_CHECKING:
from battle import Battle
class MonsterTeam:
class TeamMode(BaseEnum):
FRONT = auto()
BACK = auto()
OPTIMISE = auto()
class SelectionMode(BaseEnum):
RANDOM = auto()
MANUAL = auto()
PROVIDED = auto()
class SortMode(BaseEnum):
HP = auto()
ATTACK = auto()
DEFENSE = auto()
SPEED = auto()
LEVEL = auto()
TEAM_LIMIT = 6
def __init__(self, team_mode: TeamMode, selection_mode, **kwargs) -> None:
# Add any preinit logic here.
self.team_mode = team_mode
if selection_mode == self.SelectionMode.RANDOM:
self.select_randomly(**kwargs)
elif selection_mode == self.SelectionMode.MANUAL:
self.select_manually(**kwargs)
elif selection_mode == self.SelectionMode.PROVIDED:
self.select_provided(**kwargs)
else:
raise ValueError(f"selection_mode {selection_mode} not supported.")
def add_to_team(self, monster: MonsterBase):
raise NotImplementedError
def retrieve_from_team(self) -> MonsterBase:
raise NotImplementedError
def special(self) -> None:
raise NotImplementedError
def regenerate_team(self) -> None:
raise NotImplementedError
def select_randomly(self):
team_size = RandomGen.randint(1, self.TEAM_LIMIT)
monsters = get_all_monsters()
n_spawnable = 0
for x in range(len(monsters)):
if monsters[x].can_be_spawned():
n_spawnable += 1
for _ in range(team_size):
spawner_index = RandomGen.randint(0, n_spawnable-1)
cur_index = -1
for x in range(len(monsters)):
if monsters[x].can_be_spawned():
cur_index += 1
if cur_index == spawner_index:
# Spawn this monster
self.add_to_team(monsters[x]())
break
else:
raise ValueError("Spawning logic failed.")
def select_manually(self):
"""
Prompt the user for input on selecting the team.
Any invalid input should have the code prompt the user again.
First input: Team size. Single integer
For _ in range(team size):
Next input: Prompt selection of a Monster class.
* Should take a single input, asking for an integer.
This integer corresponds to an index (1-indexed) of the helpers method
get_all_monsters()
* If invalid of monster is not spawnable, should ask again.
Add these monsters to the team in the same order input was provided. Example interaction:
How many monsters are there? 2
MONSTERS Are:
1: Flamikin [✔️]
2: Infernoth [❌]
3: Infernox [❌]
4: Aquariuma [✔️]
5: Marititan [❌]
6: Leviatitan [❌]
7: Vineon [✔️]
8: Treetower [❌]
9: Treemendous [❌]
10: Rockodile [✔️]
11: Stonemountain [❌]
12: Gustwing [✔️]
13: Stormeagle [❌]
14: Frostbite [✔️]
15: Blizzarus [❌]
16: Thundrake [✔️]
17: Thunderdrake [❌]
18: Shadowcat [✔️]
19: Nightpanther [❌]
20: Mystifly [✔️]
21: Telekite [❌]
22: Metalhorn [✔️]
23: Ironclad [❌]
24: Normake [❌]
25: Strikeon [✔️]
26: Venomcoil [✔️]
27: Pythondra [✔️]
28: Constriclaw [✔️]
29: Shockserpent [✔️]
30: Driftsnake [✔️]
31: Aquanake [✔️]
32: Flameserpent [✔️]
33: Leafadder [✔️]
34: Iceviper [✔️]
35: Rockpython [✔️]
36: Soundcobra [✔️]
37: Psychosnake [✔️]
38: Groundviper [✔️]
39: Faeboa [✔️]
40: Bugrattler [✔️]
41: Darkadder [✔️]
Which monster are you spawning? 38
MONSTERS Are:
1: Flamikin [✔️]
2: Infernoth [❌]
3: Infernox [❌]
4: Aquariuma [✔️]
5: Marititan [❌]
6: Leviatitan [❌]
7: Vineon [✔️]
8: Treetower [❌]
9: Treemendous [❌]
10: Rockodile [✔️]
11: Stonemountain [❌]
12: Gustwing [✔️]
13: Stormeagle [❌]
14: Frostbite [✔️]
15: Blizzarus [❌]
16: Thundrake [✔️]
17: Thunderdrake [❌]
18: Shadowcat [✔️]
19: Nightpanther [❌]
20: Mystifly [✔️]
21: Telekite [❌]
22: Metalhorn [✔️]
23: Ironclad [❌]
24: Normake [❌]
25: Strikeon [✔️]
26: Venomcoil [✔️]
27: Pythondra [✔️]
28: Constriclaw [✔️]
29: Shockserpent [✔️]
30: Driftsnake [✔️]
31: Aquanake [✔️]
32: Flameserpent [✔️]
33: Leafadder [✔️]
34: Iceviper [✔️]
35: Rockpython [✔️]
36: Soundcobra [✔️]
37: Psychosnake [✔️]
38: Groundviper [✔️]
39: Faeboa [✔️]
40: Bugrattler [✔️]
41: Darkadder [✔️]
Which monster are you spawning? 2
This monster cannot be spawned.
Which monster are you spawning? 1
"""
raise NotImplementedError
def select_provided(self, provided_monsters:Optional[ArrayR[type[MonsterBase]]]=None):
"""
Generates a team based on a list of already provided monster classes.
While the type hint imples the argument can be none, this method should never be called without the list.
Monsters should be added to the team in the same order as the provided array.
Example input:
[Flamikin, Aquariuma, Gustwing] <- These are all classes.
Example team if in TeamMode.FRONT:
[Gustwing Instance, Aquariuma Instance, Flamikin Instance]
"""
raise NotImplementedError
def choose_action(self, currently_out: MonsterBase, enemy: MonsterBase) -> Battle.Action:
# This is just a placeholder function that doesn't matter much for testing.
from battle import Battle
if currently_out.get_speed() >= enemy.get_speed() or currently_out.get_hp() >= enemy.get_hp():
return Battle.Action.ATTACK
return Battle.Action.SWAP
if __name__ == "__main__":
team = MonsterTeam(
team_mode=MonsterTeam.TeamMode.OPTIMISE,
selection_mode=MonsterTeam.SelectionMode.RANDOM,
sort_key=MonsterTeam.SortMode.HP,
)
print(team)
while len(team):
print(team.retrieve_from_team())