Super Mario Land wrapper

class pyboy.plugins.game_wrapper_super_mario_land.GameWrapperSuperMarioLand(*args, **kwargs)[source]

Bases: PyBoyGameWrapper

This class wraps Super Mario Land, and provides easy access to score, coins, lives left, time left and world for AIs.

If you call print on an instance of this object, it will show an overview of everything this object provides.

Super Mario Land
>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.tick(1, True)
True
>>> pyboy.screen.image.resize((320,288)).save('docs/plugins/supermarioland.png') # The exact screenshot shown above
>>> pyboy.game_wrapper
Super Mario Land: World 1-1
Coins: 0
lives_left: 2
Score: 0
Time left: 400
Level progress: 251
Sprites on screen:
Sprite [3]: Position: (35, 112), Shape: (8, 8), Tiles: (Tile: 0), On screen: True
Sprite [4]: Position: (43, 112), Shape: (8, 8), Tiles: (Tile: 1), On screen: True
Sprite [5]: Position: (35, 120), Shape: (8, 8), Tiles: (Tile: 16), On screen: True
Sprite [6]: Position: (43, 120), Shape: (8, 8), Tiles: (Tile: 17), On screen: True
Tiles on screen:
       0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19
____________________________________________________________________________________
0  | 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339
1  | 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320
2  | 300 300 300 300 300 300 300 300 300 300 300 300 321 322 321 322 323 300 300 300
3  | 300 300 300 300 300 300 300 300 300 300 300 324 325 326 325 326 327 300 300 300
4  | 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300
5  | 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300
6  | 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300
7  | 300 300 300 300 300 300 300 300 310 350 300 300 300 300 300 300 300 300 300 300
8  | 300 300 300 300 300 300 300 310 300 300 350 300 300 300 300 300 300 300 300 300
9  | 300 300 300 300 300 129 310 300 300 300 300 350 300 300 300 300 300 300 300 300
10 | 300 300 300 300 300 310 300 300 300 300 300 300 350 300 300 300 300 300 300 300
11 | 300 300 310 350 310 300 300 300 300 306 307 300 300 350 300 300 300 300 300 300
12 | 300 368 369 300   0   1 300 306 307 305 300 300 300 300 350 300 300 300 300 300
13 | 310 370 371 300  16  17 300 305 300 305 300 300 300 300 300 350 300 300 300 300
14 | 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352
15 | 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353
mapping_compressed

Compressed mapping for pyboy.PyBoy.game_area_mapping

Example using mapping_compressed, Mario is 1. He is standing on the ground which is 10:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.game_area_mapping(pyboy.game_wrapper.mapping_compressed, 0)
>>> pyboy.game_wrapper.game_area()
array([[ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0, 13,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0, 14, 14,  0,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0, 14, 14,  0,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
       [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]], dtype=uint32)
mapping_minimal

Minimal mapping for pyboy.PyBoy.game_area_mapping

Example using mapping_minimal, Mario is 1. He is standing on the ground which is 3:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.game_area_mapping(pyboy.game_wrapper.mapping_minimal, 0)
>>> pyboy.game_wrapper.game_area()
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 3, 3, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 3, 3, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
       [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]], dtype=uint32)
world

Provides the current “world” Mario is in, as a tuple of as two integers (world, level).

You can force a level change with GameWrapperSuperMarioLand.set_world_level.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.world
(1, 1)
coins

The number of collected coins.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.coins
0
lives_left

The number of lives Mario has left.

You can change this with GameWrapperSuperMarioLand.set_lives_left.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.lives_left
2
score

The score provided by the game

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.score
0
time_left

The number of seconds left to finish the level.

You can change this with GameWrapperSuperMarioLand.set_time_left.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.time_left
400
level_progress

An integer of the current “global” X position in this level. Can be used for AI scoring.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.level_progress
251
set_time_left(time)[source]

Set the amount of time left to any number between 0 and 999.

This should only be called when the game has started.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.time_left
400
>>> pyboy.game_wrapper.set_time_left(123)
>>> pyboy.tick(1, False)
True
>>> pyboy.game_wrapper.time_left
123
Parameters:

time (int) – The wanted time left

set_lives_left(amount)[source]

Set the amount lives to any number between 0 and 99.

This should only be called when the game has started.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.lives_left
2
>>> pyboy.game_wrapper.set_lives_left(10)
>>> pyboy.tick(1, False)
True
>>> pyboy.game_wrapper.lives_left
10
Parameters:

amount (int) – The wanted number of lives

set_world_level(world, level)[source]

Patches the handler for pressing start in the menu. It hardcodes a world and level to always “continue” from.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.set_world_level(3, 2)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.world
(3, 2)
Parameters:
  • world (int) – The world to select a level from, 0-3

  • level (int) – The level to start from, 0-2

start_game(timer_div=None, world_level=None, unlock_level_select=False)[source]

Call this function right after initializing PyBoy. This will start a game in world 1-1 and give back control on the first frame it’s possible.

The state of the emulator is saved, and using reset_game, you can get back to this point of the game instantly.

The game has 4 major worlds with each 3 level. to start at a specific world and level, provide it as a tuple for the optional keyword-argument world_level.

If you’re not using the game wrapper for unattended use, you can unlock the level selector for the main menu. Enabling the selector, will make this function return before entering the game.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game(world_level=(4,1))
>>> pyboy.game_wrapper.world
(4, 1)
Kwargs:
  • timer_div (int): Replace timer’s DIV register with this value. Use None to randomize.

  • world_level (tuple): (world, level) to start the game from

  • unlock_level_select (bool): Unlock level selector menu

reset_game(timer_div=None)[source]

After calling start_game, use this method to reset Mario to the beginning of start_game.

If you want to reset to other worlds or levels of the game – for example world 1-2 or 3-1 – reset the entire emulator and provide the world_level on start_game.

Example:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.reset_game()
Kwargs:
  • timer_div (int): Replace timer’s DIV register with this value. Use None to randomize.

game_area()[source]

Use this method to get a matrix of the “game area” of the screen. This view is simplified to be perfect for machine learning applications.

In Super Mario Land, this is almost the entire screen, expect for the top part showing the score, lives left and so on. These values can be found in the variables of this class.

In this example using GameWrapperSuperMarioLand.mapping_minimal, Mario is 1. He is standing on the ground which is 3:

>>> pyboy = PyBoy(supermarioland_rom)
>>> pyboy.game_wrapper.start_game()
>>> pyboy.game_wrapper.game_area_mapping(pyboy.game_wrapper.mapping_minimal, 0)
>>> pyboy.game_wrapper.game_area()
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 3, 3, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 3, 3, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
       [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]], dtype=uint32)
Returns:

Simplified two-dimensional array of mapped tile identifiers with dtype numpy.uint32.

Return type:

numpy.ndarray

game_over()[source]

After calling start_game, you can call this method at any time to know if the game is over.