This is my first attempt at writing an Enemy AI routine. It's not absolutely perfect, but it works fairly well. The enemy will always follow the player until it hits a wall. If it gets stuck on a wall for too long, it will choose a random alternate path to try and get around the obstacle. The demo has a player sprite you control and an enemy sprite that will follow you. If you stay still for long enough, the enemy will eventually find his way to you.
The biggest area this could be improved would be the logic used when the enemy chooses a different path. It's completely random right now, but checking the current position of the player and heading in that general direction would make it better. The problem is that heading directly to the player isn't always the best path to take. It would be easier to code it if the playfield was always static, but I was looking to do something that would work with any playfield configuration.
Putting in a very complex playfield would probably make this sample code much less effective. The distance traveled when an alternate path is chosen would have to be tweaked, as well as how many turns are taken and how long that routine runs before switching back to the simple "head towards the player" movement. I'll post again when I've had more time to work on it, but I wanted to share what I have so far.
Any thoughts, comments or suggestions would be appreciated.