grantsrb / Gym-Snake

An OpenAI gym environment made for RL
64 stars 28 forks source link

Game does not render properly? #3

Open michael-ziedalski opened 5 years ago

michael-ziedalski commented 5 years ago

Hello. I found this seemingly flexible and aesthetic implementation of snake, and I wanted to try it out as soon as I could before training any model.

So, using the following code, I try to render a game with random movements gained from env.action_space.sample(), but what happens is only the first frame renders, and I get <Figure size 576x396 with 0 Axes> returned for every frame thereafter.

Other OpenAI gym environments render correctly for me, so what am I doing wrong, or is this a bug?

My code:

import gym
import gym_snake

## Creating environment
env = gym.make('snake-v0')
obs = env.reset()

## Observing snake for now
obs = env.reset()

for _ in range(5): # run for 1000 steps
    env.render() # Render latest instance of game
    action = [env.action_space.sample()] # Random action
    env.step(action) # Implement action

env.close()
grantsrb commented 5 years ago

Thanks for the heads up! Your code should render now. Let me know if the problem persists.

michael-ziedalski commented 5 years ago

I uninstalled using pip and re-downloaded the zip file, and installed again using the instructions, and this problem persists.

Here is a screenshot.

screen shot 2018-12-28 at 3 59 27 pm

For the record, my specs are MacOS 10.11.6, Python 3.6.5, Tensorflow 1.9, but everything else is completely up to date.

grantsrb commented 5 years ago

Forgive my arrogance closing the issue before it was solved. Thanks again.

Are you using a Jupyter Notebook? If you are, can you repeat what you did above and then include the line:

%matplotlib notebook

before using the render function? Like so:

import gym
import gym_snake
%matplotlib notebook

## Creating environment
env = gym.make('snake-v0')
obs = env.reset()

## Observing snake for now
obs = env.reset()

for _ in range(5): # run for 1000 steps
    env.render() # Render latest instance of game
    action = [env.action_space.sample()] # Random action
    env.step(action) # Implement action

env.close()

I believe the issue should be solved, but it would be great if you could verify.

michael-ziedalski commented 5 years ago

No problem whatsoever, I'm glad in fact that a developer is taking such an active interest in eliminating bugs.

I actually use many custom setting for matplotlib, like %config InlineBackend.figure_format = 'retina', but I've confirmed none of them have any effect here.

Running the above, using notebook as the backend, the screen is simply white now, and in the end only the last frame loads once the loop finishes, essentially creating the opposite of what was happening before with inline.

screen shot 2018-12-28 at 6 51 58 pm

I assume it's the last frame (only white until then) because the snake is nowhere to be seen.

However, I found the snake game does render if the script is run through the terminal, though that would be missing all the productive convenience of jupyter.

OpenAI gym normally renders game in another window; would that be a new rendering possibility?