GithubHelp home page GithubHelp logo

chaoxel / pyboyenv Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 1.0 10.51 MB

Turn any gameboy game into a reinforcement learning environment.

License: MIT License

Python 100.00%
reinforcement-learning environment reinforcement-learning-environments

pyboyenv's Introduction

PyBoyEnv

This package allow you to turn any gameboy memory event into a reinforcement learning environment rule.


(generated with test.py)

Installation

Install the dependencies:

pip install -r requirements.txt

Install the package with pip:

pip install ./

Quickstart

import gym
import pyboyenv

# Create the environment
env = gym.make('Pyboy-v0', game=<FILE>)

# Add rules
env.set_reward_rule(ADDRESS, TYPE, VALUE, LABEL)

# Available rules:
# - increase: add VALUE if the memory at the address ADDRESS increases
# - decrease: add VALUE if the memory at the address ADDRESS decreases
# - smaller X: add VALUE if the memory at the address ADDRESS is smaller than X
# - bigger X: add VALUE if the memory at the address ADDRESS is bigger than X
# - equals X: add VALUE if the memory at the address ADDRESS equals X
# - in X1,..,XN: add VALUE if the memory at the address ADDRESS is equal to X1 or ... or XN

# Useful values
cumul = 0 # Sum of rewards 
done = False # Is the game done ?
action = 16 # Initial action (action list available below, 16=nothing)

# Game loop
while not done:
    # State = Window screen
    state, reward, done, info = env.step(action)
    cumul += reward
    action = Agent.get_action(state, cumul, reward) # Next action
    # Print infos
    for i in info:
        print(f"{i[0]}: {i[1]}")

Actions

  • 0: WindowEvent.PRESS_ARROW_UP
  • 1: WindowEvent.PRESS_ARROW_DOWN
  • 2: WindowEvent.PRESS_ARROW_LEFT
  • 3: WindowEvent.PRESS_ARROW_RIGHT
  • 4: WindowEvent.PRESS_BUTTON_A
  • 5: WindowEvent.PRESS_BUTTON_B
  • 6: WindowEvent.PRESS_BUTTON_SELECT
  • 7: WindowEvent.PRESS_BUTTON_START
  • 8: WindowEvent.RELEASE_ARROW_UP
  • 9: WindowEvent.RELEASE_ARROW_DOWN
  • 10: WindowEvent.RELEASE_ARROW_LEFT
  • 11: WindowEvent.RELEASE_ARROW_RIGHT
  • 12: WindowEvent.RELEASE_BUTTON_A
  • 13: WindowEvent.RELEASE_BUTTON_B
  • 14: WindowEvent.RELEASE_BUTTON_SELECT
  • 15: WindowEvent.RELEASE_BUTTON_START
  • 16: WindowEvent.PASS

pyboyenv's People

Contributors

sofianedjerbi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

azertop

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.