Maze generation: Difference between revisions

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][c.c]; // n
}
if (c.c != 0) {
nbrs ~= maze[c.r][c.c - 1][c.r]; // w
}
if (c.r != h - 1) {
nbrs ~= maze[c.c][c.r + 1][c.c]; // s
}
if (c.c != w - 1) {
nbrs ~= maze[c.r][c.c + 1][c.r]; // e
}
}
Line 76 ⟶ 75:
n.m |= visited;
breakWall(c, n);
maze[c.rc][c.cr] = c;
maze[n.rc][n.cr] = n;
stack ~= c;
c = n;
Line 84 ⟶ 83:
 
// setup
maze = new cell[][](hw, wh);
for (int r = 0; r < h; r++)
for (int c = 0; c < w; c++)
maze[rc][cr] = cell(c, r, north|east|south|west);
cell[] nbrs;
cell[] stack;
cell c = maze[uniform(0, hw)][uniform(0, wh)];
c.m |= visited;
setNeighbors(c, nbrs);
Line 113 ⟶ 112:
auto vert = appender("");
for (int c; c < w; c++) {
if (maze[rc][cr].m & north) {
if (c == w - 1) hori.put("+---+"); else hori.put("+---");
} else {
if (c == w - 1) hori.put("+ +"); else hori.put("+ ");
}
if (maze[rc][cr].m & west) {
if (c == w - 1) vert.put("| |"); else vert.put("| ");
} else {
Anonymous user