Skip to main content

Chrome Dino in OpenAI Gym

Project description

# gym-chrome-dino

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

This environment utilizes
[a forked version](https://github.com/elvisyjlin/t-rex-runner)
of _Chrome Dino_, also called _T-Rex Runner_,
extracted from chromium offline error page.
See [here](https://github.com/wayou/t-rex-runner).


## Installation

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

```bash
pip install gym-chrome-dino
```

or

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


## Usage

You can get started as follows:

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

To create a headless (without opening browser) environment

```python
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()`.

```python
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:

```python
env.unwrapped.game
```

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

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

```python
env.unwrapped.game.set_acceleration(True)
```


## Example

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

```python
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](http://chromedriver.chromium.org) 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gym_chrome_dino-0.0.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

gym_chrome_dino-0.0.3-py2.py3-none-any.whl (13.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gym_chrome_dino-0.0.3.tar.gz.

File metadata

  • Download URL: gym_chrome_dino-0.0.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/20.7.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for gym_chrome_dino-0.0.3.tar.gz
Algorithm Hash digest
SHA256 44a6861d7cc7afa7086cc67a149b76f036983aac0295a6a087113731d0e1ebda
MD5 cece94db8847e9af585a5ae264278ed5
BLAKE2b-256 510ebc1d5173d66a090d2c774cda4759ac7bba5807c5e9bbb38801e61eeb7627

See more details on using hashes here.

File details

Details for the file gym_chrome_dino-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: gym_chrome_dino-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/20.7.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for gym_chrome_dino-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fac655990d39a16bfafc59958748bfa1a62a637569827036b34d8ac6a0f70244
MD5 a6e19487eef90786b14f84214e7f45f5
BLAKE2b-256 aae141accd699e9e6a1dc3f44c176696baf07272e17e7d0eabc4cb8149648ba5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page