Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Maze-generation/Rascal/maze-generation.rascal
Normal file
29
Task/Maze-generation/Rascal/maze-generation.rascal
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue