This is a pathfinding bot based on the original Pac-Man ghost AI with a small tweak to make it get stuck less and make it not go through walls when "forced" to. It still commonly gets stuck on loops, however it still works well. Use it in your games, i don't know. It can only move up, down, left and right, by the way.
Credit to Ming Su for the calculate the distance between 2 points block and Retro Game Mechanics Explained for the explanation on how pac man's AI works.