# Strange pathfinding issue

Hi,
I am currently working on improving my pathfinding skills… I just started with a non optimized A* algorithm (working with this tutorial: www.policyalmanac.org/games/aStarTutorial.htm) like I did many times before. Normally it worked, now it does in most cases: My rabbit I am testing with does always reach the target but sometimes it takes a strange way I can’t explain why.

As you can see on the screenshots:

This is the path from 0/0 to 40/40

And this is the path from 0/0 to 39/40

I guess the issue is somewhere here:

``````@Override
public void run() {
AStarQuad startQuad = map.getAStarQuad(start);
openList.add(startQuad);

while(!searchFinished()){
AStarQuad current = this.getLowestF(openList);
openList.remove(current);
closedList.add(current);

this.checkQuad(map.getNextQuad(current, 1, 0), current);
this.checkQuad(map.getNextQuad(current, 0, 1), current);
this.checkQuad(map.getNextQuad(current, -1, 0), current);
this.checkQuad(map.getNextQuad(current, 0, -1), current);
this.checkQuad(map.getNextQuad(current, 1, 1), current);
this.checkQuad(map.getNextQuad(current, 1, -1), current);
this.checkQuad(map.getNextQuad(current, -1, 1), current);
this.checkQuad(map.getNextQuad(current, -1, -1), current);

}
if(targetFound()){
ArrayList<Vector2f> pathList = new ArrayList<>();
pathList.add(target);
AStarQuad curr = this.getTarget();
while(curr != null){
pathList.add(new Vector2f(curr.getX(), curr.getY()));
curr = curr.getPrev();
}
Collections.reverse(pathList);
path = new Path(pathList);
}
else
path = new Path(null);

}

private void checkQuad(AStarQuad quad, AStarQuad current){
if(quad.isWalkable() && !closedList.contains(quad)){
quad.H = (int)FastMath.abs(target.x - quad.getX()) + (int)FastMath.abs(target.y - quad.getY());
if(!isInList(quad, closedList)){
if(!isInList(quad, openList))
openList.add(quad);
else{
if(this.getFromList(quad, openList).G > current.G + 14){
openList.remove(this.getFromList(quad, openList));
quad = new AStarQuad(quad.getX(), quad.getY(), quad.isWalkable(), current);
openList.add(quad);
}
}
}

}
}
``````

Thank you in advance for any ideas

This post has no much to do with your question but might help you.

Hi,
that post did not really help me since I try to solve things I think I can handle alone myself.
Actually I found the problem: I did not set the right G value if the quad in the openList is replaced. It’s only 14 for diagonal quads, but 10 for others.