This is a deep Q-learning algorithm to solve a pathfinding problem
In this Treasure Hunt game, the agent tries to find the optimal path to the treasure in an 8×8 maze. The function below applies deep Q-learning to train the agent to navigate the maze and find the treasure.
Agent wins Treasure Hunt game
This code is part of a larger codebase. If you have access to the full codebase, you can replace your qtrain() function with this one for experimenting.
I initially had the source code for the qtrain function, but WordPress keeps chopping some of the code from the function and rendering the entire qtrain function useless. As a remedy, I opted to upload a screenshot of the code until I finish developing a tailored CMS for Brogramo that is free from the WordPress clutter that hinders most sites.
qtrain function 1 of 3
qtrain function 2 of 3
qtrain function 3 of 3
The following image captures the results of the qtrain() function. The agent begins playing the game by making random moves and eventually begins to exploit past experiences to increase its winning streak. The game ended when the agent received a 100% win rate at epoch 87.