12MinsTo9 – simple maths and sliding tiles

A completed game of 12MinsTo9 where the maximum achieved was 512

A very simple game that’s been around for about a decade is 2048, a sliding tile game in which the goal is to slide all of the numbered tiles in one of four directions, in order to cause collisions between two tiles bearing the same number, at which point they combine to become the total of the two.

The original version of the game was written in 2014 by Gabriele Cirulli in JavaScript and CSS, and could therefore be played in a suitably endowed web browser. A possibly more well known implementation to RISC OS users is the one by Eben Upton – he of Raspberry Pi fame – which came a couple of months later, when he ported it to the BBC Micro. These days, that version can also be played in a web browser via the Complete BBC Micro Games Archive.

Rob Hampton, however, has now brought the game to the RISC OS desktop, in an implementation called 12MinsTo9 (20:48, geddit?).

For anyone who really isn’t familiar with the game, you start off with an almost empty play area that can hold sixteen tiles. Each time you slide the tiles in one of four directions, all of the tiles that can move in that direction will move as far as they can – they stop when they collide with the edge of the play area, or another tile.

Unless that tile bears the same number, in which case the two merge, and bear a new number – the sum of the two (equivalent to the number that was on both being doubled for the new tile). This frees up a space – which is handy, because once a slide in any direction is complete, a new tile (with a value of either two or four) will appear at random in one of the empty spaces.

A completed game of 12MinsTo9 where the maximum achieved was 512
A completed game of 12MinsTo9 where the maximum achieved was 512

The more tiles you are able to match, the more open space you retain (or create) for those new tiles, allowing play to continue – once there are no spaces for new tiles, and no way to slide to create any new spaces, play ends.

The goal – giving the game its original name – is to get the face value of at least one tile to reach 2048.

Rob’s version of the game is written in BBC BASIC, and should work on any machine running RISC OS 3.1 or later. He’s released it under the Apache 2.0 licence, with the source code available on GitHub.

Related posts