Maze generation: Difference between revisions

Simpler D entry
No edit summary
(Simpler D entry)
Line 992:
=={{header|D}}==
{{trans|Python}}
<lang d>import std.stdio, std.algorithm, std.range, std.random, std.string;
std.string, std.typecons;
 
void main() {
Line 1,004 ⟶ 1,003:
void walk(in int x, in int y) /*nothrow*/ {
vis[y][x] = true;
aliasstatic struct P { Tuple!(uint," x", uint,"y") P; } // will wrap-around
auto d = [P(x-1, y), P(x, y+1), P(x+1, y), P(x, y-1)];
d.randomShuffle();
Line 1,011 ⟶ 1,010:
if (p.x == x) hor[max(y, p.y)][x] = "+ ";
if (p.y == y) ver[y][max(x, p.x)] = " ";
walk(p.x, p.ytupleof);
}
}
walk(uniform(0, w), uniform(0, h));
foreach (a, b; hor.zip(ver ~ []))
writeln(join(a ~ ["+\n"] ~ b).writeln();
}</lang>
{{out}}