reverse_engineer

Personal website of Aurélien Vermylen

The 2048 game

A while ago, I got temporarily addicted to 2048. So much, that I even managed to get a 8192 tile (as you can see from my highscore below).

yeeha

The game is so simple conceptually, that I wanted to try to code an artificial intelligence that could win the game. I quickly noticed, however, that this guy, already made a great (I think the best existing) artificial intelligence for the 2048 game. However, it’s a C++ program that must be compiled on your PC and then linked to the browser with some browser plugin in order to see it play the game live.

So I decided to re-code it in javascript, so that it would run in the browser. Since I knew that the javascript interpreters (which are really full-fledged Just-in-time compilers now) had become very powerful, I thought I would manage to develop an AI which would be slower than the C++ version, but still be interesting to watch. There again, I found a better way online to do this than to re-code the AI manually (ain’t the web great ^^): emscripten.

This great C/C++/Fortran to javascript compiler coded mostly by this guy of Mozilla, made the work almost instant. I just installed emscripten and compiled the C++ code to javascript, wrote some boilerplate code and implemented it in such a way that it would use web workers (for multi-threading), and now you can watch this great AI reach the 32768 tile one third of the times!

Visit the AI site here.

Thanks to the great work of the javascript engineers of V8, SpiderMonkey and Chakra, it runs very smoothly in Chrome, Firefox and IE10+ now!