blob: c589a9784affb6ecee54b28e5ffe12f2547db62c (
plain)
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
|
# ############################################################################ #
# #
# ::: :::::::: #
# event.py :+: :+: :+: #
# +:+ +:+ +:+ #
# By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/10/01 10:51:13 by cacharle #+# #+# #
# Updated: 2020/10/05 13:51:48 by cacharle ### ########.fr #
# #
# ############################################################################ #
import enum
class Event(enum.Enum):
FORK = 1
EAT = 2
SLEEP = 3
THINK = 4
DIE = 5
NONE = 6
@staticmethod
def from_string(representation: str) -> "Event":
return {
"has taken fork": Event.FORK,
"is thinking": Event.THINK,
"is eating": Event.EAT,
"is sleeping": Event.SLEEP,
"died": Event.DIE,
}[representation]
@staticmethod
def to_string(event: "Event") -> str:
return {
Event.FORK: "has taken fork",
Event.THINK: "is thinking",
Event.EAT: "is eating",
Event.SLEEP: "is sleeping",
Event.DIE: "died"
}[event]
|