Maze generation: Difference between revisions

Content added Content deleted
m (→‎{{header|D}}: added start and end)
Line 109: Line 109:


void print() {
void print() {
maze[0][0].m &= ~north;
maze[h-1][w-1].m &= ~east;

for (int r = 0; r < h; r++) {
for (int r = 0; r < h; r++) {
auto hori = appender("");
auto hori = appender("");
auto vert = appender("");
auto vert = appender("");
for (int c; c < w; c++) {
for (int c; c < w; c++) {
if (maze[c][r].m & north) {
if (maze[r][c].m & north) {
if (c == w - 1) hori.put("+---+"); else hori.put("+---");
if (c == w - 1) hori.put("+---+"); else hori.put("+---");
} else {
} else {
if (c == w - 1) hori.put("+ +"); else hori.put("+ ");
if (c == w - 1) hori.put("+ +"); else hori.put("+ ");
}
}
if (maze[c][r].m & west) {
if (maze[r][c].m & east) {
if (c == w - 1) vert.put("| |"); else vert.put("| ");
if (c == 0) vert.put("| |"); else vert.put(" |");
} else {
} else {
if (c == w - 1) vert.put(" |"); else vert.put(" ");
if (c == 0) vert.put("| "); else vert.put(" ");
}
}
}
}
Line 131: Line 134:
}</lang>
}</lang>


<pre>+---+---+---+---+---+---+---+---+---+---+---+
<pre>+ +---+---+---+---+---+---+---+---+---+---+
| | | |
| | | |
+---+---+---+ +---+ + +---+---+ + +
+ +---+ + +---+ +---+---+---+ + +
| | | | |
| | | | | |
+ +---+---+---+ +---+---+---+ +---+ +
+ + +---+---+---+---+---+ +---+---+ +
| | | | | |
| | | | | |
+---+ +---+---+---+---+---+ + + + +
+ +---+---+---+---+---+ + + +---+---+
| | | | | | |
| | | | |
+ + + +---+ +---+ + + +---+---+
+---+ + +---+---+ +---+---+---+---+ +
| | | | | | | | |
| | | |
+ + +---+ + + + + +---+---+ +
+ + +---+---+---+ + +---+---+---+---+
| | | | | | | |
| | | | | | |
+ +---+ +---+---+ +---+---+ + + +
+ +---+ +---+ + +---+---+ + + +
| | | | | | |
| | | | | | | |
+ + +---+ + + +---+ +---+---+ +
+ + +---+ + +---+ + +---+---+ +
| | | | |
| | | |
+---+---+---+---+---+---+---+---+---+---+---+</pre>
+---+---+---+---+---+---+---+---+---+---+---+</pre>