Maze generation: Difference between revisions

Simpler D entry
(Updated D entry)
(Simpler D entry)
Line 1,553:
import std.stdio, std.algorithm, std.range, std.random;
 
enum intuint w = 14, h = 10;
auto vis = new bool[][](h, w),
hor = iota(h + 1).map!(_ => ["+---"].replicate(w)).array,
ver = h.iota.map!(_ => ["| "].replicate(w) ~ "|").array;
 
void walk(in intuint x, in intuint y) /*nothrow*/ {
vis[y][x] = true;
foreach (p; [[x-1,y], [x,y+1], [x+1,y], [x,y-1]].randomCover) {
static struct P { immutable uint x, y; } // Will wrap-around.
auto d = [P(x-1, y),if P(x,p[0] y+1),>= P(x+w || p[1,] y),>= P(x,h y-|| vis[p[1)]][p[0]]) continue;
foreach if (p;[0] d.randomCover== x) {hor[max(y, p[1])][x] = "+ ";
if (p.x[1] >== w || p.y) >= h || visver[p.y][p.max(x, p[0])] = " continue";
if walk(p.x == x) hor[max(y0], p.y)][x1] = "+ ");
if (p.y == y) ver[y][max(x, p.x)] = " ";
walk(p.tupleof);
}
}