How to create an adjacency matrix based on a 2D map?

Hello. The problem is the following, there is a map(like the picture). We need to build an adjacency matrix where row 1 is the cell where there is a monster. What kind of algorithm it can be implemented?
5df0fdf46186c923640513.png
April 3rd 20 at 17:31
1 answer
April 3rd 20 at 17:33
Solution
As "portals" is not provided, in any cell you can get a maximum of 4 neighbors.

Number of cells, each go around, count how many of the four neighbors are available – not a wall, not the edge of the map.
Damn, everything just happened. Thank you! - jordon_Haag commented on April 3rd 20 at 17:36

Find more questions by tags AlgorithmsGraphsMathematical matrix