-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreature_actions.py
52 lines (41 loc) · 1.22 KB
/
creature_actions.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
from enum import Enum
class AutoNumber(Enum):
def __new__(cls):
value = len(cls.__members__) # note no + 1
obj = object.__new__(cls)
obj._value_ = value
return obj
class Actions(AutoNumber):
LEFT = ()
RIGHT = ()
UP = ()
DOWN = ()
EAT = ()
MATE = ()
FIGHT = ()
WORK = ()
DIVIDE = ()
VOCALIZE = ()
@staticmethod
def get_all_actions():
return [Actions.LEFT, Actions.RIGHT, Actions.UP, Actions.DOWN, Actions.EAT, Actions.MATE, Actions.FIGHT,
Actions.WORK, Actions.DIVIDE, Actions.VOCALIZE]
def __str__(self):
return str(self.name)
@staticmethod
def num_actions():
return len(Actions.get_all_actions())
@staticmethod
def is_legal(action):
if action in Actions.get_all_actions():
return True
return False
@staticmethod
def index_to_enum(index):
return Actions.get_all_actions()[index]
@staticmethod
def enum_to_index(action):
return Actions.get_all_actions().index(action)
@staticmethod
def get_actions_str():
return [str(action) for action in Actions.get_all_actions()]