https://github.com/vpn1997/2048-ai
Bot playing 2048
https://github.com/vpn1997/2048-ai
game-theory machine-learning
Last synced: 9 months ago
JSON representation
Bot playing 2048
- Host: GitHub
- URL: https://github.com/vpn1997/2048-ai
- Owner: vpn1997
- Created: 2017-10-01T10:54:03.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-15T13:37:16.000Z (about 8 years ago)
- Last Synced: 2025-05-30T14:21:07.596Z (about 1 year ago)
- Topics: game-theory, machine-learning
- Language: Python
- Size: 655 KB
- Stars: 18
- Watchers: 3
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Playing 2048 game with an Automated Bot.
Bot uses Expectimax search with the depth of 4 to find the best possible move.
Project is still in progress. During testing 1024 tile was produced every time and 2048 tile in 60% of the games.
# Prerequisites
Game theory, Machine Learning, Minmax, Expectimax
# Files Info
direct.py --> Expectimax implementation (main algorithm)
puzzle.py ---> Implementation of game (main file, run this file for demo)
logic.py ----> Implementation of game (backend)
merge_game.py -----> Helper file for merging the matrix
## Demo
```bash
$ git clone https://github.com/vpn1997/2048-Ai
$ cd 2048-Ai
$ sh dependencies.sh
$ python puzzle.py
```
## Human Play
Click the "Bot Play" button to turn to Manual Playing mode.
Click the same button, now turned to "Human Play" to let the bot take control



## Heuristics
(In file direct.py)
I have used a score and a penalty function.
A configuration gets a high score if it follows snake line pattern.
Weights are assigned to individual tiles. You can tweak them to get better results.
Penalty is given depending on how many filled tiles are present (more filled tiles => bigger penalty).
You can download the game interface from https://github.com/yangshun/2048-python.
## Future work
1. Getting 2048 or bigger tiles at higher frequency.
2. Using Reinforcement learning didn't give any promising results.
The highest tile it used to get during the game was 128.
So still working on improving that model.
## Reference
https://stackoverflow.com/questions/22342854/what-is-the-optimal-algorithm-for-the-game-2048