Basically, you have a heuristic value, a move cost, and a total cost. For every passable tile (assuming you have tiles) you find the heuristic, this can be done using the Manhattan method. It is the difference in x plus the difference in y from the start to the end. You then set the move cost, this can be done however you like, lets say all linear movements (up, down, left, and right) have a cost of 10, and all non linear (diagonal) movements have a cost of 20, basically that means is costs twice as much to move diagonal as it does to move linear. Now, the total cost is the movement cost plus the heuristic. You want to make a list of all tiles (open list) that are touching you (except the one you are on, add this to a 'closed' list), these are the tiles to set the values for, when you move to the one with the lowest value, clear the open list and add the new tile to the closed list. Repeat. Remember, if your tiles are not moving, you can calculate the heuristic before hand, and not have to re calculate. I hope I have explained this well enough.
No comments:
Post a Comment