Avoid macros. Replace
#define N 6 with
constexpr int N = 6;.
N is not a very descriptive name; you should give it a better one (
MAZE_SIZE). You’re also using this for both dimensions of the maze, which limits you to square mazes.
operator= should not return a const reference.
Cell::walls is a map that stores a
bool, you could replace it with a
set, and use the presence of the key in the set as the value.
Rather than using short strings for things like direction, you could use an enum type. This would save space and improve performance.
Cell::direction can be a const function (
std::string Cell::direction( const Cell &other ) const).
You could add an
setxy function to
Cell, and use that in the
Grid constructor (
grids( i )( j ).init(x, y);).
Grid::get_all_neighbors can also be a const member function. You can get rid of
co_ordinates by using
When checking a bool value, you don’t need to use
==, you can check it directly. To check for false, you can use the
!grids( i )( j - 1 ).visited.
There are a couple of duplicated conditions in
get_all_neighbors. This function can be rewritten with nested
if statements to remove them. This would also improve the readability just a bit.
In a lot of your
for loops, your comparison uses
!=. While that works here, more common is to use
< comparison is essential when using something like OpenMP to add multithreading.
body variable can be moved outside of the for loop. This will avoid repeatedly creating and destroying it.
generate_maze uses a hardcoded
6 as a starting cell. This should be a constant somewhere (defined next to
N), or should be some fraction of
N. You seem to be using
current_cell just to hold
y values. You can use either a smaller coordinate class, or a pair, to manipulate these. By using the full
Cell object you’re copying around a lot of (empty) maps and stacks.
rand is not a very good source of random numbers. Look into the facilities provided by the