Guest User

Untitled

a guest
Oct 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. ) Add the starting square (or node) to the open list.
  2.  
  3. 2) Repeat the following:
  4.  
  5. a) Look for the lowest F cost square on the open list. We refer to this as the current square.
  6.  
  7. b) Switch it to the closed list.
  8.  
  9. c) For each of the 8 squares adjacent to this current square …
  10.  
  11. If it is not walkable or if it is on the closed list, ignore it. Otherwise do the following.
  12.  
  13. If it isn’t on the open list, add it to the open list. Make the current square the parent of this square. Record the F, G, and H costs of the square.
  14.  
  15. If it is on the open list already, check to see if this path to that square is better, using G cost as the measure. A lower G cost means that this is a better path. If so, change the parent of the square to the current square, and recalculate the G and F scores of the square. If you are keeping your open list sorted by F score, you may need to resort the list to account for the change.
  16.  
  17. d) Stop when you:
  18.  
  19. Add the target square to the closed list, in which case the path has been found (see note below), or
  20. Fail to find the target square, and the open list is empty. In this case, there is no path.
  21.  
  22. 3) Save the path. Working backwards from the target square, go from each square to its parent square until you reach the starting square. That is your path.
Add Comment
Please, Sign In to add comment