gameboy_worlds.emulation
This submodule handles the emulation of Gameboy games. The core classes here are:
StateParser: Responsible for parsing the game state from the screen, and the memory states of the gameboy. Can be used to extract relevant information from the game state at each step (e.g. player location, current party, inventory items, etc).StateTracker: Uses theStateParserand pre-registers specific state tracking logic that is called after every button press in the game. This class is responsible for maintaining the game state information at each step. It also tracks relevant metrics over playthroughs (e.g. number of battles won) and aggregates metrics over multiple playthroughs (across resets) if required.Emulator: The core class that handles the emulation of the game. It carries aStateParserandStateTracker. Every step runs a single button press, and ensures that the state tracker is properly updated.
Briefly skim the documentation for each of these classes to understand their roles, the fundamental structure they impose and how they interact with each other.
In practice, unless you are implementing new games, you will not need to interact with these base classes directly. Each have subclasses that implement Pokémon specific logic and provides some additional structure.
This is what you should familiarize yourself with most deeply if you wish to use this package as a black box API and not care about the internals. Go to the pokemon submodule and look at the classes defined there.
1""" 2This submodule handles the emulation of Gameboy games. The core classes here are: 31. `StateParser`: Responsible for parsing the game state from the screen, and the memory states of the gameboy. Can be used to extract relevant information from the game state at each step (e.g. player location, current party, inventory items, etc). 42. `StateTracker`: Uses the `StateParser` and pre-registers specific state tracking logic that is called after every button press in the game. This class is responsible for maintaining the game state information at each step. It also tracks relevant metrics over playthroughs (e.g. number of battles won) and aggregates metrics over multiple playthroughs (across resets) if required. 53. `Emulator`: The core class that handles the emulation of the game. It carries a `StateParser` and `StateTracker`. Every step runs a single button press, and ensures that the state tracker is properly updated. 6 7Briefly skim the documentation for each of these classes to understand their roles, the fundamental structure they impose and how they interact with each other. 8 9In practice, unless you are implementing new games, you will not need to interact with these base classes directly. Each have subclasses that implement Pokémon specific logic and provides some additional structure. 10This is what you should familiarize yourself with most deeply if you wish to use this package as a black box API and not care about the internals. Go to the `pokemon` submodule and look at the classes defined there. 11""" 12 13from gameboy_worlds.emulation.emulator import Emulator, LowLevelActions 14from gameboy_worlds.emulation.tracker import StateTracker, TestTrackerMixin 15from gameboy_worlds.emulation.parser import StateParser 16 17 18def clear_tmp_sessions(): 19 """ 20 Clears any temporary emulator sessions that may have been left 21 over from previous runs. This is useful to call at the start of a new 22 run to ensure no leftover sessions interfere with the new run. 23 """ 24 from gameboy_worlds.emulation.emulator import IDPathCreator 25 from gameboy_worlds.utils import load_parameters 26 27 parameters = load_parameters() 28 creator = IDPathCreator(parameters) 29 creator.clear_tmp_sessions()
19def clear_tmp_sessions(): 20 """ 21 Clears any temporary emulator sessions that may have been left 22 over from previous runs. This is useful to call at the start of a new 23 run to ensure no leftover sessions interfere with the new run. 24 """ 25 from gameboy_worlds.emulation.emulator import IDPathCreator 26 from gameboy_worlds.utils import load_parameters 27 28 parameters = load_parameters() 29 creator = IDPathCreator(parameters) 30 creator.clear_tmp_sessions()
Clears any temporary emulator sessions that may have been left over from previous runs. This is useful to call at the start of a new run to ensure no leftover sessions interfere with the new run.