Skip to content

An interface between Mario 64 and Python, suited for training AI. Example code provided

Notifications You must be signed in to change notification settings

Gumbo64/sm64-AI

 
 

Repository files navigation

sm64 AI environment

This fork provides an interface between Python and the game Mario 64 in order to train AI, with many additional features to make it as painless and practical as possible. This functionality includes

  • Support for multiple game instances
  • Support for up to 254 players within the same game (can touch and see each other etc)
  • Can load into any level directly
  • Images and several other numerical features (position, velocity, height, health etc) accessible
  • Custom resolution images
  • Python tool to stitch all images together in one window
  • Extremely high speed, since the game executes in native C code and not an emulator
  • Variety of environment types provided
  • Pytorch (CleanRL) examples provided
  • Supports the pettingzoo API
  • Curiosity based learning

Results

My most successful approach has been using curiosity-based learning with EA's technique, where the AI is rewarded for reaching areas that have not been visited yet.

Below is a video of it running (click on it)
Alt text

Comparing the coverage of the random player to the AI's displays its successful learning.

Original map for reference Randomly moving players Curiosity-based AI learning
enter image description here enter image description here enter image description here

Setup

  1. Put a sm64 US rom in the env folder and rename it baserom.us.z64

  2. If on windows, set up MSYS2 and install dependencies otherwise for linux just install build dependencies

  3. Open MSYS2 (windows) or terminal (linux) from the repository folder and then run this command.


cd env && make -j16 MAX_PLAYERS=20

MAX_PLAYERS is the number of marios playing per environment. Even numbers are recommended otherwise hide and seek will not work. 255 is the maximum, 20 is recommended. If you want to change MAX_PLAYERS, delete the env/build/us_pc folder first (my temporary solution)

  1. install python requirements

pip install -r requirements.txt

  1. (optionally) download the pre-trained model into /trained_models and run sm64_test_curiosity_model.py to test it

To change the map, go to env/mods/compass/main.lua and change gLevelValues.entryLevel to whatever level

About

An interface between Mario 64 and Python, suited for training AI. Example code provided

Resources

Stars

Watchers

Forks

Languages

  • Python 74.7%
  • Jupyter Notebook 25.3%