A* Pathfinding Algorithm (Coding Challenge 51 - Part 1)

The Coding Train · 3.4M views · 2017 · 48:42

Open on YouTube

Algorithms & data structuresCreative coding & generative artGame programming & enginestutorial

Why Stack Overflow recommends it

Stack Overflow users link it when they are building their own A* visualizations on a grid and want a step-by-step walkthrough of the algorithm to follow or adapt.

Recommended by 0 people across 0 different months, 2017 to 2022.

What it is

Daniel Shiffman of The Coding Train implements the A* pathfinding algorithm live in p5.js, finding the optimal route between two points on a 2D grid. He builds the grid, open and closed sets, neighbor search, a heuristic and the path trace-back step by step over about 48 minutes.

What people said

Cites ekim420 · 2017-11 · Stack Overflow · on “How to click on a Cell object?”

I'm using Javascript, p5.js, and Daniel Shiffman's tutorial [this video] to create a visual representation of an A* search algorithm. An image of an example grid looks like this: example grid [LINK] Is it possible to click on any cell of the grid, in order to print out it's attributes? Based on Daniel Shiffman's other tutorial on how to click on objects [LINK] , I understand I have to create 2 functions that activate and execute respectively. I understand how to do this with a circle because a circle has a radius. But, I don't understand how to do this with a cell because I only have it's coordinates. I can't see how to use coordinates as a metric to calculate length. I'd appreciate any guidance

Cites Sumeet · 2018-03 · Stack Overflow · on “dijkstra algorithm, run only one time for shortest paths of some nodes (not two, not the whole graph)”

First of all Dijkstra is not the best algorithm and many heuristics outperform it in most practical implementations. we are only interested in the shortest paths of A,B ; C,K Looks like you could take a look at A* [this video] algorithm which eliminates the nodes that will not lead you to your final destination with least cost. But it requires a good estimation (and hence the word heuristic) of the distances of various nodes to the destination. Coming to your main question, the answer is both yes and no with some overheads. We all know that whenever a node gets removed from the min-heap its done for the algorithm. So, as soon as your node gets removed from the min-heap, just terminate it, but tha

Cites borbzo · 2022-08 · Stack Overflow · on “Javascript - get neighbor cells in a 2D array?”

I've been trying to follow this tutorial: [this video] However, I'm using vanilla Javascript. I'm struggling to get the neighboring cells for each cell in my grid. I'm pretty new to coding so help would be very much appreciated! Here is my code so far: //GLOBAL VARIABLES const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const wh = 600; const cellSize = 30; const rows = 20; const cols = 20; const grid = new Array(rows); const open = []; const closed = []; let start; let end; //FUNCTIONS //Immediately-invoked function expression //Runs code immediately when the page loads and keeps it out of the global scope (avoids naming conflicts) (function() { setup(); })();