Evolving intelligence in a classic game of Pong
This project implements a modern twist on the classic Pong game by integrating the NEAT (NeuroEvolution of Augmenting Topologies) algorithm to evolve intelligent game agents. The system uses Python and Pygame to simulate gameplay while employing neat-python for dynamic neural network evolution. It is designed for developers, researchers, and hobbyists interested in AI, game development, and machine learning. Unique selling points include real-time AI training, interactive checkpointing, and adaptive gameplay that evolves over time.
- Python 3.x
- Pygame: For game rendering and event handling.
- neat-python: For implementing the NEAT algorithm.
- pickle: For saving and loading checkpoints.
- glob & os: For file and checkpoint management.
- Python 3.x installation
- Ensure pip is installed
Install the required packages using:
pip install pygame neat-python
Clone the repository from GitHub:
git clone https://github.com/muhammadhamzagova666/ai-pong-neat.git
cd ai-pong-neat
Start training the AI by running:
python Source/main.py
This will start the game, begin the NEAT training process, and automatically resume from the latest checkpoint if available.
After training completes, the best performing network is loaded and a live game session is initiated for demonstration purposes.
ai-pong-neat/
├── AI-Controlled Pong Game Project Presentation.pdf
├── AI-Controlled Pong Game Project Proposal.pdf
├── Report/
│ ├── Report.tex
│ ├── FAST.png
│ ├── Game.png
│ ├── NU-logo.jpg
│ └── Training.png
└── Source/
├── best.pickle
├── config.txt
├── main.py
├── README.md
├── checkpoints/
│ ├── neat-checkpoint-0
│ ├── neat-checkpoint-1
│ └── ... (other checkpoints)
└── pong/
├── __init__.py
├── game.py
├── paddle.py
└── ball.py
- Source/: Contains the Python source code and NEAT configuration.
- Source/checkpoints/: Holds checkpoint files to resume AI training.
- Report/: Contains project report, diagrams, and presentation files.
- config.txt: Contains NEAT algorithm settings.
- (Optional) Create a
.env
file if any additional environment-specific settings are required.
- Simply run the training and testing scripts as mentioned above.
-
A Dockerfile can be added for containerized deployment:
FROM python:3.9-slim WORKDIR /app COPY . . RUN pip install -r requirements.txt CMD ["python", "Source/main.py"]
-
Build and run using:
docker build -t ai-pong-neat . docker run -it ai-pong-neat
- Testing: Currently, interactive tests can be triggered by simulating gameplay, with logs printed to the console.
- Debugging Tips:
- Use Pygame’s built-in display debugging.
- Inspect checkpoint files and best.pickle for training state.
- Review console outputs from NEAT reporters.
- Ensure proper frame rate using
pygame.time.Clock()
. - Monitor and adjust NEAT parameters in config.txt for balance between training speed and network complexity.
- Validate all configurations.
- Keep repository dependencies up-to-date.
- If deploying publicly, consider sandboxing game execution.
- Bug Reports & Feature Requests: Submit via GitHub issues.
- Pull Requests: Fork the repository, create a feature branch, and submit a pull request.
- Please adhere to the Code of Conduct for contributions.
- For API reference and detailed explanation of modules (e.g.,
Source/main.py
), please refer to the docs.
- Enhance multiplayer support.
- Improve AI training visualization.
- Add comprehensive unit tests.
- Integrate CI/CD for automated testing and deployment.
- Q: How do I resume training?
A: The system automatically resumes from the latest checkpoint in the/checkpoints
directory. - Q: What are the project dependencies?
A: Python 3.x, Pygame, neat-python.
- This project was inspired and developed from the teachings of the Tech with Tim YouTube channel, particularly the video Python Pong AI Tutorial - Using NEAT.
- Special thanks to contributors and libraries like Pygame and neat-python.
For support or to contribute, please reach out via GitHub:
- GitHub Profile: muhammadhamzagova666