openai/retro

GameBoyAdvance does not seem to load savestate

nicoxxl opened this issue · 3 comments

Issue summary

With the following code, the game start from the start instead of the chosen state.

The save state is generated using mGBA 0.9.0 (the standalone one, not with RetroArch) on the same ROM file.

The test.py output the following line, while starting the game from start:

env.em.set_state(env.initial_state) False

System information

  • Operating system : Arch Linux
  • python 3.9
  • master
  • Game : F-Zero - Maximum Velocity (USA, Europe), sha1 8a08e29ec987f9cbdde21c34d5f7657aa7ba0be6

Code

FZeroMaximumVelocity-GbAdvance/metadata.json

{
    "default_state": "training_hotviolet_pawn_biancacity"
}

test.py

import retro
import os

HERE = os.path.dirname(os.path.abspath(__file__))
retro.data.Integrations.add_custom_path(HERE)


def main_test():
    env = retro.make(
        game="FZeroMaximumVelocity-GbAdvance",
        inttype=retro.data.Integrations.ALL,
        state="training_hotviolet_pawn_biancacity",
    )
    obs = env.reset()
    print("env.em.set_state(env.initial_state)", env.em.set_state(env.initial_state))
    act = [0] * 12
    act[8] = 1
    while True:
        obs, rew, done, info = env.step(act)
        env.render()
        if done:
            obs = env.reset()
    env.close()


if __name__ == "__main__":
    main_test()
$ tree FZeroMaximumVelocity-GbAdvance/
FZeroMaximumVelocity-GbAdvance/
├── data.json
├── metadata.json
├── rom.gba
├── rom.sha
├── scenario.json
├── script.lua
├── training_hotviolet_pawn_biancacity.ss1
└── training_hotviolet_pawn_biancacity.state

This is not a bug, the GBA core in Gym Retro is very old in comparison and mGBA has checks to keep too-old versions from loading savestates that would surely be incompatible. I try not to trigger those checks if not needed, but every so often the layout needs to change for it to keep working.

Also the format is slightly different--you'd need to set the settings in the standalone version to be pretty specific and then post-process the savestate file (mostly just gzipping it) before you can import it in Gym Retro anyway.

Thanks a lot !

I found a workaround (I ma posting it for future references) :

I wrote a simple script to go to the desired state and then used the method env.em.get_state() to get the savestate (and then gzipped it).