Source code here

2048 is a single-player game where the player has to slide tiles on a grid to combine them and create a tile with the number 2048. The game is played on a 4x4 grid, which is initially filled with two tiles, and every turn a new tile with the number 2 or more rarely 4 appears at a random empty spot on the board.
The player can slide the tiles in four directions: up, down, left, and right, the slide operation moves the tiles as far as possible in the chosen direction until they are stopped by either another tile or the edge of the grid. If two cells with the same number collide while moving, they will merge into a tile with the sum of their two values, and the total score is incremented by the amount of the newly formed tile. The resulting tile cannot merge with another tile again in the same move. Note that due to the game rules, the board will always be filled with tiles with a power of 2. The game ends when the player has no legal moves left, which happens when the board is full, and no adjacent tiles have the same value.

In the repository linked above, I implemented a Deep Q-Network (DQN) agent that learns to play the 2048 game. The agent uses a convolutional neural network to approximate the Q-function, which is used to select the best action to take in a given state. The agent uses an epsilon-greedy policy (different policies are implemented) to explore the environment and learn the optimal policy.

The agent is trained using the DQN algorithm, which is a model-free reinforcement learning algorithm that learns to play the game by interacting with the environment and updating its Q-function based on the rewards it receives.

Demo of the DQN agent playing a game
Demo of the DQN agent playing a game.