Metadata-Version: 2.1
Name: pyboy
Version: 2.2.2
Summary: Game Boy emulator written in Python
Author-email: Mads Ynddal <mads@ynddal.dk>
License: GNU Lesser General Public License
        =================================
        
        _Version 3, 29 June 2007_
        _Copyright © 2007 Free Software Foundation, Inc. &lt;<http://fsf.org/>&gt;_
        
        Everyone is permitted to copy and distribute verbatim copies
        of this license document, but changing it is not allowed.
        
        
        This version of the GNU Lesser General Public License incorporates
        the terms and conditions of version 3 of the GNU General Public
        License, supplemented by the additional permissions listed below.
        
        ### 0. Additional Definitions
        
        As used herein, “this License” refers to version 3 of the GNU Lesser
        General Public License, and the “GNU GPL” refers to version 3 of the GNU
        General Public License.
        
        “The Library” refers to a covered work governed by this License,
        other than an Application or a Combined Work as defined below.
        
        An “Application” is any work that makes use of an interface provided
        by the Library, but which is not otherwise based on the Library.
        Defining a subclass of a class defined by the Library is deemed a mode
        of using an interface provided by the Library.
        
        A “Combined Work” is a work produced by combining or linking an
        Application with the Library.  The particular version of the Library
        with which the Combined Work was made is also called the “Linked
        Version”.
        
        The “Minimal Corresponding Source” for a Combined Work means the
        Corresponding Source for the Combined Work, excluding any source code
        for portions of the Combined Work that, considered in isolation, are
        based on the Application, and not on the Linked Version.
        
        The “Corresponding Application Code” for a Combined Work means the
        object code and/or source code for the Application, including any data
        and utility programs needed for reproducing the Combined Work from the
        Application, but excluding the System Libraries of the Combined Work.
        
        ### 1. Exception to Section 3 of the GNU GPL
        
        You may convey a covered work under sections 3 and 4 of this License
        without being bound by section 3 of the GNU GPL.
        
        ### 2. Conveying Modified Versions
        
        If you modify a copy of the Library, and, in your modifications, a
        facility refers to a function or data to be supplied by an Application
        that uses the facility (other than as an argument passed when the
        facility is invoked), then you may convey a copy of the modified
        version:
        
        * **a)** under this License, provided that you make a good faith effort to
        ensure that, in the event an Application does not supply the
        function or data, the facility still operates, and performs
        whatever part of its purpose remains meaningful, or
        
        * **b)** under the GNU GPL, with none of the additional permissions of
        this License applicable to that copy.
        
        ### 3. Object Code Incorporating Material from Library Header Files
        
        The object code form of an Application may incorporate material from
        a header file that is part of the Library.  You may convey such object
        code under terms of your choice, provided that, if the incorporated
        material is not limited to numerical parameters, data structure
        layouts and accessors, or small macros, inline functions and templates
        (ten or fewer lines in length), you do both of the following:
        
        * **a)** Give prominent notice with each copy of the object code that the
        Library is used in it and that the Library and its use are
        covered by this License.
        * **b)** Accompany the object code with a copy of the GNU GPL and this license
        document.
        
        ### 4. Combined Works
        
        You may convey a Combined Work under terms of your choice that,
        taken together, effectively do not restrict modification of the
        portions of the Library contained in the Combined Work and reverse
        engineering for debugging such modifications, if you also do each of
        the following:
        
        * **a)** Give prominent notice with each copy of the Combined Work that
        the Library is used in it and that the Library and its use are
        covered by this License.
        
        * **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
        document.
        
        * **c)** For a Combined Work that displays copyright notices during
        execution, include the copyright notice for the Library among
        these notices, as well as a reference directing the user to the
        copies of the GNU GPL and this license document.
        
        * **d)** Do one of the following:
            - **0)** Convey the Minimal Corresponding Source under the terms of this
        License, and the Corresponding Application Code in a form
        suitable for, and under terms that permit, the user to
        recombine or relink the Application with a modified version of
        the Linked Version to produce a modified Combined Work, in the
        manner specified by section 6 of the GNU GPL for conveying
        Corresponding Source.
            - **1)** Use a suitable shared library mechanism for linking with the
        Library.  A suitable mechanism is one that **(a)** uses at run time
        a copy of the Library already present on the user's computer
        system, and **(b)** will operate properly with a modified version
        of the Library that is interface-compatible with the Linked
        Version.
        
        * **e)** Provide Installation Information, but only if you would otherwise
        be required to provide such information under section 6 of the
        GNU GPL, and only to the extent that such information is
        necessary to install and execute a modified version of the
        Combined Work produced by recombining or relinking the
        Application with a modified version of the Linked Version. (If
        you use option **4d0**, the Installation Information must accompany
        the Minimal Corresponding Source and Corresponding Application
        Code. If you use option **4d1**, you must provide the Installation
        Information in the manner specified by section 6 of the GNU GPL
        for conveying Corresponding Source.)
        
        ### 5. Combined Libraries
        
        You may place library facilities that are a work based on the
        Library side by side in a single library together with other library
        facilities that are not Applications and are not covered by this
        License, and convey such a combined library under terms of your
        choice, if you do both of the following:
        
        * **a)** Accompany the combined library with a copy of the same work based
        on the Library, uncombined with any other library facilities,
        conveyed under the terms of this License.
        * **b)** Give prominent notice with the combined library that part of it
        is a work based on the Library, and explaining where to find the
        accompanying uncombined form of the same work.
        
        ### 6. Revised Versions of the GNU Lesser General Public License
        
        The Free Software Foundation may publish revised and/or new versions
        of the GNU Lesser General Public License from time to time. Such new
        versions will be similar in spirit to the present version, but may
        differ in detail to address new problems or concerns.
        
        Each version is given a distinguishing version number. If the
        Library as you received it specifies that a certain numbered version
        of the GNU Lesser General Public License “or any later version”
        applies to it, you have the option of following the terms and
        conditions either of that published version or of any later version
        published by the Free Software Foundation. If the Library as you
        received it does not specify a version number of the GNU Lesser
        General Public License, you may choose any version of the GNU Lesser
        General Public License ever published by the Free Software Foundation.
        
        If the Library as you received it specifies that a proxy can decide
        whether future versions of the GNU Lesser General Public License shall
        apply, that proxy's public statement of acceptance of any version is
        permanent authorization for you to choose that version for the
        Library.
        
