By using this site, you agree to our Privacy Policy and our Terms of Use. Close

Here's a better Fibonnacci:

int Fib(int n)
{
    if (n <= 2)
return 1;
    int prev = 1, prev2 = 1;
    for (i = 3; i <= n; i++)
    {
       int temp = prev + prev2;
       prev2 = prev;
       prev = temp;
    }
    return prev;
}

Try that one on n = 50 and see if it takes you 4 minutes.  It should take a very small fraction of a second -- you should be able to run it on very large n rather quickly (though the int will overflow pretty quickly).

The above example is to show that problems that are recursively defined don't always have to be programmed recursively to get the right answer.  The AI routines you're referring to, such as calculating line of sight, deciding what to do when a bomb explodes, deciding how closely to follow the car in front of them, etc. are not problems that require recursive programming.  Most of what we think of as "game AI" is just a big decision making tree.  This is not a process that should require an exponential amount of work as the number of possible decisions or factors increases.