iphone app - maze solving
<p>I'm working on an iphone game with a bunch of mazes,
and there's this villain who chases you within the maze.</p>

<p>I'm not using OpenGL ES nor tile map,
so currently collision detection is performed by the xcode's CGRectsIntersectsRect function with each wall being an IB variable, kind of like this:</p>

<pre><code>    float hunterdiffx = abs(hunter.center.x - hunterDest.x);
float hunterdiffy = abs(hunter.center.y - hunterDest.y);

if((hunterdiffx!=0.0)&amp;&amp;(hunterdiffx&gt;(1.0*diffy))&amp;&amp;(!hunterCollided)){
    //NSLog(@"diffx &gt;");
    hunterVel.y = 0;
    if(hunterDest.x&gt;(hunter.center.x+3)){
        //NSLog(@"x &gt;");
        hunterVel.x = 3;
    }
    else if(hunterDest.x&lt;(hunter.center.x-3)){
        //NSLog(@"x &lt;");
        hunterVel.x= -3;
    }
    //when rabbit reaches the destination
    else if((hunter.center.x&gt;(hunterDest.x-3)) &amp;&amp; (hunter.center.x &lt; (hunterDest.x+3))){
        //NSLog(@"x =");
        //NSLog(@"one side reach");
        hunterVel.x = 0;
        hunterVel.y = 0;
    }
}
</code></pre>

<p>......</p>

<pre><code>if(CGRectIntersectsRect(hunter.frame, border1.frame){
 hunterCollided = TRUE;

    if(hunterVel.x==0){

        NSLog(@"vertical collision");
        if(hunterVel.y&gt;0){
            hunter.center = CGPointMake(hunter.center.x, hunter.center.y -10);
        }
        if(hunterVel.y&lt;0){
            hunter.center = CGPointMake(hunter.center.x, hunter.center.y +10);
        }
        hunterVel.y=0;
        if(hunterDest.x &gt; hunter.center.x){
            hunterVel.x=3;
        }
        if(hunterDest.x &lt; hunter.center.x){
            hunterVel.x=-3;
        }
      }
..............
}
</code></pre>

<p>This, as expected, leads to a very stupid behavior of the hunter, and now I'm wondering, since I'm not using tile map and cannot just use arrays to represent hunter's tries, could there be any algorithmic approach that lets the hunter find the right path within the maze?
I've struggled with a lot of math, and my brain is now mal-functioning...</p>

<p>Please help me if you have any idea.</p>