Project-URL: Homepage, https://github.com/Baekalfen/PyBoy
Project-URL: Documentation, https://docs.pyboy.dk/index.html
Project-URL: Repository, https://github.com/Baekalfen/PyBoy.git
Keywords: gameboy,game boy,emulator,cython,pypy
Classifier: License :: Free for non-commercial use
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Cython
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: System :: Emulators
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: numpy
Requires-Dist: pysdl2
Requires-Dist: pysdl2-dll
Provides-Extra: all
Requires-Dist: pyopengl; extra == "all"
Requires-Dist: markdown; extra == "all"
Requires-Dist: pdoc3; extra == "all"
Requires-Dist: gym; extra == "all"

<p align="center">
<img src="extras/README/pyboy.svg" width="480">
</p>

__If you have any questions, or just want to chat, [join us on Discord](https://discord.gg/Zrf2nyH).__

[![Discord](https://img.shields.io/discord/584149554132418570?style=for-the-badge&logo=Discord&label=PyBoy)](https://discord.gg/Zrf2nyH)

<!---
Generate GIF with the layout and captions
-->
<table>
  <tbody>
    <tr>
      <td colspan=2 align="center"><a href=https://github.com/PWhiddy/PokemonRedExperiments>Train RL agents to play Pokemon Red</a>
      </td>
      <td align="center"><a href=https://github.com/Baekalfen/PyBoy/wiki/Experimental-and-optional-features#rewind-time>Rewind any game</a><br>
      </td>
    </tr>
    <tr>
      <td colspan=2 align="center">
        <div align="center">
        <a href="http://www.youtube.com/watch?feature=player_embedded&v=DcYLT37ImBY" target="_blank">
        <img src="http://img.youtube.com/vi/DcYLT37ImBY/maxresdefault.jpg" alt="Watch the video" width="500" border="10" />
        <!-- <img src="http://img.youtube.com/vi/DcYLT37ImBY/hqdefault.jpg" alt="Watch the video" width="500" border="10" /> -->
        </a>
        <!-- https://www.youtube.com/watch?v=DcYLT37ImBY -->
        <!-- <img src="extras/README/8.gif" width="400"><br> -->
        </div>
      </td>
      <td align="center">
        <img src="extras/README/5.gif" width="250">
      </td>
    </tr>
    <tr>
      <td align="center">Play the classics<br>
      </td>
      <td align="center"><a href=https://github.com/lixado/PyBoy-RL>Create your own AI</a><br>
      </td>
      <td align="center"><a href=https://github.com/uiucanh/tetris>Beat world records with AI</a><br>
      </td>
    </tr>
    <tr>
      <td align="center">
        <img src="extras/README/1.gif" width="250">
      </td>
      <td align="center">
        <img src="extras/README/6.gif" width="250">
      </td>
      <td align="center">
        <img src="extras/README/7.gif" width="250">
      </td>
    </tr>
  </tbody>
</table>

Getting Started
===============
The instructions are simple:

```sh
$ pip install pyboy
```

For details, see [installation instructions](https://github.com/Baekalfen/PyBoy/wiki/Installation).

Now you're ready! Either use PyBoy directly from the terminal
```sh
$ pyboy game_rom.gb
```

Or use it in your Python scripts:
```python
from pyboy import PyBoy
pyboy = PyBoy('game_rom.gb')
while pyboy.tick():
    pass
pyboy.stop()
```

<!-- Or using the context manager:
```python
from pyboy import PyBoy
with PyBoy('game_rom.gb') as pyboy:
    while pyboy.tick():
        pass
``` -->


The API
=======

If you are looking to make a bot or AI, then these resources are a good place to start:
 * [PyBoy API Documentation](https://baekalfen.github.io/PyBoy/index.html)
 * [Wiki Pages](https://github.com/Baekalfen/PyBoy/wiki/)
   * [Using PyBoy with Gym](https://github.com/Baekalfen/PyBoy/wiki/Using-PyBoy-with-Gym)
   * [Example: Kirby](https://github.com/Baekalfen/PyBoy/wiki/Example-Kirby)
   * [Example: Tetris](https://github.com/Baekalfen/PyBoy/wiki/Example-Tetris)
   * [Example: Super Mario Land](https://github.com/Baekalfen/PyBoy/wiki/Example-Super-Mario-Land)
   * [Code Examples](https://github.com/Baekalfen/PyBoy/tree/master/extras/examples)
 * [Discord](https://discord.gg/Zrf2nyH)


When the emulator is running, you can easily access [PyBoy's API](https://baekalfen.github.io/PyBoy/index.html):
```python
pyboy.set_emulation_speed(0) # No speed limit
pyboy.button('down')
pyboy.button('a')
pyboy.tick() # Process at least one frame to let the game register the input
value_of_interest = pyboy.memory[0xC345]

pil_image = pyboy.screen.image
pil_image.save('screenshot.png')
```

The [Wiki](https://github.com/Baekalfen/PyBoy/wiki) shows how to interface with PyBoy from your own project.

Performance
===========

Performance is a priority for PyBoy, to make your AI training and scripts as fast as possible.

The easiest way to improve your performance, is to skip rendering of unnecessary frames. If you know your
character takes X frames to move, or the game doesn't take input every frame, you can skip those to potentially triple
your performance. All game logic etc. will still process.

Here is a simple comparison of rendering every frame, rendering every 15th frame, and not rendering any frames (higher is better). See [`pyboy.tick`](https://docs.pyboy.dk/#pyboy.PyBoy.tick) for how it works. Your performance will depend on the game.

<table>
  <tbody>
    <tr>
      <td align="center">
        Full rendering
      </td>
      <td align="center">
        Frame-skip 15
      </td>
      <td align="center">
        No rendering
      </td>
    </tr>
    <tr>
      <td>
      x124 realtime
      </td>
      <td>
      x344 realtime
      </td>
      <td>
      x395 realtime
      </td>
    </tr>
<tr> <!-- Markdown/HTML broken after this -->
<td>

```python
for _ in range(target):
    pyboy.tick()

```
</td>
<td >

```python
for _ in range(target//15):
    pyboy.tick(15, True)

```
</td>
<td >

```python
pyboy.tick(target)

```
</td>
</tr>
  </tbody>
</table>

The Game Boy was originally running at 60 frames per second, so a speed-up of 100x realtime is 6,000 frames per
second. And trivially from the table above, simulating 395 hours of gameplay can be done in 1 hour with no rendering.

It's also recommended to be running multiple instances of PyBoy in parallel. On an 8-core machine, you could potentially
do 3160 hours of gameplay in 1 hour.

Contributing
============
Any contribution is appreciated. The currently known problems are tracked in [the Issues tab](https://github.com/Baekalfen/PyBoy/issues). Feel free to take a swing at any one of them. If you have something original in mind, come and [discuss it on on Discord](https://discord.gg/Zrf2nyH).

[![Discord](https://img.shields.io/discord/584149554132418570?style=for-the-badge&logo=Discord&label=PyBoy)](https://discord.gg/Zrf2nyH)

For the more major features, there are the following that you can give a try. They are also described in more detail in the [project list in the Wiki](https://github.com/Baekalfen/PyBoy/wiki/Student-Projects):
* Hacking games
* Link Cable
* Debugger (VSCode, GDB, terminal or otherwise)
* AI - [use the `api`](https://baekalfen.github.io/PyBoy/index.html) or game wrappers to train a neural network
* Game Wrappers - make wrappers for popular games

If you want to implement something which is not on the list, feel free to do so anyway. If you want to merge it into our repo, then just send a pull request and we will have a look at it.
