Skip to content

Instantly share code, notes, and snippets.

@sagar03d
Created December 26, 2017 16:43
Show Gist options
  • Save sagar03d/1c89517a1297216cd92ec947cc082e21 to your computer and use it in GitHub Desktop.
Save sagar03d/1c89517a1297216cd92ec947cc082e21 to your computer and use it in GitHub Desktop.
import gym
import cv2
class Environment:
def __init__(self, params):
self.gym = gym.make(params.game)
self.observation = None
self.display = params.display
self.terminal = False
self.dims = (params.height, params.width)
def actions(self):
return self.gym.action_space.n
def restart(self):
self.observation = self.gym.reset()
self.terminal = False
def act(self, action):
if self.display:
self.gym.render()
self.observation, reward, self.terminal, info = self.gym.step(action)
if self.terminal:
#if self.display:
# print "No more lives, restarting"
self.gym.reset()
return reward
def getScreen(self):
return cv2.resize(cv2.cvtColor(self.observation, cv2.COLOR_RGB2GRAY), self.dims)
def isTerminal(self):
return self.terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment