openai / retro

Retro Games in Gym
MIT License
3.35k stars 524 forks source link

GameBoyAdvance does not seem to load savestate #238

Closed nicoxxl closed 3 years ago

nicoxxl commented 3 years ago

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

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
endrift commented 3 years ago

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.

endrift commented 3 years ago

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.

nicoxxl commented 3 years ago

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).