Break Through the Wall of AI Development for High Scores in “2048”! The Secret to Dramatically Boosting Your Score with the Optimal Algorithm, “Expectimax”
- Python
- AI
- algorithm
- game development
- machine learning
In AI development for the 2048 game, the greedy method reaches a plateau at around 4,000 points on average, exposing the problem of local optima, where the best immediate move leads to a future dead end. The root cause is that it does not account for uncertainty (the random appearance of tiles) or calculate future expected values.
What Happened (Symptoms and Causes)
- With the greedy method (a strategy that maximizes the number of merges), once the board becomes complex, it becomes impossible to predict the future, resulting in a game over.
- Because the player's move (Max node) is followed by the system's random tile placement (Chance node), a simple minimax search cannot handle it.
- Because the evaluation function depends only on the number of empty cells and merges, it does not consider tile monotonicity or smoothness.
How It Was Solved (Basic Steps and Commands)
Introduced Expectimax search, the standard solution for games containing probabilistic elements, which calculates the expected value of board states several moves ahead and selects the move that maximizes it.
👉 To see the specific game-tree structure of Expectimax search and methods for optimizing search speed using bit operations, check this out.
Break Through the Wall of AI Development for High Scores in “2048”! The Secret to Dramatically Boosting Your Score with the Optimal Algorithm, “Expectimax”
Results After the Fix (Before / After)
By combining Expectimax search with sophisticated heuristics, it becomes possible to consistently achieve scores in the tens of thousands and, at times, aim for hundreds of thousands. Also, when designing an evaluation function, defining not only “what is good” but also “what is acceptable” is an important best practice for avoiding a rigid AI.
🚀 For the complete code and detailed environment-specific instructions, see here
You can find a full explanation of alternative approaches to Monte Carlo tree search (MCTS) and automatic heuristic tuning using meta-optimization algorithms.
Note: This technical note is an excerpt of the key points from an article written for the technical blog CodeArchPedia.com.
Go to list of users who liked
Go to list of comments
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme