Skip to content

Instantly share code, notes, and snippets.

@jangirrishabh
Created June 17, 2016 09:44
Show Gist options
  • Save jangirrishabh/1408e16765ebfce1e29fe6eb9c2cd728 to your computer and use it in GitHub Desktop.
Save jangirrishabh/1408e16765ebfce1e29fe6eb9c2cd728 to your computer and use it in GitHub Desktop.
#import gym
#env = gym.make('MountainCar-v0')
#env = gym.make('CartPole-v0')
#env = gym.make('MsPacman-v0')
import gym # get the environment from openAI
import curses # for keypress
env = gym.make('CartPole-v0') #init environment
observation = env.reset()
screen = curses.initscr()
curses.noecho()
curses.curs_set(0)
screen.keypad(1)
screen.addstr("Play the game")
while True:
env.render() # make visible
event = screen.getch()
if event == curses.KEY_LEFT:
print("Left Arrow Key pressed")
action = 0
elif event == curses.KEY_RIGHT:
print("Right Arrow Key pressed")
action = 1
else:
break
env.step(action)
print action
curses.endwin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment