-
Notifications
You must be signed in to change notification settings - Fork 180
/
point_env.py
30 lines (24 loc) · 876 Bytes
/
point_env.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
from rllab.envs.base import Env
from rllab.spaces import Box
from rllab.envs.base import Step
import numpy as np
class PointEnv(Env):
@property
def observation_space(self):
return Box(low=-np.inf, high=np.inf, shape=(2,))
@property
def action_space(self):
return Box(low=-0.1, high=0.1, shape=(2,))
def reset(self, **kwargs):
self._state = np.random.uniform(-1, 1, size=(2,))
observation = np.copy(self._state)
return observation
def step(self, action):
self._state = self._state + action
x, y = self._state
reward = - (x ** 2 + y ** 2) ** 0.5
done = abs(x) < 0.01 and abs(y) < 0.01
next_observation = np.copy(self._state)
return Step(observation=next_observation, reward=reward, done=done)
def render(self):
print('current state:', self._state)