30 lines
752 B
Plaintext
30 lines
752 B
Plaintext
import IO;
|
|
import util::Math;
|
|
import List;
|
|
|
|
public void make_maze(int w, int h){
|
|
vis = [[0 | _ <- [1..w]] | _ <- [1..h]];
|
|
ver = [["| "| _ <- [1..w]] + ["|"] | _ <- [1..h]] + [[]];
|
|
hor = [["+--"| _ <- [1..w]] + ["+"] | _ <- [1..h + 1]];
|
|
|
|
void walk(int x, int y){
|
|
vis[y][x] = 1;
|
|
|
|
d = [<x - 1, y>, <x, y + 1>, <x + 1, y>, <x, y - 1>];
|
|
while (d != []){
|
|
<<xx, yy>, d> = takeOneFrom(d);
|
|
if (xx < 0 || yy < 0 || xx >= w || yy >= w) continue;
|
|
if (vis[yy][xx] == 1) continue;
|
|
if (xx == x) hor[max([y, yy])][x] = "+ ";
|
|
if (yy == y) ver[y][max([x, xx])] = " ";
|
|
walk(xx, yy);
|
|
}
|
|
}
|
|
|
|
walk(arbInt(w), arbInt(h));
|
|
for (<a, b> <- zip(hor, ver)){
|
|
println(("" | it + "<z>" | z <- a));
|
|
println(("" | it + "<z>" | z <- b));
|
|
}
|
|
}
|