https://github.com/ssarcandy/breakout-env
🎮 A configurable Breakout environment for reinforcement learning
https://github.com/ssarcandy/breakout-env
game python3 reinforcement-learning
Last synced: 11 months ago
JSON representation
🎮 A configurable Breakout environment for reinforcement learning
- Host: GitHub
- URL: https://github.com/ssarcandy/breakout-env
- Owner: SSARCandy
- License: mit
- Created: 2018-02-03T16:45:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-20T16:49:30.000Z (over 8 years ago)
- Last Synced: 2025-04-17T16:55:20.842Z (about 1 year ago)
- Topics: game, python3, reinforcement-learning
- Language: Python
- Homepage:
- Size: 115 KB
- Stars: 11
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Breakout-env
A [gym](https://github.com/openai/gym/blob/master/gym/envs/atari/atari_env.py) like Breakout environment but with more configurable options.




## Configurable Options
| Option | Description | Type | Range | Default Value |
|-----------------|---------------------------------|---------------|------------|----------------------------------|
| `max_step` | Max step per episode. | `int` | 0 ~ Inf | `10000` |
| `lifes` | Lifes per episode. | `int` | 0 ~ 9 | `5` |
| `ball_pos` | Ball's initial position. [y, x] | `[int, int]` | -Inf ~ Inf | `[100, 40]` |
| `ball_speed` | Ball's initial velocity. [y, x] | `[int, int]` | -Inf ~ Inf | `[4, 2]` |
| `ball_color` | Ball's color. (gray scale) | `int` | 0 ~ 255 | `143` |
| `ball_size` | Ball's size. [h, w] | `[int, int]` | 1 ~ Inf | `[5, 2]` |
| `paddle_width` | Paddle's width. | `int` | 1 ~ 100 | `15` |
| `paddle_color` | Paddle's color. (gray scale) | `int` | 0 ~ 255 | `143` |
| `paddle_speed` | Paddle's moving speed. | `int` | 1 ~ Inf | `3` |
| `bricks_rows` | Number of bricks row. | `int` | 0 ~ Inf | `6` |
| `bricks_color` | Row color of bricks.\* | list of `int` | 0 ~ 255 | `[200, 180, 160, 140, 120, 100]` |
| `bricks_reward` | The reward of bricks.\* | list of `int` | -Inf ~ Inf | `[6, 5, 4, 3, 2, 1]` |
\* `len(bricks_color)` and `len(bricks_color)` should equal to `bricks_rows`.
## Installation
Install from PyPI:
```sh
$ pip install breakout_env
```
Install from master branch
```sh
$ pip install git+https://github.com/SSARCandy/breakout-env.git@master
```
## Example
### Interact with environment
```py
from breakout_env import Breakout
# Create Breakout environment with some options.
env = Breakout({
'lifes': 7,
'paddle_width': 30,
'paddle_speed': 5
})
for ep in range(2):
obs = env.reset()
while True:
# Select random action
action = random.randint(0, env.actions - 1)
obs, reward, done, _ = env.step(action)
print('Episode: {}, Reward: {}, Done: {}'.format(ep, reward, done))
if done:
break
```
### Visualize the game
The observation retuned by env is a numpy 2D array, it can be easily visualize using some library like [OpenCV](https://opencv.org/) or [matplotlib](https://matplotlib.org/).
```py
import cv2
from breakout_env import Breakout
env = Breakout()
env.reset()
while True:
# Select random action
action = random.randint(0, env.actions - 1)
obs, _, _, _ = env.step(action)
# Show the observation using OpenCV
cv2.imshow('obs', obs)
cv2.waitKey(1)
if done:
break
```
## Develop Requirement
- python3
- numpy
## Reference
- [OpenAI Gym](https://github.com/openai/gym/blob/master/gym/envs/atari/atari_env.py)
- [ALE interface - Breakout](https://github.com/openai/atari-py/blob/master/atari_py/ale_interface/src/games/supported/Breakout.cpp)
- [BreakoutNoFrameskip-v4 video](https://youtu.be/o72FS5eqPNs)