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

How do we start a mario in firemode?

aadeshnpn opened this issue · comments

I am trying to start a level for the Deep-RL agent to play where mario is already in Firemode. Is there any hack we can do in the wrapper?

I found a hacky way. Mario will function like Fireball Mario, but will be short. When he hits an enemy he will lose the fireball power, but get tall as expected after losing fireball. However, when he gets hit a second time he will die instead of turning into small Mario. I tried out a few other ideas, but nothing more sophisticated did anything better (though there was one tek that changed Mario to short fireball Luigi oddly). You can use the snippet below to inject the hack into a production environment if these conditions will suite your use case.

import gym_super_mario_bros
env = gym_super_mario_bros.make('SuperMarioBros-v0')

def hack(method):
    def hacked():
        env.unwrapped._write_mem(0x0756, 2)
        return method()
    return hacked

env.unwrapped._did_reset = hack(env.unwrapped._did_reset)

Feel free to clone the repository and mess with the code if you'd like to tinker with it more in-depth. Closing issue as I don't see any way of integrating this feature in a clean way that preserves the intended game mechanics.