GithubHelp home page GithubHelp logo

ntasfi / pygame-learning-environment Goto Github PK

View Code? Open in Web Editor NEW
996.0 39.0 232.0 8.06 MB

PyGame Learning Environment (PLE) -- Reinforcement Learning Environment in Python.

License: MIT License

Python 99.06% Dockerfile 0.94%
reinforcement-learning game artificial-intelligence agent machine-learning pygame python deep-reinforcement-learning ai research

pygame-learning-environment's Introduction

PyGame-Learning-Environment

Games

PyGame Learning Environment (PLE) is a learning environment, mimicking the Arcade Learning Environment interface, allowing a quick start to Reinforcement Learning in Python. The goal of PLE is allow practitioners to focus design of models and experiments instead of environment design.

PLE hopes to eventually build an expansive library of games.

Accepting PRs for games.

Documentation

Docs for the project can be found here. They are currently WIP.

Games

Available games can be found in the docs.

Getting started

A PLE instance requires a game exposing a set of control methods. To see the required methods look at ple/games/base.py.

Here's an example of importing Pong from the games library within PLE:

from ple.games.pong import Pong

game = Pong()

Next we configure and initialize PLE:

from ple import PLE

p = PLE(game, fps=30, display_screen=True, force_fps=False)
p.init()

The options above instruct PLE to display the game screen, with display_screen, while allowing PyGame to select the appropriate delay timing between frames to ensure 30fps with force_fps.

You are free to use any agent with the PLE. Below we create a fictional agent and grab the valid actions:

myAgent = MyAgent(p.getActionSet())

We can now have our agent, with the help of PLE, interact with the game over a certain number of frames:

nb_frames = 1000
reward = 0.0

for f in range(nb_frames):
	if p.game_over(): #check if the game is over
		p.reset_game()

	obs = p.getScreenRGB()
	action = myAgent.pickAction(reward, obs)
	reward = p.act(action)

Just like that we have our agent interacting with our game environment.

Installation

PLE requires the following dependencies:

  • numpy
  • pygame
  • pillow

Clone the repo and install with pip.

git clone https://github.com/ntasfi/PyGame-Learning-Environment.git
cd PyGame-Learning-Environment/
pip install -e .

Headless Usage

Set the following in your code before usage:

os.putenv('SDL_VIDEODRIVER', 'fbcon')
os.environ["SDL_VIDEODRIVER"] = "dummy"

Thanks to @wooridle.

Updating

cd into the PyGame-Learning-Environment directory and run the following:

git pull

Todos

  • Documentation is currently in progress.
  • Tests
  • Parallel Learning (One agent, many game copies)
  • Add games
  • Generalize the library (eg. add Pyglet support)

Citing PLE

If PLE has helped your research please cite it in your publications. Example BibTeX entry:

@misc{tasfi2016PLE,
  author = {Tasfi, Norman},
  title = {PyGame Learning Environment},
  year = {2016},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/ntasfi/PyGame-Learning-Environment}}
}

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.