-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (30 loc) · 1.02 KB
/
Copy pathutils.py
File metadata and controls
32 lines (30 loc) · 1.02 KB
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
def flatten(tup):
"""This may help flatten the output of itertools.combinations()
into a tuple. You may find that you don't need it!"""
if len(tup) == 1:
return tup[0]
return tup
def get_direction(degrees):
fraction = (degrees % 360) / 360
orientation = None
match fraction:
case 0:
orientation = "up"
case 0.25:
orientation = "right"
case 0.5:
orientation = "down"
case 0.75:
orientation = "left"
return orientation
def is_facing_wampa(agent):
"""You may wish to use this in all_safe_next_actions"""
if not agent.KB.wampa:
return False
x, y = agent.loc
wx, wy = agent.KB.wampa
direction = get_direction(agent.degrees)
return (direction == "up" and wx == x and wy > y) or \
(direction == "down" and wx == x and wy < y) or \
(direction == "left" and wx < x and wy == y) or \
(direction == "right" and wx > x and wy == y)