The code from my video where I try to make an AI from scratch. A neural network, trained by a genetic algorithm, learns to play Super Mario Bros.
mario_nn/— the actual Mario AImain.py— the neural network, breeding/crossover/mutation, and the training loopgym_mario.py— emulator wrapper; reads the NES RAM and builds the 16×13 tile grid the network sees
- Everything else is the practice exercises I did while learning:
simple_perceptron.py— a single perceptron by handperceptrons.py— perceptron that learns to classify points above/below a lineneural_network.py— first layers + ReLU with numpystring_evolution.py— genetic algorithm evolving a target stringrockets.py— smart rockets evolving toward a targetnotes.md— notes I took while learning
pip install numpy opencv-python gym-super-mario-bros nes-py
python mario_nn/main.py
main.py currently resumes from a saved population (last_population.npz, not included). To train from scratch, swap elements = load_population() for the commented-out n = 100 / elements = create_population(n) lines.
The exercises additionally use matplotlib, nnfs, and pygame.