Maze Game Pathfinding AI

G'day guys,

I'm developing a maze-game (think Pacman, etc.) in Unity, and have now created a maze that can be navigated by the player, and now I am working on AI.

My AI has two 'modes' - 'Pursuit' and 'Patrol'. 'Patrol' is complete and I'm satisfied with it; the AI-Controlled character moves about the maze picking random directions, but of course doesn't double back the way it came (it would look absurd).

Now I'm developing 'Pursuit' mode. I've build a very rudimentary system, which you can see below, that uses the game's array-driven navigation to make the AI move north (if possible) if the player is indeed north of it, south if the player is south etc.

This works pretty well, to be honest, for its simplicity. But alas it is, of course, possible to 'trap' this simpleton AI by hiding in a position (such as a corner) where both horizontally and vertically it isn't possible to get closer to you. I tried (as you can see) to tell it to, in this situation, go to 'Patrol' mode for 1 'movement', but once it does this of course it sees the old 'corner' position as an attractive option.

I'm expecting that I'll have to take quite some time to study the A* algorithm and write my own Unity implementation (all links to the wiki script version are broken for some reason) as I know it's probably best to learn to do it myself, as so far - despite using these forums/questions to learn from other developers - I've avoided using other people's scripts as there is no benefit in using something I don't understand.

At any rate, I was wondering if anybody had any suggestions that might allow me to avoid writing a lengthy and (to me at least) complicated A* system?

function PursuitAI (){
        playerRow = gridPlayerCharlie.rowIndex;
        playerCol = gridPlayerCharlie.colIndex;

        var randomDirection  = (Random.Range(1, 5));

        oldDirection = realBearing;

        if (playerRow > rowIndex && north == true){
            desiredBearing = 'North';
        } else if (playerRow < rowIndex && south == true){
            desiredBearing = 'South';
        } else if (playerCol > colIndex && east == true){
            desiredBearing = 'East';
        } else if (playerCol < colIndex && west == true){
            desiredBearing = 'West';
        } else {PatrolAI();}
    }

A simple flood-fill algorithm would work. See the code in the project here.