Question

I'm remaking an old warcraft 3 custom game that I used to play way back when and putting it on the iphone. Basically, you have a set amount of time to build a maze out of a set amount of blocks, and the longer it takes the creep to run the maze, the more points you get.

I'm doing this all in airplay with cocos2d, and right now I'm putting in the a* pathfinding algorithm. I'm using Justin Heyes-Jones' implementation and working on the node class right now.

However, a couple things are confusing me. The class looks like this:

class MapSearchNode
{
public:
    unsigned int x;  // the (x,y) positions of the node
    unsigned int y; 


    MapSearchNode() { x = y = 0; }
    MapSearchNode( unsigned int px, unsigned int py ) { x=px; y=py; }

    bool IsGoal( MapSearchNode &nodeGoal ) { return (x == nodeGoal.x && y == nodeGoal.y); }
    bool IsSameState( MapSearchNode &rhs ) { return (x == rhs.x && y == rhs.y); }

    float GoalDistanceEstimate( MapSearchNode &nodeGoal );
    float GetCost( MapSearchNode &successor );
    bool GetSuccessors( AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node );

    //void PrintNodeInfo();
};

I'm just not sure what GetCost means. In this example maze, where X's are walls and _'s are walkable areas, would the cost of going from (3, 1) to (3, 2) be 0? And then what would the cost of going from (3, 1) to (4, 1), since it's impossible?

X X _ X X
X _ _ X X
X _ X X X
X _ _ _ _
X X X X X

And then I guess I can just implement GoalDistanceEstimate by using the distance formula, correct?

Was it helpful?

Solution

The general A* is based on a weighted graph. In practical maze solving applications, all edges have the same finite weight (usually 1) for passable terrain and infinite (written as a very large number, just use 100000 or something) for impassable terrain.

OTHER TIPS

To my understanding, the cost was the "combined total" that determined the "fastest path". The cost is added to for every square or node that they have to go to. This can also include things such as terrain limitations (such as slowing you down etc.).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top