This project uses Hierarchical Reinforcement Learning (HRL) to train an AI to play Pokémon Yellow. The AI is structured in a three-tiered hierarchy: Specialists, a Manager, and a Meta-Manager.
- Hierarchical Reinforcement Learning (HRL): A multi-layered AI architecture for complex decision-making.
- Specialist Models: Individual models trained for specific tasks like exploration, battling, healing, and shopping.
- Manager AI: A mid-level AI that directs the Specialists based on the current game state.
- Meta-Manager AI: A top-level AI that sets long-term goals for the Manager.
- Training & Watching Modes: You can either train the AI models from scratch or watch the trained models play the game.
- Debugging Tools: Includes tools for memory scanning, watching memory values, and debugging text hashes.
- Python 3.x
- A legitimate copy of the Pokémon Yellow ROM file, named
PokemonYellow.gb.
-
Clone the repository:
git clone <repository-url> cd "Pokemon Yellow AI"
-
Place the ROM: Put your
PokemonYellow.gbfile in the root directory of the project. -
Install Dependencies: Run the
menu.batscript and select option8to install the required Python packages fromrequirements.txt. Alternatively, you can run this command in your terminal:pip install -r requirements.txt
-
Create Initial Save State: Run
menu.batand select option10to run thecreate_save_state.pyscript. This will guide you through creating the necessary initial save file for the AI to start from. You will also need to create save states for different scenarios like battles, healing, etc. and place them in thestatesdirectory.
The primary way to interact with this project is through menu.bat.
The AI is trained in a bottom-up fashion. You must train the models in this order:
-
(L1) Train Specialists:
- In
menu.bat, select option1. - You can then choose which specialist to train (e.g., Exploration, Battle, Healer).
- Training requires corresponding save states in the
statesdirectory (e.g.,battle_00.state,healer_01.state).
- In
-
(L2) Train the Manager:
- After training all the specialists, select option
2inmenu.bat. - This trains the Manager AI, which learns to control the specialists.
- After training all the specialists, select option
-
(L3) Train the Meta-Manager:
- Once the Manager is trained, select option
3inmenu.bat. - This trains the top-level "CEO" AI that sets goals for the Manager. This process is very slow.
- Once the Manager is trained, select option
You can watch the AI play at any level of the hierarchy.
- (L1) Watch a Specialist: Select option
4to watch a single specialist model perform its task. - (L2) Watch the Manager: Select option
5to watch the Manager AI control the specialists without any high-level goals. - (L3) Watch the Meta-Manager: Select option
6to watch the full AI stack in action. - Watch the Rules-Based Manager: Select option
7to watch a non-learning, rules-based version of the manager.
To monitor the training progress, run menu.bat and select option 9. This will start TensorBoard, and you can view the logs at http://localhost:6006.
PokemonYellow.gb: The game ROM (must be provided by the user).menu.bat: The main script for interacting with the project.requirements.txt: A list of Python dependencies.src/: Contains the source code for the AI agents, environment, and utilities.agents/: The policy networks for the AI.env/: The custom Gymnasium environment for Pokémon Yellow.utils/: Utility scripts for callbacks, memory, etc.
models/: Stores the trained AI models.logs/: Contains TensorBoard logs for monitoring training.states/: Stores game save states (.statefiles) used for training specific scenarios.train_*.py: Scripts for training the different levels of the AI.watch_*.py: Scripts for watching the trained AI models play.debug_*.py: Various utility scripts for debugging.
The AI uses a Hierarchical Reinforcement Learning (HRL) architecture with three levels:
-
Specialists (L1): These are low-level agents trained to perform specific, short-term tasks. Examples include:
exploration_model: Navigates the game world.battle_model: Fights Pokémon.healer_model: Navigates to a Pokémon Center to heal.- And more for shopping, managing inventory, and switching Pokémon.
-
Manager (L2): This is a mid-level agent that does not directly control the game. Instead, it decides which Specialist to activate based on the current game context. For example, if a wild Pokémon appears, the Manager will activate the
battle_model. -
Meta-Manager (L3): This is the highest-level agent, acting as the "CEO" of the AI. It sets long-term goals for the Manager to achieve, such as "get badge 1" or "level up Pokémon". The Manager then translates these goals into actions by deploying the appropriate Specialists.
This hierarchical structure allows the AI to break down the complex goal of playing Pokémon Yellow into smaller, more manageable tasks.
The menu.bat provides access to several utilities:
- Metrics Exporter: Export training metrics to a summary file.
- GUI Memory Scanner: A tool to find memory addresses in the game.
- Memory Watcher: Watch memory values change in real-time.
- Text Hash Debugger: Capture the hash of on-screen text.
You can also run the training scripts in debug mode from the menu, which will run on a single CPU and render the game window.
Contributions are welcome! Please feel free to submit a pull request.
This project is unlicensed.