Skip to content

๐ŸŽฎ๐ŸŒŸA Reinforcement Learning (RL) project using Double Deep Q-Network (DDQN) to train an agent to play Kirby's Dreamland.

License

Notifications You must be signed in to change notification settings

ModusMorris/Kirbys_Dreamland_RL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

43 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Reinforcement Learning: Playing Kirby's Dreamland ๐ŸŒŸ

Kirby complete level

๐Ÿ“ Project Overview

Welcome to the Kirby's Dreamland RL Project! This project showcases the implementation of a Reinforcement Learning (RL) agent that learns to play the first level of Kirby's Dreamland. Using a Double Deep Q-Network (DDQN), the agent aims to:

  • ๐ŸŒ  Complete the level by reaching the warp star.
  • ๐Ÿ’€ Avoid losing all lives (Game Over).

Key features of the project include:

  • ๐Ÿ–ฅ๏ธ Efficient training using a Convolutional Neural Network (CNN) that processes game data as arrays, not raw images.
  • ๐Ÿ† A custom reward and penalty system to guide the agentโ€™s progress.
  • Evaluation Script to test trained models easily and debug performance.

๐Ÿ”‘ Key Details

๐ŸŒ Environment

This project uses PyBoy, a Game Boy emulator, as the training environment. Game states are extracted as arrays representing the game field instead of relying on raw image data. ๐ŸŽฎ Action Space: Kirby can perform various actions such as:

  • Moving left or right
  • Jumping
  • flying
  • absorb in enemies and items
  • Attacking enemies
  • ๐Ÿ–ผ๏ธ Observation Space: The game area is represented as a continuously updated 2D array.

๐Ÿง  Training Details

The RL agent was trained for 25000 epochs, with each episode defined as:

  • ๐ŸŽฏ Completion: Kirby reaches the warp star.
  • ๐Ÿ’€ Termination: Kirby loses all lives.
  • โฑ๏ธ Timeout: Kirby takes 2500 steps without completing the level.

๐Ÿ“Š Rewards and Penalties

The agent is guided by a custom reward system:

  • ๐Ÿฅ‡ Rewards:
    • Progressing toward the goal (e.g., moving right).
    • Defeating enemies or completing the level.
  • โš ๏ธ Penalties:
    • Standing idle or moving away from the goal
    • Losing health or a life.

๐Ÿงฉ Neural Network Architecture

  • ๐Ÿค– Model: Double Deep Q-Network (DDQN).
  • ๐ŸŒ€ Feature Extractor: CNN layers to process game field arrays.
  • โšก Efficiency: By training on arrays instead of raw images, the agent achieves:
    • ๐Ÿš€ Faster training.
    • ๐Ÿ› ๏ธ Reduced resource usage.
    • ๐Ÿ“ˆ Maintained accuracy.

โšก Why This Approach?

Training directly on raw game images is computationally expensive and often unnecessary. By representing the game state as numerical arrays:

  • ๐Ÿ› ๏ธ Resources: Significantly reduced computational requirements.
  • ๐Ÿš€ Speed: Faster training with efficient memory usage.
  • ๐ŸŽฏ Focus: Enables the agent to learn the most relevant patterns in the game environment.

๐Ÿš€ Getting Started

๐Ÿ”ง Setup

  1. Clone the repository: git clone https://github.com/your-repo/kirby-rl.git cd kirby-rl
  2. Install the dependencies: pip install -r requirements.txt Python verion 3.9.20
  3. Place the Kirby.gb ROM file to the Game folder.

๐Ÿ‹๏ธ Run Training

Start training the agent by running: python main.py

๐Ÿ”„ Resume Training

To resume training from the last checkpoint:

  • The model will automatically load the latest saved state.
  • Exploration (epsilon) will adjust dynamically to continue learning effectively.

๐ŸŽฎ Running Trained Models (Evaluation)

To test a trained model without retraining, you can use the evaluation.py script: python evaluation.py This script allows you to:

  • โœ… Load a pre-trained model and observe its performance.
  • โœ… Debug and analyze the agentโ€™s behavior without needing to retrain.
  • โœ… Test different models efficiently.

๐ŸŒŸ Results

After training for 25000 epochs:

  • ๐ŸŽ‰ The agent completes the first level by reaching the warp star.
  • ๐Ÿ“ˆ Learning is guided by a reward system that encourages progress and discourages inefficient behavior.

๐ŸŒ Future Work

๐Ÿ’ก Potential enhancements for the project:

  1. ๐Ÿ•น๏ธ Extend Training: Apply the RL agent to additional levels of the game.
  2. ๐Ÿ“Š Compare Algorithms: Experiment with alternative RL models for better performance.
  3. ๐Ÿ”ง Reward Tuning: Refine the reward system for more complex scenarios.

๐Ÿ”ฅ Join the Project & Contribute!

Feel free to fork, modify, and experiment with different RL approaches. Letโ€™s see how far Kirby can go! ๐Ÿš€

About

๐ŸŽฎ๐ŸŒŸA Reinforcement Learning (RL) project using Double Deep Q-Network (DDQN) to train an agent to play Kirby's Dreamland.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages