Maze generation: Difference between revisions
Content added Content deleted
(Shorter first D version) |
(Simpler D version) |
||
Line 814:
enum int w = 16, h = 8;
alias std.array.replicate R;
auto
auto ver = array(map!((_){ return R(["|
auto vis = new bool[][](h, w);
void walk(in int x, in int y) /*nothrow*/ {
vis[y][x] = true;
alias 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)];
randomShuffle(d);
foreach (p; d) {
Line 834 ⟶ 832:
walk(uniform(0, w), uniform(0, h));
foreach (a, b; lockstep(hor, ver ~ []))
writeln(join(a ~ ["+\n"] ~ b));
}</lang>
Output example:
|