Skip to content

SquiRtLAn agent that learns the walk to Oak’s lab.

Trains an agent to play Pokémon Blue from the screen, through PyBoy and PyTorch.

SquiRtL trains an agent to play Pokémon Blue from the screen alone. A deep Q-network reads the frames the PyBoy emulator draws, presses one of the Game Boy's buttons each step, and learns from a reward read out of the game's memory, until Blue walks from his bedroom to Oak's lab and chooses his starter. Each part of the story below plays on a model of the game's first rooms in the page, so it runs with no emulator and no ROM.

The Reward ​

Every step of an episode pays a little for each position Blue has not reached before and far more for each milestone on the way to the starter, which ends the episode.

Return so far0.00000Step 0 of 181This press paidBlue wakes0.00000Each term so farNew positions0 × 0.000250.00000Milestones0 of 30.00000The starterNot yet0.00000
The players, on every widget
  • The agent
  • Random presses
What one press pays, on every widget
  • New positions+0.00025
  • Milestones+0.10000
  • The starter+0.35000
  • Already reached0.00000

What the Network Sees ​

The network never reads where Blue stands, reading instead the last four frames of the screen shrunk to gray, the squares he has reached around him, and a flag for each moment of the opening from Oak appearing to the Pokédex.

What a player seesStep 0 of 181
Frames4 × 72 × 80, newest last · 23,040 bytes
Grid48 × 48, Blue at the center · 2,304 bytes
Flags7, in the order the opening sets them · 7 bytes
Oak appeared0Followed Oak0Oak asked0Got the starter0
Past the goal, paying nothing
Battled the rival0Got Oak’s parcel0Got the Pokédex0

Learning in the Page ​

Training spreads value back from where an episode pays, square by square, so each walk from Blue's door after more episodes spends fewer presses at random and reaches Pallet Town's north edge, where Oak appears, sooner. Here a small table of values, trained in the page over a model of Pallet Town, stands in for the deep Q-network, which trains only through squirtl train.

0501001502000 presses
  • The coin’s presses
  • The table’s
  • Where a walk stops

Against Random Presses ​

Each run is evaluated beside random presses under the same seeds, counting how many of each player's episodes reach the starter and how many steps each takes to get there. Here the agent's part goes to a player that walks the shortest way to the starter and presses at random as often as an evaluation does, so the race shows the shape of an evaluation rather than the result of a trained run.

Episodes that have reached the starter
Reached itSteps to itThe agent0 of 3093Random presses0 of 306,498