-
Notifications
You must be signed in to change notification settings - Fork 0
/
lunar_lander.py
52 lines (38 loc) · 1.45 KB
/
lunar_lander.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
#!/usr/bin/env python
"""RandomWalk environment class for RL-Glue-py.
"""
from environment import BaseEnvironment
import numpy as np
import gym
class LunarLanderEnvironment(BaseEnvironment):
def env_init(self, env_info={}):
"""
Setup for the environment called when the experiment first starts.
"""
self.env = gym.make("LunarLander-v2")
self.env.seed(0)
def env_start(self):
"""
The first method called when the experiment starts, called before the
agent starts.
Returns:
The first state observation from the environment.
"""
reward = 0.0
observation = self.env.reset()
is_terminal = False
self.reward_obs_term = (reward, observation, is_terminal)
# return first state observation from the environment
return self.reward_obs_term[1]
def env_step(self, action):
"""A step taken by the environment.
Args:
action: The action taken by the agent
Returns:
(float, state, Boolean): a tuple of the reward, state observation,
and boolean indicating if it's terminal.
"""
last_state = self.reward_obs_term[1]
current_state, reward, is_terminal, _ = self.env.step(action)
self.reward_obs_term = (reward, current_state, is_terminal)
return self.reward_obs_term