Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lokranjanp/asteroidsai

Training a Neural Network to master the famous arcade game, Asteroids
https://github.com/lokranjanp/asteroidsai

Last synced: 6 days ago
JSON representation

Training a Neural Network to master the famous arcade game, Asteroids

Awesome Lists containing this project

README

        

# AI-Powered Asteroids Game

## Overview
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
Game graphics used from: [Spacecraft Redux](https://www.kenney.nl/assets/space-shooter-redux)

### Human Playable Game
The human-playable version of the game can be found at: [Asteroids](https://github.com/lokranjanp/Asteroids)

### Data Analysis Repository
Data analysis comparing human and RL agent gameplay can be found at: [Asteroids Data Analysis](https://github.com/lokranjanp/Human-RL-DQN-interpretations)

## Project Phases

### Phase 1: Human Playable Game
Developed a fully functional, human-playable version of Asteroids using Pygame. This phase involved:
- Designing game mechanics
- Creating graphics and controls for smooth gameplay

### Phase 2: Game Reinforcement Learning (RL)
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

### Phase 3: Human Game Data vs. RL Game Data Analysis
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

## Technical Details

### Neural Network Architecture
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

## Installation

### Prerequisites
- Python 3.10
- Pygame
- PyTorch

### Setup
1. Clone the repository:
```bash
git clone https://github.com/lokranjanp/AsteroidsAI.git
```
2. Navigate to the project directory:
```bash
cd AsteroidsAI
```
3. Install the required dependencies:
```bash
pip install -r requirements.txt
```

### Running the Game
1. To play the human-playable version:
```bash
python3 main.py
```
2. To run the RL agent:
```bash
python3 agent.py
```

## Usage

### Human Playable Game
- Use arrow keys to move the spaceship.
- Press the spacebar to shoot.

### RL Agent
- The RL agent automatically navigates and plays the game based on the trained model.

## Contributing
We welcome contributions to improve the project. Please feel free to submit a pull request or open an issue to discuss any changes.

## Acknowledgements
- [Kenney.nl](https://www.kenney.nl/assets/space-shooter-redux) 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! 🎮🚀