Anonymous user
Maze generation: Difference between revisions
→{{header|D}}
m (→{{header|D}}) |
|||
Line 16:
enum {visited = 1, north = 2, east = 4, south = 8, west = 16};
struct cell { int c, r, m; }▼
const w = 11, h = 8;
▲struct cell { int c, r, m; }
cell[][] maze;
Line 55 ⟶ 54:
nbrs.length = 0;
if (c.r != 0) {
nbrs ~= maze[c.c][c.r - 1
}
if (c.c != 0) {
nbrs ~= maze
}
if (c.r != h - 1) {
nbrs ~= maze[c.c][c.r + 1
}
if (c.c != w - 1) {
nbrs ~= maze
}
}
Line 76 ⟶ 75:
n.m |= visited;
breakWall(c, n);
maze[c.
maze[n.
stack ~= c;
c = n;
Line 84 ⟶ 83:
// setup
maze = new cell[][](
for (int r = 0; r < h; r++)
for (int c = 0; c < w; c++)
maze[
cell[] nbrs;
cell[] stack;
cell c = maze[uniform(0,
c.m |= visited;
setNeighbors(c, nbrs);
Line 113 ⟶ 112:
auto vert = appender("");
for (int c; c < w; c++) {
if (maze[
if (c == w - 1) hori.put("+---+"); else hori.put("+---");
} else {
if (c == w - 1) hori.put("+ +"); else hori.put("+ ");
}
if (maze[
if (c == w - 1) vert.put("| |"); else vert.put("| ");
} else {
|