-
Notifications
You must be signed in to change notification settings - Fork 0
/
stagevars.py
75 lines (55 loc) · 1.81 KB
/
stagevars.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
import random
import math
from globalvars import WIN_X, WIN_Y, GRID_X, GRID_Y
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
class Stagevars:
# ------------------------------------------------ #
def __init__(self):
# general implicit
self.x = random.randint(0, GRID_X)
self.y = random.randint(0, GRID_Y)
self.angle = random.randint(0, 3)
self.av = 1
self.turn = 0
self.health = 1
# sensors
self.costmap_grad_forw = 0
self.costmap_grad_lat = 0
self.costmap_value = 0
# ------------------------------------------------ #
def action(self):
speed = 2
self.angle = round(self.angle + self.turn) % 4
if self.av > 0:
if self.angle == 0:
self.y = self.y - 1
if self.angle == 1:
self.x = self.x + 1
if self.angle == 2:
self.y = self.y + 1
if self.angle == 3:
self.x = self.x - 1
# Continuous case
#self.x = self.x + speed * \
#_activation_av(self.av) * math.sin(self.angle)
#self.y = self.y - speed * \
#_activation_av(self.av) * math.cos(self.angle)
# ------------------------------------------------ #
def get_pos(self):
x = (int)(self.x % GRID_X)
y = (int)(self.y % GRID_Y)
return(x, y, self.angle)
def set_activations(self, action):
self.av = round(action[0])
self.turn = round(action[1]) - round(action[2])
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
def example():
random.seed(5)
a = Stagevars()
a.av = 1
for i in range(10):
a.action()
a.turn = (random.random()-0.5)*2.0
print(a.angle)
print(a.x)
print(a.y)