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.
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.
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.
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.
- ๐ค 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.
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.
- Clone the repository:
git clone https://github.com/your-repo/kirby-rl.gitcd kirby-rl - Install the dependencies:
pip install -r requirements.txtPython verion 3.9.20 - Place the Kirby.gb ROM file to the Game folder.
Start training the agent by running:
python main.py
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.
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.
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.
๐ก Potential enhancements for the project:
- ๐น๏ธ Extend Training: Apply the RL agent to additional levels of the game.
- ๐ Compare Algorithms: Experiment with alternative RL models for better performance.
- ๐ง Reward Tuning: Refine the reward system for more complex scenarios.
Feel free to fork, modify, and experiment with different RL approaches. Letโs see how far Kirby can go! ๐
