### Astar Problems

I'm currentlying making an AIAgent class that uses astar to path find but i think i messed up on my astar function could some be amazing and have a look at my function and point out where i'm going wrong i'm at a loss as to where i went wrong =D
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128`` ``````vector Pathfinder::aStar(float x1, float y1, float x2, float y2) { vector path; m_pPoints->walkable = true; // Define points to work with Points *start = getPointFromCoord(x1, y1); Points *end = getPointFromCoord(x2, y2); Points *current; Points *child; // Define the open and the close list list openList; list closedList; list::iterator i; unsigned int n = 0; // Add the start point to the openList openList.push_back(start); start->opened = true; while (n == 0 || (current != end && n < 20)) { // Look for the smallest F value in the openList and make it the current point for (i = openList.begin(); i != openList.end(); ++ i) { if (i == openList.begin() || (*i)->getFScore() <= current->getFScore()) { current = (*i); } } // Stop if we reached the end if (current == end) { break; } // Remove the current point from the openList openList.remove(current); current->opened = false; // Add the current point to the closedList closedList.push_back(current); current->closed = true; // Get all current's adjacent walkable points for (int x = 5; x < 10; x ++) { for (int y = 5; y < 10; y ++) { // If it's current point then pass if (x == 0 && y == 0) { continue; } // Get this point child = getPoint(current->getX() + x, current->getY() + y); // If it's closed or not walkable then pass if (child->closed || !child->walkable) { continue; } // If we are at a corner, do a barrel roll if (x != 0 && y != 0) { // if the next horizontal point is not walkable or in the closed list then pass if (!pointIsWalkable(current->getX(), current->getY() + y) || getPoint(current->getX(), current->getY() + y)->closed) { continue; } // if the next vertical point is not walkable or in the closed list then pass if (!pointIsWalkable(current->getX() + x, current->getY()) || getPoint(current->getX() + x, current->getY())->closed) { continue; } } // If it's already in the openList if (child->opened) { // If it has a worse g score than the one that pass through the current point // then its path is improved when it's parent is the current point if (child->getGScore() > child->getGScore(current)) { // Change its parent and g score child->setParent(current); child->computeScores(end); } } else { // Add it to the openList with current point as parent openList.push_back(child); child->opened = true; // Compute it's g, h and f score child->setParent(current); child->computeScores(end); } } } n ++; } // Reset for (i = openList.begin(); i != openList.end(); ++ i) { (*i)->opened = false; } for (i = closedList.begin(); i != closedList.end(); ++ i) { (*i)->closed = false; } // Resolve the path starting from the end point while (current->hasParent() && current != start) { path.push_back(current->getPosition()); current = current->getParent(); n ++; } return path; } ``````
Topic archived. No new replies allowed.