Git Product home page Git Product logo

gym-chrome-dino's Introduction

gym-chrome-dino

An OpenAI Gym environment for Chrome Dino / T-Rex Runner Game

screenshot

This environment utilizes a forked version of Chrome Dino, also called T-Rex Runner, extracted from chromium offline error page. See here.

Installation

You can install gym-chrome-dino from PyPI by either

pip install gym-chrome-dino

or

git clone https://github.com/elvisyjlin/gym-chrome-dino.git
cd gym-chrome-dino
pip install -e .

Usage

You can get started as follows:

import gym
import gym_chrome_dino
env = gym.make('ChromeDino-v0')

To create a headless (without opening browser) environment

env = gym.make('ChromeDinoNoBrowser-v0')

Observations, Actions and Rewards

  • The observation is a RGB numpy array with shape of (150, 600, 3).
  • The available actions are 0: do nothing, 1: jump, and 2: duck.
  • A positive reward 0.01 is given when the dinosaur is alive; a negative penalty -1.0 is given when the dinosaur hits an obstable, which might be a cactus or a bird.

For the DeepMind DQN recipe, where we give 4-stacked resized grayscaled frames (80, 160, 4) to the agent, we provide a wrapping method make_dino(). It also comes with a timer wrapper, which reports the interval between env.step().

from gym_chrome_dino.wrappers import make_dino
env = make_dino(env, timer=True, frame_stack=True)

DinoGame

An instance of DinoGame is created when the environment is made. There are some useful methods for fine control of the training environment. The DineGame can be accessed as follows:

env.unwrapped.game

DinoGame provides a get_score() method to get the score of current game.

score = env.unwrapped.game.get_score()

By default, the acceleration of the game is set to zero. If you want to restore the original acceleration value, please do set_acceleration(True). On the other hand, set_acceleration(False) sets the value to zero.

env.unwrapped.game.set_acceleration(True)

Example

Here is a simple example to use gym-chrome-dino.

import gym
import gym_chrome_dino
from gym_chrome_dino.utils.wrappers import make_dino
env = gym.make('ChromeDino-v0')
env = make_dino(env, timer=True, frame_stack=True)
done = True
while True:
    if done:
        env.reset()
    action = env.action_space.sample()
    observation, reward, done, info = env.step(action)

WebDriver

gym-chrome-dino runs the game on chromedriver via selenium because it is a proper way to monitor and to play Chrome Dino. As a result, the latest chromedriver executable file will be downloaded to the current working directory where your program is.

gym-chrome-dino's People

Contributors

elvisyjlin 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

Watchers

 avatar  avatar

gym-chrome-dino's Issues

How do I install this package in google colab?

This package does instasll completely fine in my normal python environment. But, when I tried to install this package in colab the installation go stuck for 37 minutes until I cancelled it, I tried again but it always got stuck.

So, is there any solution to this? Am I missing a dependency?

Crouch action does not work properly

I looked into the game file, it says 2 acts for crouch movement. But when I create the environment, it does not crouch - just stand still. Also, 0 make the dino jump instead of just running.

env = gym.make('ChromeDino-v0')

env = make_dino(env, timer=True, frame_stack=True)
state = env.reset()
done = False
score = 0
while True:
#     action = np.random.choice(np.arange(1,4))
    action = 2
    state, reward, done, _ = env.step(action)
    score += reward
    if done:
        state = env.reset()

Returns no state but memory location.

As
env = gym.make('CartPole-v0').unwrapped
env.reset()

Returns
array([ 0.0286644 , -0.0473783 , -0.01396534, 0.03493663])

Your agent returns memory location, why that?

Fails to run on Colab

It fails to run on Colab with the following error. Could someone help me out here?


WebDriverException Traceback (most recent call last)
in ()
----> 1 env = gym.make('ChromeDinoNoBrowser-v0')
2 #env = make_dino(env, timer=True, frame_stack=True)

7 frames
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
109 raise WebDriverException(
110 'Service %s unexpectedly exited. Status code was: %s'
--> 111 % (self.path, return_code)
112 )
113

WebDriverException: Message: Service ./chromedriver unexpectedly exited. Status code was: -6

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.