Anonymous user
Maze generation: Difference between revisions
Updated D entry
m (→{{header|REXX}}: changed the displayed (output) maze from 20x20 to 10x10. -- ~~~~) |
(Updated D entry) |
||
Line 1,040:
=={{header|D}}==
<lang d>import std.stdio, std.algorithm, std.range, std.random, std.string;
void main() {
enum int w = 16, h = 8;
▲ alias std.array.replicate R;
auto vis = new bool[][](h, w),
hor = iota(h + 1).map!(_ => R(["+--"], w))().array(),
ver = iota(h).map!(_ => R(["| "], w) ~ "|")().array();
void walk(in int x, in int y) /*nothrow*/ {
vis[y][x] = true;
static struct P { immutable uint x, y; } //
auto d = [P(x-1, y), P(x, y+1), P(x+1, y), P(x, y-1)];
foreach (p; d.randomCover(Random(unpredictableSeed))) {
Line 1,060:
}
walk(uniform(0, w), uniform(0, h));
foreach (a, b;
join(a ~ ["+\n"] ~ b).writeln();
}</lang>
|