Arcade game using Pygame and open-source game graphics built in Python 3.10. This project served as a facilitator game for an undergrad minor project to train a Reinforcement Learning (RL) model to play Asteroids.
Game graphics used from: Spacecraft Redux
The human-playable version of the game can be found at: Asteroids
Data analysis comparing human and RL agent gameplay can be found at: Asteroids Data Analysis
Developed a fully functional, human-playable version of Asteroids using Pygame. This phase involved:
- Designing game mechanics
- Creating graphics and controls for smooth gameplay
Integrated a reinforcement learning (RL) agent into the game using PyTorch. Key tasks included:
- Training the RL agent to play the game autonomously
- The agent learned through trial-and-error to navigate, avoid obstacles, and maximize its score
Analyzed game data from human players against the data generated by the RL agent. This provided insights into differences in:
- Gameplay strategies
- Decision-making processes
- Overall performance
The RL agent was trained using a deep neural network with the following architecture:
- Input Layer: Takes the game state as input, which includes the spaceship's position, health, power level, points, and positions of asteroids and bullets.
- Hidden Layers: Two fully connected hidden layers with ReLU activation functions.
- Output Layer: Outputs action probabilities for moving left, right, forward, and shooting.
The neural network was trained using the DQN (Deep Q-Network) algorithm, optimizing the following parameters:
- Learning Rate: 0.001
- Gamma (Discount Factor): 0.99
- Python 3.10
- Pygame
- PyTorch
- Clone the repository:
git clone https://github.com/lokranjanp/AsteroidsAI.git
- Navigate to the project directory:
cd AsteroidsAI
- Install the required dependencies:
pip install -r requirements.txt
- To play the human-playable version:
python3 main.py
- To run the RL agent:
python3 agent.py
- Use arrow keys to move the spaceship.
- Press the spacebar to shoot.
- The RL agent automatically navigates and plays the game based on the trained model.
We welcome contributions to improve the project. Please feel free to submit a pull request or open an issue to discuss any changes.
- Kenney.nl for providing the game graphics.
- Our project guide, Dr. Shashank Dhananjay, Associate Professor @ Dept of ISE, NIE, Mysore and reviewer for their valuable feedback and support.
Happy gaming! 🎮🚀