-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeusser.py
98 lines (81 loc) · 2.82 KB
/
geusser.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
import sys
lines = []
def get_values(line):
values = line[1:-1].split()
x = values[0][:-1]
y = values[1][:-1]
z = values[2][:-1]
return (int(x), int(y), int(z))
class States:
P_STOP = 0
STOP = 1
P_FORWARD = 2
FORWARD = 3
P_BACK = 4
BACK = 5
P_RIGHT_DRIFT = 6
RIGHT_DRIFT = 7
P_LEFT_DRIFT = 8
LEFT_DRIFT = 9
NAMES = ['STOP', 'STOP', 'FORWARD', 'FORWARD', 'BACK', 'BACK',
'RIGHT_DRIFT', 'RIGHT_DRIFT', 'LEFT_DRIFT', 'LEFT_DRIFT']
def __init__(self):
self.current = 1
self.last_state = 1
def do_step(self, x, y, z):
score = x + y + z
# Staying still
if abs(score) < 50:
if self.current in [States.P_STOP, States.STOP]:
self.current = States.STOP
else:
self.last_state = self.current
self.current = States.P_STOP
# Forward moving
elif x > 5000 and abs(y) < 1000 and abs(z) < 10000:
if self.current in [States.P_FORWARD, States.FORWARD]:
self.current = States.FORWARD
else:
self.last_state = self.current
self.current = States.P_FORWARD
# Backwards moving
elif x < -5000 and abs(y) < 1000 and abs(z) < 10000:
if self.current in [States.P_BACK, States.BACK]:
self.current = States.BACK
else:
self.last_state = self.current
self.current = States.P_BACK
# Right drifting
elif (x > 5000 and y > 5000) or z > 7500 or (y > 5000 and z > 5000):
if self.current in [States.P_RIGHT_DRIFT, States.RIGHT_DRIFT]:
self.current = States.RIGHT_DRIFT
else:
self.last_state = self.current
self.current = States.P_RIGHT_DRIFT
# Left drifting
elif (x < -5000 and y < -5000) or z < -7500 or (y < -5000 and z < -5000):
if self.current in [States.P_LEFT_DRIFT, States.LEFT_DRIFT]:
self.current = States.LEFT_DRIFT
else:
self.last_state = self.current
self.current = States.P_LEFT_DRIFT
else:
if self.current in [States.P_FORWARD, States.FORWARD]:
self.current = States.FORWARD
else:
self.last_state = self.current
self.current = States.P_FORWARD
def name_state(self):
use_name = self.current
# Transient state
if self.current % 2 == 0:
use_name = self.last_state
return States.NAMES[use_name]
with open(sys.argv[1], "r") as fl:
for line in fl:
lines.append(line)
state = States()
for line in lines:
x, y, z = get_values(line)
state.do_step(x, y, z)
print(line[:-1] + " " + state.name_state())