Random starting state

This commit is contained in:
Nicolai Czempin 2017-04-01 10:53:41 +02:00
parent c96cb1e48e
commit 2f39f6054a

View File

@ -8,6 +8,7 @@ class RandomWalkEnv(gym.Env):
def __init__(self): def __init__(self):
self.action_space = spaces.Discrete(2) self.action_space = spaces.Discrete(2)
self.size = 6
#print("init") #print("init")
def _step(self, action): def _step(self, action):
#print("step") #print("step")
@ -17,7 +18,7 @@ class RandomWalkEnv(gym.Env):
self.state -= 1 self.state -= 1
if (action == 1): if (action == 1):
self.state += 1 self.state += 1
if (self.state >= 6): if (self.state >= self.size):
reward = 1 reward = 1
done = True done = True
if (self.state <= 0): if (self.state <= 0):
@ -25,7 +26,11 @@ class RandomWalkEnv(gym.Env):
return np.array(self.state), reward, done, {} return np.array(self.state), reward, done, {}
def _reset(self): def _reset(self):
#print("reset") #print("reset")
self.state = 1 # TODO start in a random position print("#self.size:",self.size)
self.state = np.random.randint(1,self.size-1)
print("starting: ", self.state)
def _render(self, mode='human', close=False): def _render(self, mode='human', close=False):
if close:
return
#print("render") #print("render")
print(self.state) print("current state: ",self.state)