-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
126 lines (106 loc) · 2.34 KB
/
utils.py
File metadata and controls
126 lines (106 loc) · 2.34 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
Useful functions.
"""
from enum import Enum
import numpy as np
class Actions(Enum):
Top = 0
Bottom = 1
Right = 2
Left = 3
Stay = 4
Interact = 5
class Orientations(Enum):
Top = (0, -1)
Bottom = (0, 1)
Right = (1, 0)
Left = (-1, 0)
class CardinalDirection(Enum):
North = 'N'
NorthEast = 'NE'
East = 'E'
SouthEast = 'SE'
South = 'S'
SouthWest = 'SW'
West = 'W'
NorthWest = 'NW'
def get_move(start_pos, end_pos):
if start_pos[0] < end_pos[0]:
return Actions.Right
if start_pos[0] > end_pos[0]:
return Actions.Left
if start_pos[1] < end_pos[1]:
return Actions.Bottom
if start_pos[1] > end_pos[1]:
return Actions.Top
else:
return Actions.Stay
def action_num_to_char(action_num):
"""
Converts an action (int) to a char
"""
if action_num == 0:
return "↑"
elif action_num == 1:
return '↓'
elif action_num == 2:
return '→'
elif action_num == 3:
return '←'
# Stay
elif action_num == 4:
return 's'
# Interact
elif action_num == 5:
return 'x'
def action_num_to_str(action_num):
"""
Converts the action (int) in a str
"""
if action_num == 0:
return "top"
elif action_num == 1:
return 'bottom'
elif action_num == 2:
return 'right'
elif action_num == 3:
return 'left'
elif action_num == 4:
return 'stay'
elif action_num == 5:
return 'interact'
def get_assigned_color(action_num):
"""
Returns the color assigned to the action (int).
"""
if action_num == 0:
return "FF6B6B"
elif action_num == 1:
return '4D96FF'
elif action_num == 2:
return '6BCB77'
elif action_num == 3:
return 'FFD93D'
# Stay
elif action_num == 4:
return '525E75'
# Interact
elif action_num == 5:
return 'FF7BA9'
def get_weight_assigned_color(weight):
"""
Returns the color that represents the given weight
"""
if weight >= 0.75:
return '#332FD0'
if weight >= 0.5:
return '#9254C8'
if weight >= 0.25:
return '#E15FED'
else:
return '#6EDCD9'
def normalize(v):
norm = np.linalg.norm(v, ord=1)
if norm == 0:
return v
return v / norm