-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbobi.py
46 lines (36 loc) · 1.15 KB
/
bobi.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
"""Bobi module."""
__author__ = "Hendrig"
def decide(sensor_data, current_state):
"""
Decide in which direction should robot move using sensor_data and current_state.
Bobi can move up to 2 indexes to left or right.
Args:
List of blocking objects in specific direction.
0 - Free
-1 - Object
sensor_data - [n, ne , e, se, s, sw, w, nw]
Return:
One of the possible directions.
"""
if len(sensor_data) != 8:
return None
state_dict = {
"N": 0, "NE": 1, "E": 2,
"SE": 3, "S": 4, "SW": 5,
"W": 6, "NW": 7
}
try:
current_state = state_dict[current_state]
except KeyError:
return None
if current_state != 0:
new_sensor_data = [0, 0, 0, 0, 0, 0, 0, 0]
new_sensor_data[0: (8 - current_state)] = sensor_data[current_state:]
new_sensor_data[(8 - current_state):] = sensor_data[0: current_state]
else:
new_sensor_data = sensor_data
check_list = [-2, -1, 0, 1, 2]
for i in check_list:
if new_sensor_data[i] == -1:
return i
return None