What is this project?

This is a dabble in programming my own AI from scratch without any libraries, just looking up information and doing my own research about the foundations of how neural networks function. Everything is written in C# and made in Unity.

I originally made this project in December 2024 and never bothered to publish it until now. 

The web version almost certainly WON'T run when you leave the tab. If you want to run it in the background, install the standalone version below.

What are the controls?

There are none. The only interactable part of the project is the restart button in the bottom right. The camera will automatically snap to the current furthest agent.  

What is the "average"  counter?

"Average" is the average distance an agent  reached before they died. The number is updated at the end of a generation, so whenever you see the average number change, that's the average for the PREVIOUS generation and not the current generation you're watching.

What's up with the graph?

The graph is a visualization of the currently viewed agent's neural network, IE its brain. Each square is a node of its neural network, and the size of the square is how activated it is.

Each square is also colored from green to red, representing whether its bias is positive or negative.

The bundle of lines going from each node to the next layer is the weight, and colors from green to red represent whether that weight is positive or negative. The width of the line also represents the absolute value of the weight.

How do the agents learn?

I'm using an evolutionary method to fine tune the agents through selective pressures instead of mathematical techniques like backpropagation. In this case, the selective pressure is the risk of falling to death and the giant laser beam coming toward them.

Each generation, the top 5 surviving agents from the last generation will be bred and mixed and then randomly mutated by having some of  their weights and biases flipped.

The next generation will consist of agents whose neural networks are slightly mutated versions of their parents. This ensures that the next generation will always be the descendants of the agents with the best neural networks, but the breeding and mutations will mean that new strategies and optimizations can be found. This is in an attempt to overcome the curse of being stuck in local minima that plagues AI training.

What can the agents do?

The first (leftmost) layer of the neural network consists of 64 input nodes. These represent 64 raycasts pointing in all directions, giving the agent sight.

The second layer is a "hidden" layer, meaning its only purpose is to modify and calculate meaning from the values in the input layer. There can be more than one hidden layer, but for the purpose of this project, there is only one.

The third layer is the output layer. These nodes represent the actions that the agents can take.  The stronger the value in the node, the stronger the action it will take. The agent can take 4 actions. In order from top to bottom:

  • Jump
  • Move forward
  • Air brake
  • Double jump

Why is the graph bugged out when I enter fullscreen?

The graph isn't made for the resolution changing mid-game. The most concise way I can put it is the  lines aren't canvas UI objects.

Isn't this weirdly similar to youtuber CodeBullet's evolution AI project?

Yes, but all the work for this project was done by me. I just liked the aesthetics of the laser and felt like taking inspiration.

Concluding

Thank you for checking out my AI experiment! There is a standalone version available for download if you'd like to run it outside of web!

Download

Download
PlatformerAIStandaloneBuild1.zip 32 MB

Install instructions

1. Download the zip file

2. Extract the zip file to somewhere on your computer

3. Enter the directory where you extracted it into

4. Double click on the .exe file

Development log

Leave a comment

Log in with itch.io to leave a comment.