GithubHelp home page GithubHelp logo

openaigaming's Introduction

OpenAI Gaming

Play games in the OpenAI gym using the keyboard.

Example invocation: python3 play.py CartPole-v1 --delay=50

It is also possible to record a game (using the -o command-line switch). This can be used for apprenticeship learning.

Mapping format

For every game, the computer must know a mapping from keyboard keys to actions. Mappings can be specified as JSON files. To create a mapping for a game with id x, create the JSON file keymaps/x.json.

Keys of the mapping can be:

  • "default"
  • any alphanumeric character
  • the name of any pynput.keyboard.Key object, like "left", "right", "space"

Values of the mapping can be:

  • a number
  • an array of floats (if actions are multi-dimensional)
  • "next" or "prev": If actions are discrete, they are numbered from 0 to n-1. If the action performed in the previous instant was x, "next" will perform the action (x+1)%n and "prev" will perform the action (x-1)%n.
  • "same": Perform the same action which was performed in the last instant.
  • "random": Randomly sample an action from the action space.

When no valid key is pressed, the action performed is the one corresponding to "default". If "default" action is not specified, it is taken as "random".

For discrete-action games, unmapped keys from 0 to 9 are mapped to corresponding actions of the same number. This can be a good way to explore actions in a game and devise an appropriate keymap for it.

Recording a game

A game will be recorded in several files. If the environment is queried t times using env.step, then:

  • states.npy contains the t+1 states seen in the game.
  • actions.npy contains the t actions selected by the player.
  • rewards.npy contains the t rewards obtained by the player.
  • metadata.json contains shapes and data types of states, actions and rewards and miscellaneous data like total playing time, total score, whether game was interrupted, etc.

All these files will be created in a directory whose path is specified in the -o command-line switch.

List all games

To list the games supported by the OpenAI gym, run this:

import gym.envs
for game_name in gym.envs.registry.env_specs.keys():
    print(game_name)

openaigaming's People

Contributors

sharmaeklavya2 avatar

Stargazers

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

Watchers

 avatar  avatar

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.