Wow. Same here. I just come to know the game "2048" and it's similar to "1024"
I'm used to dealing with this kind of game (blocks, grids, like my games).
Make an array and try to match each tile to each array member.
You may come to use a lot of loops.