Git Product home page Git Product logo

pyboy's Introduction

If you have any questions, or just want to chat, join us on Discord.

Discord

Train RL agents to play Pokemon Red Rewind any game
Play the classics
Create your own AI
Beat world records with AI

Getting Started

The instructions are simple:

$ pip install pyboy

Warning

If you're having issues on Windows, try this instead: pip install pyboy==2.0.0 pillow

PyPI (who maintains pip install) has stopped processing support tickets, and we've been unable to deploy a fix for over a month now. Follow this thread for status: pypi/support#3757

If you're able to get in contact with PyPI, then please help us get this resolved!

For details, see installation instructions.

Now you're ready! Either use PyBoy directly from the terminal

$ pyboy game_rom.gb

Or use it in your Python scripts:

from pyboy import PyBoy
pyboy = PyBoy('game_rom.gb')
while pyboy.tick():
    pass
pyboy.stop()

The API

If you are looking to make a bot or AI, then these resources are a good place to start:

When the emulator is running, you can easily access PyBoy's API:

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 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 for how it works. Your performance will depend on the game.

Full rendering Frame-skip 15 No rendering
x124 realtime x344 realtime x395 realtime
for _ in range(target):
    pyboy.tick()
for _ in range(target//15):
    pyboy.tick(15, True)
pyboy.tick(target)

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. 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.

Discord

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:

  • Hacking games
  • Link Cable
  • Debugger (VSCode, GDB, terminal or otherwise)
  • AI - use the api 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.

pyboy's People

Contributors

baekalfen avatar cmacrae avatar eugeneyjy avatar fieoner avatar fkatenbrink avatar grungi-ankhfire avatar jardiacaj avatar jonathanmurray avatar kr1tzy avatar krs013 avatar littlenyima avatar maciekbaron avatar marginalhours avatar mathisfederico avatar naclander avatar nicoeps avatar nicolefaye avatar owen-crook avatar posixpascal avatar pwhiddy avatar ramon-7274 avatar rkaufusi avatar sofianedjerbi avatar stillinbeta avatar thatguy11325 avatar thomafred avatar troelsy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyboy's Issues

Ability to compute frames as fast as possible

Me and @Fieoner are working on a bot and we are using your (awesome) emulator in headless mode to make it work. However, the frames are limited so that it runs in real time, which makes sense for direct standard use. For computing frames, however, it makes more sense to run it as fast as possible, so we would like to know if there's any option to make this happen or if it can be implemented.

We are happy to help.

Thanks in advance!

Save cartridge RAM

For cartridges, which has a built-in battery, we should same the contents of the external RAM.

Create a settings window

It would be nice to have a settings window to change keybindings, ROM directory, screen recording settings etc.

Failing to build pillow

I tried following the instructions for Ubuntu. I ran pip install -r requirements.txt and it failed to build pillow

Make a screen recorder

It would be useful to implement a feature in a GameWindow, which allows to record the game frame-by-frame. Contrary to regular screen-capture, this would allow perfectly timed frame-rates.

The output formats would preferably be GIF and MP4.

Infinite time counter in Super Mario Land

The timer starts at 465 and wraps around after hitting 460. This means the player cannot get past first level, as it goes into an infinite loop while counting down the seconds left of the game.

sendInput([WindowEvent.LoadState]) does nothing

Hi, im trying to make an IA for Motocross Maniacs but I need to load state in order to dont spend hours between bootrom loadings and such, also the rom crashes if the game timesup or loses the race so I need this to work as I intend. I was modifying tetris_bot.py in order to see if I can load rom states but it seems either this isn't implemented or I'm not using the correct method.

Im trying pyboy.sendInput([WindowEvent.LoadState]) but this does nothing.

Pokemon Blue infinite loop on white-out

The game is not put into an exact lock, as the check for PC-change is not triggered. It is likely a subroutine, which does not get the correct flag on a jump.

Run SDL2 in separate thread

For some games, nearly 50% of the CPU time goes into rendering the screen. This could easily be moved to another thread, to better utilize the available hardware.

Cython instructions for Raspberry Pi

To start off, it doesn't matter which model of RPi, or under which circumstances. It might require overclocking, multithreading and/or use of OpenGL.

Add terminal "Window" for Blargg's test-ROMs

Blargg's test-ROMs supposedly writes the text on the screen to the Link Cable as well as the screen. For the tests, it would be useful to not start the (SDL) window, but simply have it print out in the terminal.

This could also be used for automatic testing, as the output could check where errors have occurred.

Pokemon Gold error on New Game

When starting a new game in Pokemon Gold, the game gives the error message "No windows available for popping." and locks up.

Lazy imports for optional features (and faster starts)

Since some packages (OpenGL, imageio) are only needed for certain features like video recording and experimental GameWindows, it would be nice if we could lazily import either those packages or the modules that import them. That way, someone could try the code without having to install all the dependencies (e.g., my brother had a hard time trying the code because gcc fails to compile Pillow on macOS). It would also speed up the startup, since there would be less work to do before the game can launch.

One place this is a problem is the GameWindows. Since GameWindow/__init__.py imports all of the GameWindows to its namespace, the references to that package in main.py trigger the imports even though it's trying to import just one of the GameWindows. While having an empty __init__.py and importing from the submodules would fix that, I think it would fragment the code too much (and already it's a bit interdependent that main.py has to check the names of the GameWindows instead of keeping that functionality in the module). So, I thought I'd open this up as an issue to see if there were any ideas about how to handle this in general and whether it's something to pursue yet.

About TileViews

First, thanks for answering me before. Now, this is more a doubt than an issue... When I use the tileview I get two windows, one for the "current map without the player" and other for the HUD (the remaining time bar, power, and such). At the moment I can retreive the "on screen" sprites but I cant get the sprites in the tileviews and I need to get the sprites near the racer (in the tileview but not on screen). How should I proceed?
This is what I see:
https://i.imgur.com/3yrvuSg.png

Time in Pokemon Gold goes too fast

It might be RTC and save/load state related. The clock inside the game counts around 1 hour pr. second compared to the real world. This soft-locks the game, as it's not possible to end the phone call from the NPC Wade before he is triggered to call again.

Make subpage for installing and using optional features

We are beginning to have several optional features: GameWindow, ScreenRecorder, BotSupport and likely more to come.

We should make one or more subpages, which describes these things in detail. Both how to use them, and how to install them.

It might be a Wiki page, or subpages of .md.

First on the list, is the new dependencies in #59, which are only required for the optional ScreenRecorder.

Decouple GameWindow import from `main.py`

Currently, the GameWindow is imported from outside of the PyBoy module. It would de preferable, if it was selected with a flag through sys.argv, but the internals of PyBoy handled it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.