Dijkstra's Algorithm for movement range

 from Red Blob Games
9 Sep 2020

On another page[1] I have a demo of using Breadth First Search to calculate the movement range. This works if movement costs are all 1, either 4-way or 8-way on a square grid. But what if we want diagonal movement to cost 1.5 or √2? Then we need to switch from Breadth First Search to Dijkstra's Algorithm.

{{distanceAt(col, row).toFixed(1)}}

Diagonal cost: {{diagonalCost}}

Distance limit: {{stepLimit}}

Click on a tile to toggle the wall.

Email me , or tweet @redblobgames, or comment: