[0] https://imgur.com/a/AvUMxLQ
edit: Just wanted to add in case this is more of a frontend demo than a pathfinder demo, it does look beautiful and the search animation is more intuitive than similar demos I've seen. And runs fine on my phone.
It's just that (unlike the other 3 algorithms) DFS doesn't guarantee to find the shortest path, just a path.
Not a problem on mazes with only one solution, but problematic when there are multiple solutions (or near-infinite solutions on an empty map)
This nerd-sniped me so I dug into the code, it's because it uses the non-recursive approach but it has an extra step of not adding neighbors to the stack if they've already been added previously. So you get this staggered line search because it avoids searching any tiles adjacent to a previously searched tile unless there are no other options. Decent optimization and still technically a DFS, it's just not the textbook example.
untraversedTiles.sort((a, b) => {
if (heuristicCost[a.row][a.col] < heuristicCost[b.row][b.col]) {
return-1;
}
return 1;
});https://stackoverflow.com/questions/74331904/racing-javascri...