Kautenja / gym-super-mario-bros

An OpenAI Gym interface to Super Mario Bros. & Super Mario Bros. 2 (Lost Levels) on The NES

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not rendering

sachinruk opened this issue · comments

Describe the bug

I am trying to get a movie of my agent by plotting the observations. However, the observations do not change even though the rewards, and infos change.

Reproduction Script

Provide a script to reproduce the error using the following template,
replacing <YOUR SCRIPT> with your script:

from nes_py.wrappers import BinarySpaceToDiscreteSpaceEnv
import gym_super_mario_bros
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
env = gym_super_mario_bros.make('SuperMarioBros-v0')
env = BinarySpaceToDiscreteSpaceEnv(env, SIMPLE_MOVEMENT)

observation = env.reset()
frames = []
r = []
infos = []
for t in range(100):
    # Render into buffer. 
    frames.append(observation) #env.render(mode = 'rgb_array')
    observation, reward, done, info = env.step(env.action_space.sample())
    infos.append(info)
    r.append(reward)
    if done:
        break
        
r = np.array(r)

Expected behavior

The mean (absolute) difference between any two frames is constantly zero. I would have expected the image to change when plotting. However, when looking at the infos array, the x_pos, y_pos is constantly changing. This to me indicates that the plotting function is not working for some reason.

Additional context

I am running this on google colab. I installed the library by simply doing !pip install gym-super-mario-bros.

So turns out what was happening was that I should have been saving a copy of observation, not just appending it. Observation was being constantly rewritten. This was my work around:

frames = np.zeros((MAX_STEPS, 240, 256, 3), dtype=np.uint8)
for step in range(MAX_STEPS):
    # Render into buffer. 
    frames[step] = env.render(mode = 'rgb_array')
    observation, reward, done, info = env.step(env.action_space.sample())