Created
September 12, 2019 19:27
-
-
Save pedrohbtp/ba03e5a59f759fc7cf6c9062088a7fd8 to your computer and use it in GitHub Desktop.
basic structure of an openai gym env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
from gym import spaces | |
class MyEnv(gym.Env): | |
"""Custom Environment""" | |
metadata = {'render.modes': ['human']} | |
def __init__(self): | |
super(Snake, self).__init__() | |
# necessary internal env id | |
self.id = "MyEnv" | |
# defines the kind of actions you can take | |
# below it is an example where the possible actions are only the values 0 or 1 | |
self.action_space = spaces.Discrete(2) | |
# defines the kind of observations you can make | |
# below it is an example where the possible observations are only the values 0 or 1 | |
self.observation_space = spaces.Discrete(2) | |
def reset(self): | |
''' Resets the game and returns the initial state | |
''' | |
pass | |
def render(self, mode='human'): | |
''' renders the game | |
''' | |
pass | |
def step(self, action): | |
''' performs the action and observes the state, get the reward, check if the game | |
is over and get more info | |
''' | |
obs = None | |
reward = None | |
done = None | |
info = {} | |
return obs, reward, done, info | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment