How the Breakout network works

How a strategy for catching a ball becomes numbers in a small network, with no training. This page covers the best attempt we made for this game, a handwritten network, which averages 514.1 points. The positions and values below come from its real weights.

The game

This is MinAtar Breakout, a small version of the classic game on a 10x10 grid. A paddle on the bottom row moves left or right to keep a ball in play, and the ball breaks bricks. Moves sometimes repeat at random, 10% of the time. Rows are numbered from 0 at the top to 9 at the bottom, so the paddle is on row 9, and the ball is caught when it reaches row 8, just above it.

The network has two hidden layers of 32 units each. That size was fixed in advance so that PPO, a standard reinforcement learning method, could train exactly the same network from random weights, for a fair comparison with the handwritten one. The handwritten design ends up using only part of it. It's also the size the original article used for Breakout.

The problem the network has to solve

To catch the ball, the network needs two things it isn't given directly: which way the ball is travelling, and where it will land.

What makes this possible is how the input works. The ball is in exactly one cell, so exactly one of its 100 input numbers is 1. That means a single unit's weights on those inputs act as a lookup table: whichever cell the ball is in, the unit reads out the weight stored for that cell. There's no need for many units per position.

The strategy in plain words

  1. Work out the direction by comparing the ball's cell with its trail, the cell it just left.
  2. Look up the catch window. The ball moves diagonally, one cell per step. Once it reaches row 8, its next step would take it into the paddle's row, and the paddle saves it if it's in either of two columns: the one right under the ball, or the one the ball is about to move into. For example, a ball in column 4 moving down and to the right is saved by a paddle in column 4 or column 5. Those two columns are the catch window. Wherever the ball is now, the network looks up which two columns they'll be when it gets down to row 8, allowing for bounces off the side walls on the way.
  3. Move into the window, then wait. The paddle stops at the nearer of the two columns, so a random repeat that carries it one column further still leaves it in the other one. A waiting paddle's last move is "stay", so a repeat can't knock it out of position.
  4. While the ball rises, move early towards where it would land if it turned at the lowest brick row.
  5. At contact in the middle columns, tie two safe moves, so the bounce is random and the ball doesn't settle into a loop that misses bricks.

The network ignores the bricks entirely: of its weights read that channel. Everything it does is about the ball.

The layers

Most of layer 1 is the catch window, checked four times: once for each direction the ball can travel (right and down, right and up, left and down, left and up), because where the ball reaches row 8 depends on its direction. For a ball that's rising, the window is a forecast of where it will come down after it turns back. Each check uses two units. One fires when the paddle is left of the window, meaning it should move right. The other fires unless the paddle is right of the window, so when it's off, the paddle should move left. When the first is off and the second is on, the paddle is already inside the window. Layer 2 combines these with the ball's actual direction, so only the matching check affects the move.

One move, followed through the network

Pick a position from a real game. All of the units listed are firing, and any unit not listed is off. Some facts only matter in certain situations, like the units for a direction the ball isn't going. The gates in layer 2 simply ignore those.

Board, row 0 at the top

  • paddle
  • ball
  • trail
  • brick

Layer 1: facts about the position

Layer 2: combine them into a decision

Output

Looking at the lookup tables

This is what two first-layer units actually store. Each cell shows the columns of the two-column "catch window" if the ball is in that cell, for one direction of travel. One unit holds the window's left-hand column, and the other its right-hand column. Each unit subtracts the paddle's column and checks the sign, which tells the paddle which way to go. Hover or tap for details.

Show this table as text

Why a two-column window? A ball on row 8 survives if the paddle ends on the ball's column or the one it's moving to. Stopping at the nearer edge means a random repeat that carries the paddle one column further still lands on the other safe column. Attempt 3 added this after deaths caused by exactly that overshoot.

Direction, by adding two tables

The input never says which way the ball is going. It only shows the ball's cell and its trail, the cell it was in a step earlier. One unit works the direction out. Like every unit, it adds up a weight for each input that's switched on, and here exactly two are on: one ball cell and one trail cell. So its total is the ball's weight for its column plus the trail's weight for its column. The weights are chosen so that the total is +5 when the ball is moving right and −5 when it's moving left. That even holds at a wall, where the ball stays in the same column for one step, and simply subtracting the two columns would give 0.

Click a column in each row to place the ball and its trail, and follow the arithmetic.

How the design got here

Only attempt 1 was written without ever running the network.

AttemptMeanWhat changedWhy
1, blind137.4Original designNever run before scoring
2370.7Move on the step right after a paddle bounceThe paddle ended up behind a ball moving away
3435.6Stop at the nearer column of the catch windowOvershoot from a repeated move at contact
4514.1Near a wall, pick the bounce that shortens the next tripFull-width shots from near a wall

What this does and doesn't show