# A Star

Recently I’ve found a nice piece of pseudo code for implementing A Star after searching through a few lesser or incorrect pseudo code passages:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
clear open and closed let s be start node let e be end node s.loc = startloc s.g = 0 s.h = Cost( s, e ) push s to open while open not empty q = pop lowest f in open if q == e traverse backpath of q.parent return success for each successor p g = q.g + GridCost( q, p ) if ( p is open or closed ) if ( p.g <= g ) continue p.parent = q p.g = g p.h = Cost( p, e ) p.f = g + p.h if ( p is closed ) p.closed = false if ( p is open ) re-sort open else push p to open return failure |

My favorite thing about the pseudo code is that the closed list can be implemented with just a flag. The open list becomes the most Continue Reading →