Skip to content

Training a Deep Q Learning agent to master the famous arcade game, Asteroids using a DQN Neural Network with Long and Short term Memory recall. This is also my undergrad minor project, 21IS6P01.

License

Notifications You must be signed in to change notification settings

lokranjanp/AsteroidsAI

Repository files navigation

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

Human Playable Game

The human-playable version of the game can be found at: Asteroids

Data Analysis Repository

Data analysis comparing human and RL agent gameplay can be found at: Asteroids Data Analysis

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:
    git clone https://github.com/lokranjanp/AsteroidsAI.git
  2. Navigate to the project directory:
    cd AsteroidsAI
  3. Install the required dependencies:
    pip install -r requirements.txt

Running the Game

  1. To play the human-playable version:
    python3 main.py
  2. To run the RL agent:
    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 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! 🎮🚀

About

Training a Deep Q Learning agent to master the famous arcade game, Asteroids using a DQN Neural Network with Long and Short term Memory recall. This is also my undergrad minor project, 21IS6P01.

Topics

Resources

License

Stars

Watchers

Forks

Languages