Co-operation: A.L.E. & Mathematica

As I stated in the previous post, we decided to run Atari emulator simulations in Wolfram Mathematica. But there is a catch — Arcade Learning Evironment only provides interface through a C++ library. Here is a way how to deal with it.

MathLink

Mathematica actually provides a way how to launch programs written in other languages. MathLink is a set of libraries which allows us to call external functions from within the Mathematica environment. Here is a very detailed tutorial on how to use it. I will now focus only on connecting A.L.E. and MathLink.

In order to save you job a little, you can download an archive with prepared sample code. All the credits for the code inside this package goes to Jan Drchal, our mentor. You just have to get few things done to get this to work:

  1. Download Arcade Learning Environment from the official webpage and compile it with SDL [for Windows - follow our instructions].
  2. Copy libale.so from A.L.E. folder to ALElink folder [for Windows - use libale.dll].
  3. Locate Mathematica library folder, on Unix systems it is probably a path like this: /usr/local/Wolfram/Mathematica/[version]/SystemFiles/Libraries/[platform-name] and add it to your system $PATH variable.
  4. Open Makefile and if needed, change a path to DeveloperKit and CompilerAdditions folder stated on the first lines (it depends on your Mathematica installation folder).
  5. On Windows, you would have to make a few more changes — rename libale.so to libale.lib and change a path to your default compiler.
  6. Now you should be able to run the make command.

After successful compilation, a binary file called alelink should be created in this folder. We will now use this program in our Mathematica code:

link = Install[“path-to-alelink-folder/alelink”];

This is it. If this is not working for you, you can try to get around this by using the port connection mode:

  1. Run the alelink binary from the command line: ./alelink
  2. After the prompt Create link, type any port number like 74 [for Windows, it is an arbitrary word]
  3. Keep it running and in Mathematica, use this syntax:
link = Install[“port-number", LinkMode -> Connect]

What can we now do with it? You can find this out by typing:

LinkPatterns[link]

You can find implementation of all these functions in sources within our archive file. In the end, here is an example how to load an Atari ROM file, get a list of available actions, display a screen image and apply the chosen action:

ALEInit[“path-to-roms-folder/rom-filename”];
actions = ALEGetLegalActions[]
act = actions[[1]];
Image[ALEGetScreenRGB[]/255.]
ALEAct[act];
Show your support

Clapping shows how much you appreciated Atari ANN’s story.