P
PyBoy5mo ago
snakelimb

Issue asserting Cartridge title SML

I am having some difficulty running the SML land Rom in pyboy. I am under the impression that pyboy will use the cartridge title (from the header) to determine which game wrapper to use, and this is why the sample code includes the assert pyboy.cartridge_title == "SUPER MARIOLAN". Right now my code fails this assertion, and when I made some code to read the header, it says the title should be "SUPER MARIOLAND" with the "D" at the end. Well, modifying the assert statement to reflect this additional D did not help. I can run the code without the assert statement but then I get issues, like "AttributeError: '_cython_3_0_8.cython_function_or_method' object has no attribute" 'game_area_mapping' which I assume is because the proper wrapper is not being used. I did just check the pyboy version and it is Version: 1.6.14, so perhaps I need to update. I am running the code in the puffertank container in WSL, which VS Code is connected to. It looks like that was the pyboy version that was required by pokegym.
20 Replies
krs013
krs0135mo ago
Modifying the code won't be an effective way to debug unless you recompile PyBoy from source after doing so, just FYI. I can't help more right now but maybe someone around here has a checksum of the rom--my first guess is that you have a different or modified rom file of some kind.
Bækalfen
Bækalfen5mo ago
Don't know about puffertank etc. You should probably ask the author (@jsuarez?) about which versions of PyBoy are supported. You're right that SML does in fact have the bytes for "LAND" with a 'D'. Can't remember right now if there are any reason to truncate it But SML has always been part of the testing, so it's weird if it doesn't work
krs013
krs0135mo ago
There were multiple Super Mario Land games for the gameboy, maybe it's a different one?
snakelimb
snakelimbOP5mo ago
I just downloaded 3 additional roms from different sites and tried them all to the same result. I need run a checksum comparison which I have not yet.
Bækalfen
Bækalfen5mo ago
Please don't tell us where you got the ROM from. We cannot condone piracy
Bækalfen
Bækalfen5mo ago
Here is an explanation why the name is truncated https://gbdev.io/pandocs/The_Cartridge_Header.html#0134-0143--title
Pan Docs
The Cartridge Header
The single, most comprehensive technical reference to Game Boy available to the public.
Bækalfen
Bækalfen5mo ago
The reason is "that's just kinda how it is"
snakelimb
snakelimbOP5mo ago
ok my bad
krs013
krs0135mo ago
Yep. I forgot about this, but the correct sha256 sum can be found in the test code:
470d6c45c9bcf7f0397d00c1ae6de727c63dd471049c8eedbefdc540ceea80b4
470d6c45c9bcf7f0397d00c1ae6de727c63dd471049c8eedbefdc540ceea80b4
snakelimb
snakelimbOP5mo ago
Thank you for the checksum. One does match that checksum, but strangly it still run into the assertion issue.
krs013
krs0135mo ago
curious. any chance it's loading from a save state?
snakelimb
snakelimbOP5mo ago
I restarted vs studio code, and am reconnecting to the docker container for puffertank. I was thinking maybe it was trying to reference one of the previous files.
Bækalfen
Bækalfen5mo ago
Also, could you paste the first part of your code? Just so we can see if anything is off
snakelimb
snakelimbOP5mo ago
py class SuperMarioLandEnv(gym.Env):
def __init__(self, rom_path, debug=False):
super().__init__()
self.pyboy = PyBoy(rom_path)
assert self.pyboy.cartridge_title == "SUPER MARIOLAN"

if not debug:
self.pyboy.set_emulation_speed(0)
self.mario = self.pyboy.game_wrapper
self.mario.game_area_mapping(self.mario.mapping_compressed, 0)
self.mario.start_game()

# Verify initial game state
assert self.mario.score == 0
assert self.mario.lives_left == 2
assert self.mario.time_left == 400

self.pyboy.tick() # To render screen after .start_game

self.action_space = spaces.Discrete(len(actions))
self.observation_space = spaces.Box(
low=0, high=255, shape=(4, 84, 84), dtype=np.uint8
)

self._fitness = 0
self._previous_fitness = 0
self._last_progress = 0
py class SuperMarioLandEnv(gym.Env):
def __init__(self, rom_path, debug=False):
super().__init__()
self.pyboy = PyBoy(rom_path)
assert self.pyboy.cartridge_title == "SUPER MARIOLAN"

if not debug:
self.pyboy.set_emulation_speed(0)
self.mario = self.pyboy.game_wrapper
self.mario.game_area_mapping(self.mario.mapping_compressed, 0)
self.mario.start_game()

# Verify initial game state
assert self.mario.score == 0
assert self.mario.lives_left == 2
assert self.mario.time_left == 400

self.pyboy.tick() # To render screen after .start_game

self.action_space = spaces.Discrete(len(actions))
self.observation_space = spaces.Box(
low=0, high=255, shape=(4, 84, 84), dtype=np.uint8
)

self._fitness = 0
self._previous_fitness = 0
self._last_progress = 0
from pyboy import PyBoy
from pyboy.utils import WindowEvent

# Initialize PyBoy with the Super Mario Land ROM
pyboy = PyBoy("supermarioland.gb")
pyboy.set_emulation_speed(0)

assert pyboy.cartridge_title == "SUPER MARIOLAN"

# Access the game wrapper
mario = pyboy.game_wrapper
mario.game_area_mapping(mario.mapping_compressed, 0)
mario.start_game()

# Verify initial game state
assert mario.score == 0
assert mario.lives_left == 2
assert mario.time_left == 400
assert mario.world == (1, 1)

# Render the screen after starting the game
pyboy.tick()
pyboy.screen.image.save("SuperMarioLand1.png")
print(mario)
from pyboy import PyBoy
from pyboy.utils import WindowEvent

# Initialize PyBoy with the Super Mario Land ROM
pyboy = PyBoy("supermarioland.gb")
pyboy.set_emulation_speed(0)

assert pyboy.cartridge_title == "SUPER MARIOLAN"

# Access the game wrapper
mario = pyboy.game_wrapper
mario.game_area_mapping(mario.mapping_compressed, 0)
mario.start_game()

# Verify initial game state
assert mario.score == 0
assert mario.lives_left == 2
assert mario.time_left == 400
assert mario.world == (1, 1)

# Render the screen after starting the game
pyboy.tick()
pyboy.screen.image.save("SuperMarioLand1.png")
print(mario)
krs013
krs0135mo ago
(pro tip: put ```py before your code for syntax highlighting)
snakelimb
snakelimbOP5mo ago
this code based on the SML example also got the AssertionError
Bækalfen
Bækalfen5mo ago
Ok, so your problem is that you're running an old version (v1.6) of PyBoy and mixing with v2.0 API
snakelimb
snakelimbOP5mo ago
So I decided to just try Kirby instead because I know I had used the environment on my laptop before. I copied the code to my pc and it ran into the same assertion issue with kirby. I went ahead and updated pyboy in the container and that fixed the assertion issue. so I'm thinking it is something to do with the Version: 1.6.14 Pyboy
Bækalfen
Bækalfen5mo ago
See this one for an example that matches your version: https://github.com/Baekalfen/PyBoy/blob/v1.6.14/extras/examples/gamewrapper_mario.py So at line assert pyboy.cartridge_title == "SUPER MARIOLAN" you have a problem because in v1.6 cartridge_title is a function, so you should do cartridge_title() == .... In v2.0 it's a variable
snakelimb
snakelimbOP5mo ago
ok I see Thank you both for your help. I got mario jumping around again. Now to improve these rewards, and get multiple envs going.

Did you find this page helpful?