Skip to content

RJ601/Gamebot_Street_Fighter_II

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🥋 Street Fighter ML Bot – Train, Play, Evolve!

A machine-learning-powered Street Fighter bot that learns from real gameplay data - either your own manual moves or a rule-based bot. Collect gameplay data, train a neural network, and watch your bot adapt its fighting style.

Ken1.mp4

[Caution: This video is fast-forwarded. The game might run very slow once you connect it to the ml-bot due to high inference time]

Built on top of the game setup provided by my instructors, this project has:

  • A data collection system to log player states & actions preparing a training dataset.
  • A rule-based mode for automatic data collection.
  • A human-play mode for richer, more realistic training data.
  • A training pipeline to convert your data into a smart ML bot.
  • An ML_Bot with temperature settings to allow diversity of moves.

Inside the PythonAPI folder

🛠 Files I Wrote or Modified

  • controller.py (modified): Integrated custom data collection, manual-play option, and ML bot option. Added data_collect() function to flatten input_dict, extract relevant states & commands, and append to data.csv. Also replaced the default bot instance with configurable options.
  • manual.py (new): Enables human-controlled play via keyboard inputs for richer training data.
  • training.py (new): Reads data.csv, processes features & labels, trains a neural network, and saves ml_bot.keras (model) and label_encoder.pkl (command encoder).
  • ml_bot.py (new): Uses the trained model to predict moves during gameplay. Includes a temperature() function to control move diversity.
  • data.csv (new): contains training data.
  • requirements.txt (new)

📦 Files Provided by Instructors (you don't have to worry about these)

These were part of the PythonAPI Folder originally provided:

  • buttons.py
  • commands.py
  • gamestate.py
  • player.py
  • bot.py (the rule-based bot)
  • controller.py (original version that sets up connection to game)

📌 Files You’ll Work With

  • training.py: Just run this script to train a new model from data.csv. Produces ml_bot.keras and label_encoder.pkl.

  • controller.py (optional): Main integration point. If interested in trying manual play, collecting more data, or trying rule-based bot, you will only have to make modifications in main(). Choose between: Human() (manual play), Bot() (if-else bot), or ml_bot() (trained AI). Also toggle data_collect() call to gather more training data into data.csv (or to stop collecting data). The file includes comments on where to choose between the bots, and where to collect data. I tried to make the instructions super simple for convenience.

    image
  • ml_bot.py (optional): Adjust numerical values in the temperature function to experiment with diversity of the bot's moves.

    image

Prequisites/Dependencies

  • Operating System: Windows 7 or above (64-bit)
  • The Python API is made in version 3.6.3 and tested only for this version but it should run on any version above 3.

Setting up the repository and ml-model in your local computer

1️⃣ Clone the Repository

git clone https://github.com/RJ601/Gamebot_Street_Fighter_II

cd Gamebot_Street_Fighter_II\PythonAPI

2️⃣ Create a Virtual Environment

(Recommended to avoid version conflicts)

python -m venv [environment_name]

[environment_name]\Scripts\activate # Windows

source [environment_name]/bin/activate # macOS / Linux

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Train the Model

python training.py

This will produce:

  • ml_bot.keras: the trained neural network model.
  • label_encoder.pkl: maps model outputs back to game moves.

Starting the game and connecting it to your controller - Instructions originally provided by my instructors

  1. For running a single bot (your bot vs CPU), open the single-player folder. For running two of your bots at the same time both fighting each other, open the two-players folder.

    Note: The single-player and two-players folders are too large to be uploaded on github. Use the following link to access the folders and then place each folder in your Gamebot_Street_Fighter_II folder.

    https://drive.google.com/drive/folders/1G1UKj8nfzxs1yjHw8McNh9LvZ1hDe_Fx?usp=drive_link

  2. Run EmuHawk.exe.

  3. From File drop down, choose Open ROM. (Shortcut: Ctrl+O)

  4. From the same single-player folder, choose the Street Fighter II Turbo (U).smc file.

  5. From Tools drop down, open the Tool Box. (Shortcut: Shift+T)

  6. Once you have performed the above steps, leave the emulator window and tool box open and open the command prompt in the directory of the API and run the following command:

    python controller.py 1

    Note: The '1' at the end of each execution command is a command-line argument. '1' is for controlling player 1 through your bot (left hand side player in the game). '2' if you want to contol player 2 (right hand side player in the game). Any command-line arguments other than '1' or '2' (without the quotes) will cause the code to give an error.

  7. After executing the code, go and select your character(s) in the game after choosing normal mode. Controls for selecting players can be set or seen from the controllers option in the config drop down of the emulator.

  8. Once the game starts (when it says "Round 1"), click on the second icon in the top row (Gyroscope Bot) of the toolbox. This will cause the emulator to establish a connection with the program you ran and you will see "Connected to the game!" or "CONNECTED SUCCESSFULLY" on the terminal.

  9. If you've not modified the controller file, you'll see the ml_bot playing here as the chosen player. In case of modifications in the controller file, your chosen bot will be playing here (you will have to play yourself if it has been set to manual/Human).

  10. The program will stop once a single round is finished. Repeat this process for running the emulator and the code again.

Future Ideas and Suggestions

  • Integration of reinforment learning so that the model keeps improving on its own.

Any other suggestions and creative ideas are most welcome

Credits

Core game framework and connection setup and instrcutions provided by my instructors.

Custom data collection, manual play mode, training pipeline, and ML bot developed by me.

📜 License

This project is licensed under the MIT License – you are free to use, modify, and distribute the code as long as you include the original license in any copies or substantial portions of the software.

About

A machine-learning-powered Street Fighter bot that learns from real gameplay data - either your own manual moves or a rule-based bot. Collect gameplay data, train a neural network, and watch your bot adapt its fighting style.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors