A simple Breakout clone for fun and reinforcement learning on internal game state.
- Interactive gameplay with keyboard control (← and →).
- Automatic gameplay with heuristic control.
- Automatic gameplay with custom control.
- CommonRLInterface for learning with different state representations.
using Pkg
Pkg.add("Breakout")Breakout is a classic arcade game where the player controls a paddle to bounce a ball and break all the bricks on the screen. The objective is to clear all bricks without letting the ball fall past the paddle.
This version features 6 rows of 14 bricks each, with point values assigned by color:
- Red – 10 points
- Orange – 8 points
- Yellow – 6 points
- Green – 4 points
- Blue – 2 points
- Cyan – 1 point
The bricks sum to 434 points, and players earn a 66-point bonus for clearing all 84 bricks.
using Breakout
breakout() # Normal speed (default: 1.0)
breakout(speed=0.5) # Slower
breakout(speed=2.0) # Faster
breakout(speed=nothing) # Maximum speedusing Breakout
breakout(Breakout.heuristic_action, speed=nothing)To create a custom controller, check out the controller implementations in the control/ folder.
breakout(control_func=keyboard_action;autorestart=true, speed=1.0, max_steps=nothing)- Launch the gameBreakoutEnv(; frame_skip=4, max_steps=20000, representation=:full)- Create RL environment
The environment supports multiple state representations for reinforcement learning:
:minimal(2 features):paddle_x, ball_xfor basic ball following:brickless(5 features):paddle_x, ball_x, ball_y, ball_vx, ball_vyfor advanced ball following without brick complexity:full(89 features): Full internal game state including one-hot encoded brick positions (default):pixels(160 x 210 features): Grayscale pixel values of screenshot as flattened vector
import CommonRLInterface as RL
# Environment with full game representation
env = BreakoutEnv()
state = RL.observe(env) # Returns 89-element vector
# Environment with minimal representation
env = BreakoutEnv(:minimal)
state = RL.observe(env) # Returns 2-element vectorThe game state is a mutable struct containing:
score::Int- Current scorepaddle_cx::Float64- Paddle center x-coordinateball_cx::Float64- Ball center x-coordinateball_vx::Float64- Ball x-velocityball_cy::Float64- Ball center y-coordinateball_vy::Float64- Ball y-velocitybricks::Vector- Array of remaining brick objects
The environment supports both discrete and continuous action spaces:
Discrete actions (default):
-1: Move paddle left0: Keep paddle stationary1: Move paddle right
Continuous actions:
- Range
(-1, 1): Continuous paddle movement speed
# Discrete actions (default)
env = BreakoutEnv(discrete=true)
actions = RL.actions(env) # Returns [-1, 0, 1]
# Continuous actions
env = BreakoutEnv(discrete=false)
actions = RL.actions(env) # Returns (-1, 1)MIT License
