I am learning c# and programming. I have this task to find a path out of a maze.
I have a 2D matrix where:
- 5 - is the end point.
- 3 - is my start point.
- 2 - is the walkable path.
- 1 - is the wall.
I wrote this code:
public static bool PathFinder(MapFile map)
{
for (int y = 0; y < map.height; y++)
{
for (int x = 0; x < map.width; x++)
{
if (map.Matrix[x, y] == 3)
{
map.Matrix[x, y] = 11;
map.start = true;
return map.end;
}
if (map.Matrix[x, y] == 2)
{
map.Matrix[x, y] = 9;
return map.end;
}
if (map.Matrix[x, y] == 1)
{
return map.end;
}
if (map.Matrix[x, y] == 5)
{
map.Matrix[x, y] = 11;
map.end = true;
return map.end;
}
}
}
The problem is that I did not understand how to check if a point on my matrix is a valid path and then walk to the next point.
What should I consider and which direction could I look to try find a solution?
OBS.:
map.start is a boolean that returns true if the start point of the maze was found.
map.end is a boolean that returns true if the end of the maze was found.
The values 9 and 11 are just references I am using to change the color of that point on the console.