Metadata-Version: 2.1
Name: pygba
Version: 0.2.1
Summary: A Python wrapper around the Game Boy Advance emulator mGBA with built-in support for gymnasium environments.
Author: Dimitri von Rütte
License: Copyright 2023 Dimitri von Rütte
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Project-URL: github, https://github.com/dvruette/pygba
Keywords: gba,mgba,emulator,gymnasium,reinforcement-learning
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: gymnasium ~=0.29.1
Requires-Dist: numpy ~=1.26.1
Requires-Dist: pygame ~=2.5.2

# PyGBA

A Python wrapper around the Game Boy Advance emulator mGBA with built-in support for gymnasium environments.


## Usage

PyGBA is designed to be used by bots/AI agents. It provides an easy-to-use interface to interact with the emulator as well as a [`gymnasium`](https://github.com/Farama-Foundation/Gymnasium) environment for reinforcement learning.

While any GBA ROM can be run out-of-the box, if you want to do reward-based reinforcement learning, you might want to use a game-specific wrapper that provides a reward function. Currently, only a wrapper for [Pokemon Emerald](https://vimm.net/vault/5625) is provided, but more will be added in the future.

A gym environment can be created as follows:
```python
from pygba import PyGBA, PyGBAEnv, PokemonEmerald

rom_path = "path/to/pokemon_emerald.gba"
gba = PyGBA(rom_path, autoload_save=True)  # if autoload_save is True, a save file will be loaded if one exists next to the ROM

game_wrapper = PokemonEmerald()  # optionally customize the reward function by passing additional arguments
env = PyGBAEnv(gba, game_wrapper)
```


## Installation

Install PyGBA with pip using:
```bash
pip install pygba
```

You'll also need to install [mGBA](https://mgba.io/) with Python bindings. By default, mGBA is installed without Python bindings, so until the situation is improved, you'll need to build mGBA from source.

### Installing mGBA from wheels
Help wanted.

### Building mGBA from source

Official installation instructions can be found [here](https://github.com/mgba-emu/mgba/#compiling), but here's a quick summary.
The important detail is that Python bindings have to be enabled by passing `-DBUILD_PYTHON=ON` to CMake.

First, clone the mGBA repository:
```bash
git clone https://github.com/mgba-emu/mgba.git
cd mgba
```

- **Unix**:
    On Unix-based systems, run the following commands:
    ```bash
    mkdir build
    cd build
    cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DBUILD_PYTHON=ON ..
    make
    sudo make install
    ```

- **macOS**:
    On macOS, additional dependencies are required:
    ```bash
    brew install cmake ffmpeg libzip qt5 sdl2 libedit lua pkg-config
    mkdir build
    cd build
    cmake -DCMAKE_PREFIX_PATH=`brew --prefix qt5` -DBUILD_PYTHON=ON ..
    make
    sudo make install
    ```
    Note: If both `qt` and `qt5` are installed you might run into issues. If that's the case, try uninstalling `qt`.

- **Windows**:
    Please follow the official instructions [here](https://github.com/mgba-emu/mgba/#windows-developer-building).

After compiling mGBA, the Python bindings should be built at `build/python/lib.{platform}-{architecture}-cpython-{version}/mgba`.
To use it in your Python code, you'll need to add it to your `PYTHONPATH` environment variable.

You can check if the bindings were built and installed correctly by running `python -c "import mgba"` (should output nothing).
