I have this maze:
##++##############
##++++++++++++++##
########++########
##++++++++##----##
##++########--####
The "#" symbols are walls in the maze.
The "+" regions of the maze are reachable regions of the maze from the entry point, and the "-" region of the maze are unreachable from the entry point. The entry point is located at the top of the maze.
What I would like to do now is plot a cost of the reachable regions in the maze, which will look like this:
##00##############
##++02++04++06++##
########++########
##++08++06##----##
##10########--####
This shows that the maze has a cost of 10 from entry to exit.
The maze up top is stored in a 2d array and I used recursion to solve the reachable zones. How can I label costs of the paths using my recursive function, which looks like this:
void
flood_fill(m_t * maze, int row, int col) {
// If row,col is outside maze
if ( row < 0 || row >= maze->height || col < 0 || col >= maze->width) return;
// If row,col is not open
if (maze->M[row][col].type != '.') return;
// Mark row,col as part of path.
maze->M[row][col].type = '+';
// Go LEFT
flood_fill(maze, row, col - 1);
// Go DOWN
flood_fill(maze, row + 1, col);
// Go RIGHT
flood_fill(maze, row, col + 1);
// Go UP
flood_fill(maze, row - 1, col);
return;
}
For the first maze, I used this recursive function at the top of the maze, and it flood filled all the reachable cells with "+".
Are there any suggestions as to how I can do something similar to this but with the path costs instead. I'm just looking for some examples or suggestions as to how I might go about it. Any help on how I can go about achieving the second maze example would be helpful.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…