Writing a 2048 clone in elm
09 May 2014Several weeks ago, I, along with the rest of the internet, discovered 2048, a fascinating one player game based on powers of two. Although it has a simple premise, the game requires a complex set of carefully thought out non-linear strategies to win, in a way that makes it comparable to a Rubik’s Cube, or the two player game Go.
There are many interesting mathematical questions one could ask about the game, both trivial and non-trivial. For example:
- What is the least number of moves required to win?
- What is the lowest possible score when the game is won?
- What is the highest number of moves that can be carried out before a win?
- What is the lowest possible score when the game is lost?
- Is a win always guaranteed?
I intend to try to tackle some of these in another post.
For now, I have applied my new found love for functional programming and created a clone of 2048 in elm. Elm is a programming language based on Haskell that uses Functional Reactive Programming to enable the creation of interactive applications, while keeping the language functional.
Read more