0% found this document useful (0 votes)
26 views5 pages

Expectimaxalgo Game 2048

Uploaded by

sajidajalil63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

Expectimaxalgo Game 2048

Uploaded by

sajidajalil63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Solution of a game using Exectimax.

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

Step 1: Understand the Game State

1. Represent the board as a 4x4 matrix.


2. The player move chooses one of the four directions: up, down, left, or right.
3. After each move, a new tile (2 or 4) spawns randomly in an empty cell.

Step 2: Define the Expectimax Tree

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.

Step 3: Design the Evaluation Function

The evaluation function estimates how "good" a board state is. Common heuristics:

1. Smoothness: Minimize differences between adjacent tiles.


2. Monotonicity: Arrange tiles in a consistent order (e.g., descending).
3. Empty Tiles: Prefer boards with more empty spaces.
4. Max Tile Value: Favor higher maximum tile values.
Step 4: Implement the Expectimax Algorithm

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.

You might also like