Expectimaxalgo Game 2048
Expectimaxalgo Game 2048
2048 Game: 2048 is a single-player sliding tile puzzle video game by Italian web developer Gabriele
Cirulli. The objective of the game is to slide numbered tiles on a grid to combine them to create a tile
with the number 2048; however, one can continue to play the game after reaching the goal.
The 2048 game can be solved using the Expectimax algorithm, a decision-making algorithm often used
in games where outcomes involve both strategic player decisions and randomness. Expectimax extends
the Minimax algorithm by considering probabilistic outcomes, making it suitable for scenarios like 2048
where new tiles spawn randomly.
Game Mechanics
Grid: The game is played on a 4×4 grid.
o Each tile contains a number (e.g., 2, 4, 8, etc.).
2. Tile Movement:
o Players can swipe (or press arrow keys) to move all tiles on the grid up, down, left, or
right.
o Tiles slide as far as possible in the chosen direction, merging with another tile of the same
value if they collide.
3. Merging Tiles:
o When two tiles of the same number collide, they merge into a single tile with their
combined value.
▪ Example: A tile with 2 and another with 2 merge to create 4.
o Merging tiles increases the player's score by the value of the merged tile.
4. Spawning New Tiles:
o After every move, a new tile (usually 2 or 4) spawns randomly in an empty cell.
o The probability of spawning a 2 is 90%, while a 4 spawns 10% of the time.
5. Game Over:
o The game ends when there are no valid moves left (no empty spaces and no adjacent tiles of the
same value).
Let’s walk through the Expectimax algorithm using an empty 4x4 grid in the 2048 game, and simulate two moves
step by step. We'll use simplified numbers and an easy-to-follow example.
Summary
Step-by-Step Guide
1. Player Nodes (Max Nodes): Represent the player's moves, trying to maximize the score or a heuristic value of the board.
2. Chance Nodes: Represent the random tile spawns (2 or 4). Probabilities:
o 90% chance for a 2.
o 10% chance for a 4.
The evaluation function estimates how "good" a board state is. Common heuristics:
1. Recursively evaluate:
o Player nodes: Select the maximum value among possible moves.
o Chance nodes: Calculate the expected value based on probabilities of new tile spawns.
2. Depth cutoff: Limit the depth of recursion to manage computational cost.