Newswire
Features
Connection
Job Search
Directories

by Mark Brockington
Gamasutra
June 27, 2000

Printer Friendly Version
   
Discuss this Article

Features

Pawn Captures Wyvern: How Computer Chess Can Improve Your Pathfinding

Listing 2. The Code For The IDA* Algorithm

int IDAStar(position p, int g) {

    /* g = number of steps taken to reach position */
    /* fmax = determined by ComputeMoves */

    int numOfSuccessors;     /* total moves */
    int lb;                  /* lower bound */
    int done;          /* finished search?  */
    int i;                  /* move counter */
    int h;    /* heuristic distance to goal */

    /* Use admissible heuristic to estimate distance */
    /* to the goal nodes.                            */
    h = EstimateDistanceToGoal(p);

    /* Are we at a goal node? */
    if (h == 0) { return TRUE; }
    /* Can we make it to the goal node in time? */
    if (g+h >= fmax) { return FALSE; }

    /* Can't cut off search, search all children */
    numOfSuccessors = GenerateSuccessors(p);
    for (i=1; i <= numOfSuccessors; i++) {
        done = IDAStar(p.succ[i], g+1);
        if (done == TRUE) { return TRUE; }
    }
    return FALSE;
}
________________________________________________________

Back to Article

Home   JoinHelpContact UsShop
 


Home | Join | Help | Contact Us | Shop | Newswire | Site Map
Write for Us | Features | Connection | Job Search | Directories


Copyright © 1999-2000 Miller Freeman Inc. All rights reserved.
Privacy Policy

Miller Freeman Game Group: GDC, GDMag, IGF Independent Games Festival Game Developer Magazine Game Developers Conference