- Your closed list logic is a little off. You should test to see if a neighbour is in the closed list, and if it is, ignore it and move on, since the closed list represents tiles you've already visited.
- Similarly, you shouldn't ever be removing entries from the closed list.
- Neither should you be removing the neighbouring squares from the open list in the neighbour checking loop.
- It also seems that if the cost function test fails in the part where you check to see if the neighbour is in the open list, it will end up adding the neighbour to the open list again a little bit later in the code.
- Why do you recalculate the goal square in findBestPath()?
Incidentally, what's your getcost() function look like?