Zafar Mahmood
Zafar Mahmood

Reputation: 41

SuperMarioBros-Nes with OpenAI baseline, How?

I am trying to run SuperMarioBros environment in OpenAI baselines. Usually these retro environments are different from native attari 2600 that been support by gym library.

In order to make it run with baselines a third party library is need to be installed that comes with retro using the code taking the help from this link (https://www.videogames.ai/2019/01/29/Setup-OpenAI-baselines-retro.html)

python -m retro.import .
python -m baselines.run --alg=a2c --env=SuperMarioBros-Nes --gamestate=Level3-1.state --network=cnn --num_env=2 --num_timesteps=1e3

but unfortunately even after this, it doesn't run and giving the error of rom not found.

Although after installing the external retro, it should be okay but its requiring raw-rom files directly from game-emulator. Is there any possible way to find a turn around ? Or am I missing something here

    Process SpawnProcess-2: Traceback (most recent call last): 
File "/usr/local/lib/python3.6/dist-packages/retro/__init__.py", line 49, in make     retro.data.get_romfile_path(game, inttype)   
File "/usr/local/lib/python3.6/dist-packages/retro/data/__init__.py", line 288, in get_romfile_path    
raise FileNotFoundError("No romfiles found for game: %s" % game) FileNotFoundError: 
No romfiles found for game: SuperMarioBros-Nes

Upvotes: 2

Views: 2387

Answers (2)

Sandeep Bhutani
Sandeep Bhutani

Reputation: 629

I did a hack and able to run the mario in retro (In windows itself). Below are step by step of the trick:

  1. install retro and install https://pypi.org/project/gym-super-mario-bros/ given in my previous answer
  2. Copy .nes files from lib/python3.7/site-packages/gym_super_mario_bros/_roms (this is where gym-super-mario-bros installed in site-packages) -> to Lib\site-packages\retro\data\stable\SuperMarioBros-Nes (This is where retro is installed in site-packages).
  3. Rename the super-mario-bros.nes to rom.nes
  4. You are done. You can start mario using following code :
import retro
def main():
    env = retro.make(game='SuperMarioBros-Nes')
    obs = env.reset()
    while True:
        obs, rew, done, info = env.step(env.action_space.sample())
        env.render()
        if done:
            obs = env.reset()
    env.close()

if __name__ == "__main__":
    main()

An extra tip: If you want to play mario manually after this then run following command. (Z for jump and x for firing): python -m retro.examples.interactive --game SuperMarioBros-Nes [Enjoy]

Upvotes: 1

Sandeep Bhutani
Sandeep Bhutani

Reputation: 629

By default only 1 game ROM is installed by retro.

Did you try this. It is not using retro env (Or maybe using internally, not sure). But it is working for me:
https://pypi.org/project/gym-super-mario-bros/

Python 2.7.16 |Anaconda, Inc.| (default, Mar 14 2019, 21:00:58)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 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)
>>> done = True
>>> for step in range(5000):
...     if done:
...         state = env.reset()
...     state, reward, done, info = env.step(env.action_space.sample())
...     env.render()
...

Note: I am running on linux machine (Windows was giving trouble)

Upvotes: 0

Related Questions