a* neighbor calculations

This commit is contained in:
Baipyrus 2024-01-27 23:55:08 +01:00
parent 4b61a2ed24
commit 14c6eec96f

View File

@ -44,6 +44,17 @@ while (open.length > 0) {
if (!input[ny]) continue; if (!input[ny]) continue;
const next = input[ny][nx]; const next = input[ny][nx];
if (!next || closed.includes(next)) continue; if (!next || closed.includes(next)) continue;
const nd = current.g + next.c;
if (open.includes(next)) {
if (nd < next.g)
next.g = nd;
continue;
}
next.g = nd;
next.h = man_dist(next, end);
open.push(next);
} }
} }
console.log(end.g); console.log(end.g);