Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input: tile[] map;
- intpair start;
- intpair goal;
- //intpair är en struct med två ints, kostar mindre än vector2 (floats tar mer minne)
- list<tile> open = new list<tile>();
- list<tile> closed = new list<tile>();
- open.add(map[start.x, start.y])
- while(open.count > 0)
- {
- tile current = open[0];
- if(current == goal)
- {
- //skriv pathen här, return
- }
- open.remove(current);
- closed.add(current);
- foreach neighbour of current
- if neighbour not in open, not in closed and not solid
- neighbour.parent = current
- neighbour.g = current.g + (diagonal/orthogonal kostnad)
- neighbour.h = //fågelvägen till goal
- neighbour.f = neighbour.g + neighbour.h
- open.add(neighbour)
- sort open by f (ascending)
- }
- return null; //not found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement