3
1 Comment

Game Engine Adventures: AI Playing 2048 [Week 6]

Last week I decided to build an AI agent for the game 2048. If you never played it before, 2048 is a puzzle game. Tiles with values of 2 or 4 spawn randomly on a 4 by 4 grid. On each turn, you choose to shift all of the tiles up, down, left or right. Tiles with the same value combine into one tile with sum of the original tiles. Tiles "4" and "4" will combine to create "8". Tiles "8" and "8" will combine to create "16". The goal of the game is to create a tile with value of 2048. You can try to play it yourself at: https://play2048.co/

At first, I thought the challenging part will be designing an output for the agent. I thought that each tile can be moved individually. It turns out that there are only four actions. That makes the output of the agent very simple.

The trickier part is the dynamics of the game. The tiles spawn in random locations and with random values. This makes it harder for the agent to learn a good combination of moves. Also, the game gets exponential harder. It is a lot harder to get tile with value of 512 than a tile of 256. Lastly, certain moves do not change the state of the game. This can lead to an agent getting stuck.

For the initial proof-of-concept I simplified the game by only spawning tiles with value 2 and in deterministic locations. To handle the increasing difficulty, I designed a reward function to provide a reward for each time tiles are combined, each time a new high value tile is created, and for winning the game. There is also a penalty for each move which does not result in tiles combining. To prevent the agent from getting stuck, I mask each action which did not result in a change to the game gird in the previous move.

The agent still has 15 million training steps to go. So far it is able to win the simplified version of 2048 some of the time. Next I'll fine tune it with random tile values. After that, I'll unleash it on the original version of the game. 🦾🤖🤖🤖

  1. 1

    FaceMAgic Pro APK Latest version is free editing AI face-swapping tool that allows morphing your face into the body of any celebrity. It provides a realistic view of editing and no one will believe that it is fake. In addition, the modified version offers lots of additional features free of cost that is paid for in the original version.

Trending on Indie Hackers
Competing with Product Hunt: a month later 33 comments Why do you hate marketing? 29 comments My Top 20 Free Tools That I Use Everyday as an Indie Hacker 18 comments $15k revenues in <4 months as a solopreneur 14 comments Use Your Product 13 comments How I Launched FrontendEase 13 comments