In a perfect maze, there is one and only one path from any point in the maze to any other point. That is, there are no inaccessible sections, no circular paths, and no open regions.
Viewing a maze as a two-dimensional matrix of square cells, a perfect maze is one in which any two cells are connected by a single unique path. As a consequence of this definition, all cells in a perfect maze are reachable from the starting point by some unique path, meaning that perfect mazes are guaranteed to have a unique solution.
To generate a perfect maze, I ‘ll start with a maze in which all of the possible walls exist (i.e., a wall exists on every side of each cell), then continue removing walls until I have a perfect maze.
Here it is the source code, to be explained very soon.