AsDroid
Imitation learning with a neural network from scratch in C.
As an exercise to learn pointers in C I implemented a neural network from scratch. I used it to control a character in a simple 2d game where the player shoots a falling target.
This was my first semester of college and we were tasked with making a simple game on our own to learn a library called CProcessing for graphics and stuff. For the past year I’d been learning the basics of neural networks by building a simple library in Python (see this project) so with that on the mind I wanted to try something similar using C. This way I could learn CProcessing and get practice with pointers at the same time.
The result was this simple game. (clip is 2x speed, human player left, bot right)
The code works by keeping a buffer of state-action pairs from the player and the bot for the last ~2 seconds worth of frames. whenever the player hits a target, the network controlling the bot gets trained for one epoch on the player’s buffer. The same happens using the bots own buffer when it scores a point as well. Using this approach the bot is usually able to play the game well after ~50 training samples and has mastered it after the player has reached 100 points (which translates to roughly ~150 training updates depending on the run).
I will release the source code for this when I get licensing permission from DigiPen.