Loading…
Loading…
Always expands the node that looks closest to the goal by heuristic alone. Very fast and targeted, but its path is not guaranteed to be shortest.
Seed the open set with the start.
1open.add(new int[]{h(start), start}); queued[start] = true;2while (!open.isEmpty()) {3 int node = open.poll()[1];4 if (visited[node]) continue;5 if (node == goal) return buildPath();6 visited[node] = true;7 for (int nb : neighbors(node))8 if (!visited[nb] && !queued[nb]) {9 parent[nb] = node; queued[nb] = true;10 open.add(new int[]{h(nb), nb});11 }12}