Skip to main content

Pathfinding

  • click to interact
  • source: examples/src/04-space/pathfinding.ts

Breadth-first search#

Dijkstra#

A-Star#

  • algorithm:
let f be a priority of a nodelet g be a cost from the origin to the current nodelet h be an estimated cost from the current node to the targetlet n1 be the first nodelet n2 be the target nodelet F be a priority queue
1. create queue F2. insert n1 into F3. until F is empty    a) let q be a node of the lowest priority f    b) take q from F    c) for each neighbour s of q        if s = n2, finish                let new_cost be q.g + estimation(s, q)        if(new_cost >= s.g) goto c)                s.g = q.g + estimation(s, q)        s.h = estimation(s, n2)                s.f = s.g + s.h                if there is another node s in the queue F which is of a lower priority than s.f, goto c)                put s into F, setting the priority to s.f        goto c)    end    goto 3

A-Star octile manhattan#

A-Star octile euclidean#

A-Star with optimistic heuristics#

A-Star with pessimistic heuristics#