Writing a 2048 Clone in Ruby
Before we start coding, we take some time to look at the actual game of 2048.
Two Dimensional Arrays in Ruby
We'll use a two dimensional array to represent the 2048 game board, but how do we create a 2D array in Ruby?
Rotating a Two Dimensional Array in Ruby
In order to implement the 2048 algorithm cleanly, we'll need to know how to rotate a 2D array by 90 degrees in Ruby.
The Board Class
Before we dive into the heavy stuff, we'll look at the array we use to store the board, as well as how to print the board to the console and a few other things.
The Core Algorithm
Finally, onto the meat of 2048. We take a look at how the board is rotated and slid to implement the game of 2048.
The Final Few Methods
Now that the core of the game is done, we take a few minutes and look at a few odds and ends. Among those, the code that spawns new tiles and the code that looks for the game over state.
Cloning 2048 in Ruby
In this series of articles, a complete clone of the game 2048 is written from scratch.