Maze generation: Difference between revisions

Content added Content deleted
m (→‎{{header|Sidef}}: modified the code to work with the latest version of Sidef)
Line 5,190: Line 5,190:


# cell is padded by sentinel col and row, so I don't check array bounds
# cell is padded by sentinel col and row, so I don't check array bounds
var cell = (1..h -> map {([true] * w) + [false]} + [[false] * w+1]);
var cell = (1...h -> map {([true] * w) + [false]} + [[false] * w+1]);
var ver = (1..h -> map {["| "] * w });
var ver = (1...h -> map {["| "] * w });
var hor = (0..h -> map {["+--"] * w });
var hor = (0...h -> map {["+--"] * w });


func walk(x, y) {
func walk(x, y) {
Line 5,199: Line 5,199:


var d = [[-1, 0], [0, 1], [1, 0], [0, -1]];
var d = [[-1, 0], [0, 1], [1, 0], [0, -1]];
while (d.len?) {
while (!d.is_empty) {
var i = d.pop_rand;
var i = d.pop_rand;
var (x1, y1) = (x + i[0], y + i[1]);
var (x1, y1) = (x + i[0], y + i[1]);
Line 5,213: Line 5,213:
walk(w.rand.int, h.rand.int); # generate
walk(w.rand.int, h.rand.int); # generate


0...h each { |i|
0...h -> each { |i|
say (hor[i].join('') + '+');
say (hor[i].join('') + '+');
if (i < h) {
if (i < h) {