Playing Tetris with Genetic Algorithms

Learn what ALE is and how it can be incorporated into our framework.

What is Arcade Learning Environment (ALE)?

The Arcade Learning Environment (ALE) is a framework designed to allow programmers to easily develop AI agents for Atari 2600 games. The ALE was originally written in C++ with interfaces to Python, Java, and other languages. The ALE supports numerous Atari ROMs, including popular titles like Tetris, Space Invaders, and Pac-Man.

ALEx stands for Arcade Learning Environment in Elixir. ALEx uses NIFs to create an Elixir wrapper around the ALE to allow Elixir programmers to develop agents for the ALE. ALEx offers all of the same functionality as the ALE, conveniently packaged in an Elixir library.

In this lesson, we’ll use ALEx to evolve agents to play Tetris. The agents we design in this chapter will be naive; the purpose of this project is simply to see how genetic algorithms can integrate with visual tools to produce real results.

Installing and compiling ALEx

The ALE, and subsequently ALEx, requires libsdl1.25 and cmake. If you don’t have either, install them like this:

$ sudo apt-get install libsdl1.2-dev libsdl-gfx1.2-dev \
    libsdl-image1.2-dev cmake

Next, add ALEx to your dependencies in mix.exs:

Get hands-on with 1400+ tech skills courses.