Created
June 17, 2016 09:44
-
-
Save jangirrishabh/1408e16765ebfce1e29fe6eb9c2cd728 to your computer and use it in GitHub Desktop.
This file contains 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 | |
#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