DFS. NxN, , :
function generateMaze(&$maze, $point) {
$dirs = [
[0,-1],
[1,0],
[0,1],
[-1,0],
];
shuffle($dirs);
foreach($dirs as $dir) {
$newPoint = [$point[0] + $dir[0], $point[1] + $dir[1]];
if (isGoodPath($maze, $newPoint)) {
$maze[$newPoint[0]][$newPoint[1]] = '.';
generateMaze($maze, $newPoint);
}
}
return $maze;
}
isGoodPath(), , , ( "" )
: https://ideone.com/oufifB
25x25:
.
.
. .
.
. .
. .
.
. . .
. . .
. . .
.
. .
.
. .
. .
. .
" " , .