I have to confess that I am more than a little addicted to 2048, the internet game created by Gabriele Cirulli (which was based on 1024 by Veewo Studio, itself conceptually similar to Threes by Asher Vollmer). The concept is very simple: starting with two randomly positioned tiles (each with a 90% chance of being a 2, and a 10% chance of being a 4), you slide all of the tiles on a 4x4 grid in a particular direction and when two tiles with the same value collide, they merge to create a tile with double the value. 2+2 becomes 4, 4+4 becomes 8. After each move, another tile appears at random, again with a 90% chance of being a 2. Get to 2048 and you win. Easy, right? Wrong! Play without a cunning plan and you will quickly run out of space and moves, and the game will end.
While playing 2048 one day, I started to wonder if I could program my own version. Games are not something I have spent much time writing. BASIC on an 8 bit computer was simply not fast enough for anything but the simplest of games. My attempt at a side-scrolling helecopter combat game was one of many casualties of the frailties of Eighties magnetic storage media. Probably a good thing too, as firing your gun stopped everything in its tracks so that the firing animation could take place! But 2048 was different, requiring only a little animation. What the hell, I thought. A few hours of blindly hacking away yielded BB2048W (2048 coded in BB4W, get it?), which had the basic functions. Unfortunately, it lacked animation. Move in a particular direction and the tiles simply appeared in their new positions, with new numbers when appropriate. This made working out what had happened a little tricky. (As an aside: there is at least one version of 2048 available on Android that works in this piss-poor way!). A few more hours hacking, and I had managed to get "stepped" animation, where tiles jumped from one square to the next. A few more hours, and I had managed to get much smoother animation.
I have spent a lot of time refining the code. The earliest versions required four different chunks of code to process moves in each of the four directions. Later on, these were replaced by two chunks of code: one to control horizontal movement, and the other to control vertical movement. Later still, and I had managed to cobble together a single chunk of all singing, all dancing code that could process movement in any direction provided you fed it the required vector information.
For speed, the number tiles are plotted each time by the program as a simple coloured square with the number as text, but I was curious if my program would be fast enough to use bitmap tiles. Amazingly, it was, so I added the ability to use pictures instead of numbers, and in such a way that it is easy to change the pictures without changing the program. The supplied ZIP file contains picture tiles for a Doctor Who version. This idea was shamelessly ripped off from here, but I think I have better pictures (borrowed from here, for those who care). OK, so there is no War Doctor, and it will soon be out of date, but it is the only non-number version of 2048 that makes sense!
There is something very satisfying in creating a program, and actually using it (if only to waste time, in the case of 2048!). There was something even more satisfying about managing to get the 2048 tile in a version of the game I had programmed myself. Sadly, my satisfaction was short lived; a nasty bug in the code prevented the game from detecting that I had won!
I am rather proud of my version of 2048. The code it entirely my own work, and shares nothing with the original. I did peek at the source code of the original (it is freely available on the web, which explains all of the clones springing up on every App Store!), but as it was not programmed in BASIC, I have absolutely no idea how it works! If it is anything like mine, I will be very surprised!
You can download a ZIP file containing everything you need. The program does not need formal installation: simply unzip the program's folder in any location you like, and run it. User preferences are stored on a per-user basis in the Application Data folder. Your Registry will not be accessed in any way.
A NOTE ABOUT NORTON: The "advanced" heuristic algorithms used by Norton antivirus will flag this program as a high risk to your system, and the program will be removed. Sadly, the expense of digitally signing my software is simply too high, so you will have to take my word for it that this program will not harm your system in any way, or steal your identity to allow me to live the high life on some tropical paradise island surrounded by dusky maidens. You can safely retrieve it from Norton's Quarantine, and exclude it from future scans.
Source code available on request.
Please let me know what you think of this program – good or bad! Please also let me know if you encounter any bugs. Full details of what you were doing at the time will be helpful in tracking down the mistake and squashing it good and proper.
Home
How I wasted my teenage years!
Letter Graph
Make your graphs more meaningful...
Colour Check
A colour sampling tool.
2048
My take on the game that is sweeping the nation!
FRapp
A file rename utility.
Magnifiques
An old friend – the latest version of a program I started in the Eighties!
Textractor
A useful text extraction tool.
Tangler
A simple text reformatting tool.