Search code examples
pythonreinforcement-learningopenai-gymnes

Is there a way to change the register of Super Mario Bros (NES) level 1 world 1 to start in a specific position?


I've been using the gym-super-mario-bros library (https://github.com/Kautenja/gym-super-mario-bros) and I was trying to change the registers' values in order to set the position of Mario to a specific position inside level 1 in world 1.

I tried to check the RAM information map (https://datacrystal.romhacking.net/wiki/Super_Mario_Bros.:RAM_map), but if I change the page information in 0x6d and the position inside the page (0x86), Mario always move to 0 position at the very beginning of the game. In the library code I modified the values inside the _x_position function in smb_env.py.


Solution

  • In the NESEnv class there are functions for saving the current state of the emulator and another for restoring it. These are named _backup and _restore, respectively. You can call these like this:

    env = gym_super_mario_bros.make(version)
    env.unwrapped._backup()
    env.unwrapped._restore()