This project was developed as part of the Nature Inspired Computing course at Innopolis University. The goal is to train an AI agent to autonomously complete King's Pass, the opening area of the game Hollow Knight, using a NEAT (NeuroEvolution of Augmenting Topologies) evolutionary algorithm.
The agent interacts with the game through a custom mod written in C#, which reads the Knight's game state every few frames — including position, velocity, and health — and broadcasts it over a local TCP socket to a Python process. The Python side runs a NEAT algorithm that evolves neural networks, where each network receives the game state as input and outputs a set of actions (move left, move right, jump, dash, attack). These actions are sent back to the game as simulated keypresses.
Fitness is evaluated using a multi-phase checkpoint system designed around King's Pass's layout. The level requires the agent to first move right, then climb upward, navigate a fork, and finally reach the exit door. Each phase rewards the most relevant movement — horizontal progress early on, then vertical progress during the climb, and a combination of both near the end. A speed bonus is also applied for agents that complete the level faster.
mod/— C# Hollow Knight mod that exports game state over TCPevolutionary_algorithm/— Python NEAT implementation and fitness logicevolutionary_algorithm/config.txt— NEAT hyperparametersevolutionary_algorithm/bridge.py— TCP communication with the modevolutionary_algorithm/actions.py— Keyboard input simulationevolutionary_algorithm/fitness.py— Multi-phase fitness functionevolutionary_algorithm/main.py— Main training loop
Step 1 — Install Hollow Knight Buy and install Hollow Knight on Steam if not already done.
Step 2 — Switch to the correct game version
- Right-click Hollow Knight in Steam → Properties
- Go to Betas tab
- Select "previous version 1.5.78.11833"
- Let Steam download the downgrade
Step 3 — Install Scarab
- Download Scarab from https://github.com/fifty-six/Scarab/releases
- Run it and let it auto-detect your HK installation
- Install DebugMod and Benchwarp
- Launch the game and confirm you see the MOD string in the top left
Step 4 — Clone the repo
git clone https://github.com/darknessd1-netizen/Hollow-Knight-evolutionary-algorithm.git
cd Hollow-Knight-evolutionary-algorithm
Step 5 — Set up the mod
- Create mod/HKPath.props with your PC's HK path:
<Project>
<PropertyGroup>
<HKPath>C:\Program Files (x86)\Steam\steamapps\common\Hollow Knight</HKPath>
</PropertyGroup>
</Project>
- Build and install the mod:
cd mod
dotnet build
The post-build event will automatically copy the DLL to your HK mods folder.
Step 6 — Install Python dependencies
py -m pip install neat-python pyautogui
Step 7 — Set up Benchwarp
- Launch Hollow Knight and load your King's Pass save
- Enable hotkeys in Benchwarp settings
- Test that WD while paused warps back to that spot
Step 8 - Set up DebugMod (optional)
- Launch Hollow Knight and load your King's Pass save
- In hotkeys for DebugMod set up hotkeys for increasing/decreasing tick rate
- Enable Invincibility in "Cheats"
- Increase/decrease tick rate (not faster than x25 than normal or else the algorithm may not send inputs fast enough)
- Increase/decrease max run time in main.py
Step 8 — Run the algorithm
- Launch Hollow Knight and load your King's Pass save
- Open a terminal in the repo folder: cd evolutionary_algorithm py main.py
- Press Enter when prompted and the algorithm will start
- Daniil Ostrovskij
- Alisa Rabover
- Denis Bordiugov