The game 2048 has fascinated players and AI enthusiasts alike, spawning many attempts to create intelligent agents that can master its mechanics. One popular approach is the expectimax search algorithm, which looks ahead by considering all possible tile spawns and moves in a recursive manner. But what if there were no handcrafted heuristics or scoring functions guiding the AI? This post explores such a minimalist AI approach that relies solely on randomness and chance.
What is Expectimax Search?
The expectimax search algorithm is a recursive technique alternating between two types of steps:
- Expectation steps: It tests all possible tile spawn locations and their values, weighting each optimized score by the probability of that spawn occurring.
- Maximization steps: It tests all possible moves for the current board state and selects the one with the highest expected score.
This method is powerful because it takes into account both the player’s choices and the randomness of tile spawns, allowing the AI to plan several moves ahead.
An AI Without Hard-Coded Intelligence
Usually, AI implementations for 2048 include heuristicsâlike scoring functions that evaluate how “good” a board state is (for example, favoring smoothness or tile clustering). But what happens if an AI contains no hard-coded intelligence at all?
I experimented with a surprisingly simple algorithm for this:
- To decide the next move for the current board, the AI simulates playing the game in memory by making random moves until the game ends.
- The AI then uses the results of these random trials to inform its next move.
This approach mirrors a very naive version of human thoughtâmaking decisions based on experience from random tries rather than careful planning.
The Limitations of Pure Randomness
EDIT: While conceptually interesting, this random-move AI is quite weak compared to expectimax search that analyzes all possibilities because it effectively only looks ahead by one tile placement. Its drawbacks include:
- Shortsightedness: Without heuristics, it doesnât actively seek out advantageous board states.
- Inefficient Exploration: Random moves can lead to rapid game-ending mistakes.
- Slow Improvement: Learning purely from random play takes far longer to discover high-scoring strategies.
Despite this, it’s a fascinating baseline that helps illustrate why more sophisticated methods outperform naive approaches.
Adding Heuristics: A Hybrid Approach
To improve performance without abandoning the core idea, I added a simple heuristic: the absolute value heuristic. This heuristic evaluates the value of the tiles and influences move choices.
In practice, this hybrid method led to significantly better results, such as achieving the coveted 2048 tile with more consistent play. The animation below demonstrates the last few moves of such a game, highlighting how even a small heuristic can make a substantial difference.
Key Takeaways
- Expectimax search is an effective recursive method for AI game planning, alternating between probabilistic and maximizing steps.
- AI without heuristics, relying solely on random moves, reflects a naive human decision process but tends to underperform.
- Integrating simple heuristics can dramatically improve AI gameplay.
- Experimenting with both pure randomness and heuristics offers valuable insight into AI strengths and weaknesses in 2048.
Conclusion
The quest to create an AI for 2048 that doesnât rely on any handcrafted intelligence reveals a fundamental challenge: without guiding principles, random play struggles to consistently produce high scores. Yet, this simplicity helps us appreciate the power and necessity of intelligent search strategies like expectimax. Sometimes, even a small nudge from a heuristic can transform random wandering into purposeful progression.
Whether youâre building your own AI or just curious about how algorithms tackle randomness and decision-making, experimenting with expectimax and heuristic-free approaches is a great way to deepen your understanding of game AI.