Back
to Richel Bilderbeek's homepage.
Back
to Richel Bilderbeek's Code Snippets.
CountDeadEnds
Counts
all the dead ends in a maze, for example the mazes created by CreateMaze/CreateSloppyMaze.
* View the code of 'CountDeadEnds' in plain text.
//From
http://www.richelbilderbeek.nl/CppCountDeadEnds.htm
const int
CountDeadEnds(const
std::vector<std::vector<int> >& maze)
{
int nDeadEnds = 0;
{
{
if (maze[y][x] != 0) continue; //Continue if here is a wall
= (maze[y+1][x ] == 1 ? 1 : 0)
+ (maze[y-1][x ] ==
1 ? 1 : 0)
+ (maze[y ][x+1] ==
1 ? 1 : 0)
+ (maze[y ][x-1] ==
1 ? 1 : 0);
if (nWalls == 3) ++nDeadEnds;
}
}
return nDeadEnds;
}
Back
to Richel Bilderbeek's Code Snippets.
Back
to Richel Bilderbeek's homepage.