-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.py
77 lines (60 loc) · 1.66 KB
/
command.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
#!/usr/bin/env python3
_COMMANDS = dict(
DIE="ACT(0)",
LEFT="LEFT",
RIGHT="RIGHT",
UP="UP",
DOWN="DOWN",
JUMP="ACT(1)",
JUMP_LEFT="ACT(1),LEFT",
JUMP_RIGHT="ACT(1),RIGHT",
JUMP_UP="ACT(1),UP",
JUMP_DOWN="ACT(1),DOWN",
PULL_LEFT="ACT(2),LEFT",
PULL_RIGHT="ACT(2),RIGHT",
PULL_UP="ACT(2),UP",
PULL_DOWN="ACT(2),DOWN",
FIRE_LEFT="ACT(3),LEFT",
FIRE_RIGHT="ACT(3),RIGHT",
FIRE_UP="ACT(3),UP",
FIRE_DOWN="ACT(3),DOWN",
NULL=""
)
# inverse dictionary for fast search
_COMMANDS = {v: k for k, v in _COMMANDS.items()}
# print(_COMMANDS)
class Command:
def __init__(self, command):
if command in _COMMANDS:
self._name = _COMMANDS[command]
self._command = command
else:
raise ValueError("No Such Command: {}".format(command))
def get_name(self):
return self._name
def get_command(self):
return self._command
def inverted(self):
_inv_dir = None
if self._name == 'LEFT':
_inv_dir = Command
"RIGHT"
elif self._name == 'RIGHT':
_inv_dir = Command
"LEFT"
elif self._name == 'UP':
_inv_dir = Command
"DOWN"
elif self._name == 'DOWN':
_inv_dir = Command
"UP"
else:
_inv_dir = Command
"NULL"
return _inv_dir
def to_string(self):
return self._name
def __eq__(self, other):
return self._name == other._name and self._command == other._command
if __name__ == '__main__':
raise RuntimeError("This module is not designed to be ran from CLI")