

The game ends when the player manages to create a cell with value 2048 (win) or when there are no other moves to make (lose). At the end of every move a random value is added in the board in one of the empty cells and its value is either 2 with 0.9 probability or 4 with 0.1 probability. If that previous cell has the same value, the two cells are merged into one cell with double value. When you perform a move all the values of the grid move towards that direction and they stop either when they reach the borders of the grid or when they reach another cell with non-zero value. At every point during the game you are able to move the values towards 4 directions Up, Down, Right or Left. The main idea of the game is that you have a 4×4 grid with Integer values, all of which are powers of 2. The original game is written in JavaScript, so I had to rewrite it in JAVA from scratch.
Halma board game against ai code in java license#
The code is open-sourced under GPL v3 license and you can download it from Github. In this article I will briefly discuss my approach for building the Artificial Intelligence Solver of Game 2048, I will describe the heuristics that I used and I will provide the complete code which is written in JAVA. So the natural thing to do is to try to develop an AI solver in JAVA to beat the 2048 game. Personally even though I spent a fair amount of time playing the game, I was never able to reach 2048. As expected the difficulty of the game increases as more cells are filled with high values. It’s a simple but highly addictive board game which requires you to combine the numbers of the cells in order to reach the number 2048.

By now most of you have heard/played the 2048 game by Gabriele Cirulli.
