Here is an example that shows how to get a sprite to wander around a tile-map maze endlessly. (without getting stuck)
The turn conditions are the collision offsets. When it gets to a horizontal wall it chooses a vertical angle. When it comes to a vertical wall it changes to a horizontal angle.
hope it comes in useful for someone