Kautenja / gym-super-mario-bros

An OpenAI Gym interface to Super Mario Bros. & Super Mario Bros. 2 (Lost Levels) on The NES
Other
678 stars 133 forks source link

hiccups during rendering #100

Closed samiulextreem closed 4 years ago

samiulextreem commented 4 years ago

Describe the bug

when i run the environment the game play is in constant hiccups

A clear and concise description of what the bug is.

Reproduction Script

from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
import gym
from  gym import  wrappers
import numpy as np
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT

env_id = 'SuperMarioBros-v1'

env = gym_super_mario_bros.make(env_id)

if __name__ == '__main__':

    obs = env.reset()
    total_mean_rewards = np.zeros(shape =100)
    for  i in range(100000):

        obs, rewards, dones, info = env.step(env.action_space.sample())
        total_mean_rewards[i%100] = rewards
        env.render()
        if dones == True:
            print('env finished')
            env.reset()

    print(np.mean(total_mean_rewards))
Kautenja commented 4 years ago

it's not stuttering, the game is being paused. You need to wrap the environment with the JoypadSpace (env = JoypadSpace(env, SIMPLE_MOVEMENT)) otherwise you are sampling the entire controller space, which has a pause button in it.

from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
import gym
from  gym import  wrappers
import numpy as np
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT

env_id = 'SuperMarioBros-v1'

env = gym_super_mario_bros.make(env_id)
env = JoypadSpace(env, SIMPLE_MOVEMENT)

if __name__ == '__main__':
    obs = env.reset()
    total_mean_rewards = np.zeros(shape=100)
    for  i in range(100000):
        obs, rewards, dones, info = env.step(env.action_space.sample())
        total_mean_rewards[i%100] = rewards
        env.render()
        if dones == True:
            print('env finished')
            env.reset()
    print(np.mean(total_mean_rewards))
samiulextreem commented 4 years ago

lol