This repository contains code for training a reinforcement learning model to play Street Fighter II: Special Champion Edition using the Proximal Policy Optimization (PPO) algorithm.
Remeber to set up the game from the roms folder using the terminal To run the code, follow the instructions below:
pip install gym gym-retro
pip install opencv-python
pip install stable-baselines3[extra] optuna- The
StreetFighterclass is implemented as a custom environment using the Gym interface. - Grayscaling, frame delta, and frame resizing are applied to preprocess observations.
- The
StreetFighterenvironment uses retro.Actions.FILTERED to filter the action space. - This helps focus on relevant actions for optimal training.
- Random Sampling of Actions
- https://github.com/FruitPnchSamuraiG/StreetFighter/assets/146465657/b182aa1c-035b-4718-b02d-e55c5346aeb5
- The reward function is set to the in-game score.
- The
stepmethod reshapes the reward function based on the score delta.
- Hyperparameters are optimized using Optuna, and the best model is saved.
- The
TrainAndLoggingCallbackclass defines a callback to save the model during training. - The
Train Modelsection demonstrates how to train the model using the best hyperparameters.
- The trained model is evaluated using the
evaluate_policyfunction. https://github.com/FruitPnchSamuraiG/StreetFighter/assets/146465657/bbcf38d0-020c-4cfa-98ea-7d4e42186f6b
- The
Test out the Modelsection demonstrates how to use the trained model to play the game. https://github.com/FruitPnchSamuraiG/StreetFighter/assets/146465657/3c435c54-ce85-445f-9d76-931c7cefc926
logs/: TensorBoard logs during training.opt/: Saved optimized models.train/: Checkpoints saved during training.
Follow the Jupyter notebook StreetFighter_Tutorial.ipynb to understand the code execution flow.
Happy gaming and training!