ecently, my friend challenged me to make an AI that plays the famous 2048 game in Java. I made it and it worked fine for a few minutes then got stuck. After a little debugging, I realized that it was not reading the board correctly and it thought that a 32 was a 1024. In order to explain why it did this, I must first explain how it gets the value of the tiles on the screen.
It first makes the user draw a square around the game board. This was done to tell the program where the game was on the screen. It then generates 16 points, each located in an individual tile. Using the Robot class, it stores the colors of those 16 points in an array.
Here is a picture of this (the small squares represent the points):
It then checks if it has found a new color. If it has found a new color then it assigns the next power of 2 to that color. For example, the first color(the background) is assigned to 0. the next color(white) is assigned to 2 then the next is assigned to 4 and so on. The problem is that when the tiles move, they are animated that is, they don't just teleport to the correct location instead, they move to the correct location. this causes a moment where the wrong color passes under one of the 16 points and the program incorrectly reads that tile.
which brings me to my question: Is there any way to read the tile value in the game 2048 without having to recreate the game in Java?
EDIT:
More specifically, my question is How to get the actual game board Data from 2048 in java?
What I am asking is a way to get the values of the tiles in an external java program.
For Example, take this board:
From this board i would like to get the values of the numbers and store them in an array which would look something like this: {0,0,2,4,0,0,32,2,2,2,16,8,4,32,64,128}
Thanks in advance :)