A Python implementation of the popular 2048 game featuring an AI agent that learns to play through self-training using TensorFlow.
- Classic 2048 game implementation
- AI agent powered by TensorFlow
- Self-learning capabilities through reinforcement learning
- GPU acceleration support
- Real-time visualization of game states
- Performance logging and monitoring
- Training progress visualization using Matplotlib
- Python 3.7+
- TensorFlow 2.x
- NumPy
- Pygame
- Matplotlib
- Clone the repository:
git clone https://github.com/scar17off/ai-2048.git
cd 2048-ai-self-learning
- Install dependencies:
pip install tensorflow numpy pygame matplotlib
self_learn.py
: Main self-learning AI implementationgame_logic.py
: 2048 game mechanicstrain_model.py
: Model training orchestrationai_play.py
: AI gameplay executioncolors.py
: Game interface color definitions
- Generate training games:
python generate_training_games.py
Or download pre-generated games (dataset) in releases.
- Train the AI model:
python train_model.py
Or download pre-trained model in releases.
- Watch the AI play:
python ai_play.py
The project automatically configures GPU settings for optimal performance. It enables memory growth and selects the primary GPU for processing, as shown in self_learn.py
.
To run the project on GPU:
- Install TensorFlow GPU version:
pip install tensorflow-gpu
-
Install CUDA (https://developer.nvidia.com/cuda-downloads) version 12.0 or later.
-
Run the project as usual.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Original 2048 game by Gabriele Cirulli
- TensorFlow team for the excellent machine learning framework