Early 2019 I took an online course on machine learning (available on Udemy here). Upon completion I decided to try and build a neural network capable of playing a game I created a while back. Check out the results here!
I suggest you first check out the video in the top of this post, then get back here if you want to know more. The model is based on training a neural network using reinforcement learning (specifically using a technique called Q-learning). Described in more depth in the below pseudocode:
- Initate random weights for the neural network’s hidden layer.
These weights determine which action the agent should take depending on the input state.
- Check available line of sight in 5 directions.
Specifically the five colored raycasts in the figure, indicating how far away any blocking object is located.
- Take action based on input state.
- Turn left
- Do nothing
- Go right
- Assign reward.
- If crashed = negative reward
- If alive = minor positive reward
- If successfully passed a tree = positive reward
- Log memory.
Save the input state, which action was taken and the associated reward.
- If alive = repeat step 2-6.
- If crashed = train the neural network using backpropagation and experience replay.
Reduces the likelihood of the network committing the same action that resulted in a crash, while simultaneously reinforcing the behaviour that resulted in a positive rewards.
The game is built in Unity and is written in C#. No external machine learning libraries were used.