OpenAI First Test

Prerequisites

  • Make sure that you followed the first part of this tutorial on installing OpenAI and all its dependencies.
  • Make sure that when you run docker ps on the command line you get output similar to the following (if not, then either Docker is not installed, is not running, or your user does not have priveleges to access the Docker group). OpenAI Universe will not run if this step is not met.

    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    
  • Ensure you are using the virtualenv you created for this project, you can go into it by running the following (substituting for where you located your virtualenv.

    source ~/virtualens/openai/bin/activate
    

First Game

Go into an interactive python shell by typing the following on the command line:

python

Copy and paste the following lines of python code:

# THIS CODE IS TAKEN FROM THE OPENAI GITHUB PAGE
# https://github.com/openai/universe#run-your-first-agent

import gym
import universe  # register the universe environments

env = gym.make('flashgames.DuskDrive-v0')
env.configure(remotes=1)  # automatically creates a local docker container
observation_n = env.reset()

Note: You may need to hit enter one or two extra times after pasting this into the interactive shell to make sure the last line of code gets executed.

When you first run this, it will take some time to download all the files for that game, and you will see progress bars as it does this.

After it has done this, it will continually spit out a large amount of server log printouts about connections, protocols, sockets, and clients. At this stage it should automatically open up an internet browsers. Within your browser window, you will see screen capture of a chrome browser, playing a flash game, like in the following image.

Image of Dusk Drive Game on Browser

If it does not open up a browser automatically (it didn't for me), then you will need to manually enter the following URL in your internet browser:

  • http://localhost:15900/viewer/?password=openai

While it is still spitting out text on the printout, paste the following lines of code in one go (again you may need to press ENTER one or two extra times to get the final line to go through).

# THIS CODE IS TAKEN FROM THE OPENAI GITHUB PAGE
# https://github.com/openai/universe#run-your-first-agent
while True:
    action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n]  # your agent here
    observation_n, reward_n, done_n, info = env.step(action_n)
    env.render()

You should hopefully start seeing, seeing some printouts on the command line about rewards. Also, you should see the car in the window actually driving around by itself.