2048 AI
SCORE: 0
Select AI and Depth, then press Start.
About This Project
This interactive web application demonstrates an AI game engine that was designed from scratch by myself and some teammates to quickly solve the game 2048. All of the game logic and AI calculations run directly in your browser using Python, powered by PyScript and WASM.
AI Types:
- Random: This takes a pseudorandomly selected valid move at each step.
- Expectimax: Searches the game tree by alternating between MAX nodes (the AI's move, maximizing heuristic value) and CHANCE nodes (the random tile spawn, computed as a probability-weighted average over all empty cells — 90% for a 2-tile, 10% for a 4-tile). Board states are scored on monotonicity, empty tile count, and adjacent mergeable pairs, normalized and combined with tuned weights. Optimizations include transposition-table caching, adaptive search depth, and empty-cell subsampling to bound the branching factor on open boards.
The Depth setting controls the look-ahead horizon. Higher depth = stronger play at the cost of more computation, particularly when many tiles are empty. Moves are throttled to a 5ms floor for UI responsiveness — clone the repo to benchmark full speed.