A modern twist on the classic Asteroids game where the enemies (asteroids) use a Genetic Algorithm to learn and adapt to your playstyle.
This project features a modular evolutionary framework, allowing for plug-and-play AI strategies. The asteroids are controlled by neural networks that evolve over generations.
- Crossover (Sexual Reproduction): Offspring inherit traits from the two best-performing parents. This allows for faster convergence and the emergence of "Super Asteroids" that combine speed and maneuverability.
- Tournament Selection: Pick random groups of asteroids and let them compete. The winner passes on its genes, ensuring behavioral diversity and preventing the AI from becoming too predictable.
You can swap between evolution strategies by changing a single constant in src/utils/constants.py:
# Change this to "crossover" or "tournament"
EVOLUTION_STRATEGY = "crossover"- Python 3.11
pygame-cenumpypygame-gui
-
Install dependencies:
pip install pygame-ce numpy pygame-gui
-
Run the game:
python main.py
- Aim: Move your mouse (the rocket points toward the cursor).
- Thrust: Hold Left Mouse Button (LMB) to accelerate.
- Shoot: Press Right Mouse Button (RMB) to fire bullets.
- Pause: Press ESC.
src/core/: Game state management and main loop.src/entities/: Rocket, Asteroid, and Bullet logic.src/evolution/: All pluggable AI strategies and the factory.src/utils/: Neural network math and game constants.assets/: Game images, fonts, and UI themes.
