Systems

Neural Network Game Physics Engine

A scikit-learn MLP learns 2D elastic circle collisions from analytic ground truth, and a hand-written C++ forward pass uses it to resolve collisions in a real-time ASCII simulation. The net reaches a test RMSE of 0.175, and the simulator runs an analytic world side by side to measure how chaotic collisions grow that error over 200 steps.

Stack
Python, scikit-learn, C++17, nlohmann-json
Code
github.com/ADM1SH/nn-physics-engine

Overview

Install

# 1. Train the network and export weights.json (uses the shared project venv)
cd "05-nn-physics-engine/python"
../../.venv10projects/bin/python train.py
# -> prints held-out test MSE/RMSE and a few predicted-vs-analytic examples
# -> writes ../data/weights.json

# 2. Build the C++ simulator (uses nlohmann-json, installed via `brew install nlohmann-json`)
cd ../cpp
clang++ -std=c++17 -O2 -I/opt/homebrew/Cellar/nlohmann-json/3.12.0/include -o sim sim.cpp

# 3. Run it
./sim              # prints divergence stats every 20 steps + summary
./sim --render     # also prints ASCII frames every 40 steps

Docs

The full documentation covers how it works, configuration and results.