This project implements a deep learning-based AI system that can play Street Fighter II Turbo. The system records human gameplay, trains neural networks on these recordings, and then uses the trained models to control characters in the game.
The project consists of several key components:
- Data Collection - Record human gameplay to create training datasets
- Data Processing - Normalize and transform gameplay data into suitable format for DL
- Model Training - Train neural networks to predict button presses based on game state
- Bot Execution - Use trained models to play the game automatically
The system supports two types of neural network architectures:
- Standard ANN - Feed-forward neural network with dense layers (original implementation)
- RNN/LSTM - Recurrent neural network that better captures temporal game state sequences
The system supports all characters in Street Fighter II Turbo:
| ID | Character | ID | Character | |
|---|---|---|---|---|
| 0 | Ryu | 6 | Zangief | |
| 1 | E. Honda | 7 | Dhalsim | |
| 2 | Blanka | 8 | M. Bison | |
| 3 | Guile | 9 | Sagat | |
| 4 | Ken | 10 | Balrog | |
| 5 | Chun-Li | 11 | Vega |
- Python 3.6+
- TensorFlow 2.x
- Street Fighter II Turbo ROM
- BizHawk Emulator (EmuHawk.exe)
- Clone this repository
- Install required Python packages:
pip install tensorflow pandas numpy scikit-learn joblib pynput scikeras
- Navigate to either the
single-playerortwo-playersfolder - Run
EmuHawk.exe - From the File menu, choose Open ROM (Ctrl+O)
- Select the
Street Fighter II Turbo (U).smcROM file - From Tools menu, open the Tool Box (Shift+T)
- Open a command prompt in the
PythonAPIdirectory and run:python controller.py "1" "record" - Select your character in the game after choosing normal mode
- Click on the Gyroscope Bot icon (second icon in the top row)
- The emulator will connect to your program and show "Connected to game"
- Play the game - your moves will be recorded to create the dataset
The recorded data will be saved in the normalized_character_datasets folder.
- Follow steps 1-5 from the Recording Gameplay section
- Open a command prompt in the
PythonAPIdirectory and run:python controller.py "1"
To use the RNN-based models instead of standard ANN, run:
python controller.py "1" "rnn"
- Select your character in the game after choosing normal mode
- Click on the Gyroscope Bot icon (second icon in the top row)
- The AI bot will now take control and play the game
For two-player mode with player 2 controlled by AI, use:
python controller.py "2" # Standard ANN
python controller.py "2" "rnn" # RNN model
-
PythonAPI/- Main code directory- bot.py - Standard ANN implementation
- rnn_bot.py - RNN implementation using LSTM models
- buttons.py - Button state representation
- command.py - Command objects to send to game
- controller.py - Main interface between game and system
- game_state.py - Game state representation
- player.py - Player state representation
- listen_to_key.py - Keyboard input detection
- make_dataset.py - Dataset creation utilities
-
normalized_character_datasets/- Raw datasets for each character -
flattened_window_datasets/- Processed datasets ready for training -
models/- Trained standard ANN models -
RNN_models/- Trained RNN/LSTM models -
train_models/- Training scripts- train_individual_character.py - Train standard ANN models
- train_individual_character_rnn.py - Train RNN models
-
single-player/- Single-player game files -
two-players/- Two-player game files
To train standard ANN models for specific characters:
- Ensure you have recorded gameplay data for the characters
- Process the normalized datasets into windowed datasets
- Edit train_individual_character.py to specify which character IDs to train
- Run the training script:
python train_models/train_individual_character.py
To train RNN/LSTM models:
- Ensure you have the flattened window datasets ready
- Edit train_individual_character_rnn.py to specify which character IDs to train
- Run the RNN training script:
python train_models/train_individual_character_rnn.py - The script will perform a grid search to find optimal hyperparameters
- Models will be saved to the
RNN_models/directory
- Game not responding to AI commands: Ensure the game is properly connected to the controller
- Character not moving as expected: Check that the model for that character has been properly trained
- Connection errors: Make sure you're running the correct port (9999 for player 1, 10000 for player 2)
- ImportError with KerasClassifier: Make sure you have installed the
scikeraspackage
- Uses a sliding window of 6 frames flattened into a 1D feature vector
- Neural networks use 3 dense layers with dropout for regularization
- Models are trained with class weighting to handle imbalanced button presses
- Processes the 6-frame window as a temporal sequence (not flattened)
- Uses LSTM layers to capture temporal relationships between frames
- Better captures action sequences and player movement patterns
- Hyperparameter optimization via grid search to find optimal architecture
- Provides improved gameplay prediction by understanding time-dependent patterns
| Feature | Standard ANN | RNN/LSTM |
|---|---|---|
| Temporal Understanding | Limited | Strong |
| Training Speed | Faster | Slower |
| Model Size | Smaller | Larger |
| Sequence Learning | No | Yes |
| Hyperparameter Tuning | Manual | Automated Grid Search |
| Memory Usage | Lower | Higher |