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.
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:
- Download Arcade Learning Environment from the official webpage and compile it with SDL [for Windows - follow our instructions].
- Copy libale.so from A.L.E. folder to ALElink folder [for Windows - use libale.dll].
- 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.
- 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).
- 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.
- 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:
- Run the alelink binary from the command line: ./alelink
- After the prompt Create link, type any port number like 74 [for Windows, it is an arbitrary word]
- 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:
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:
actions = ALEGetLegalActions
act = actions[];