As the title says I have an array representing a 2d grid with walkable/nonwalkable data.
From that array, I want to create a new array with integers representing the number of steps to the nearest nonwalkable node.
What I do now is for every node in the grid to check all the neighbors in a radius of 1,2,3 and so on until we hit a nonwalkable node. But as I need to check all the nodes and multiple neighbors it is slow.
What I want to accomplish is the numbers in the image. Red representing the nonwalkable nodes. Grid example
Is there a fast way of doing this? If it matters I was doing this in c# but if I get an example in any other language I could probably figure it out.