Advertisement
illlitr8

Pseudokod A*

Dec 2nd, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. input: tile[] map;
  2. intpair start;
  3. intpair goal;
  4. //intpair är en struct med två ints, kostar mindre än vector2 (floats tar mer minne)
  5.  
  6. list<tile> open = new list<tile>();
  7. list<tile> closed = new list<tile>();
  8.  
  9. open.add(map[start.x, start.y])
  10.  
  11. while(open.count > 0)
  12. {
  13.     tile current = open[0];
  14.     if(current == goal)
  15.     {
  16.         //skriv pathen här, return
  17.     }
  18.     open.remove(current);
  19.     closed.add(current);
  20.     foreach neighbour of current
  21.         if neighbour not in open, not in closed and not solid
  22.         neighbour.parent = current
  23.         neighbour.g = current.g + (diagonal/orthogonal kostnad)
  24.         neighbour.h = //fågelvägen till goal
  25.         neighbour.f = neighbour.g + neighbour.h
  26.         open.add(neighbour)
  27.     sort open by f (ascending)
  28. }
  29. return null; //not found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement