Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,36 +1,36 @@
|
|||
function maze(x,y) {
|
||||
var n=x*y-1;
|
||||
if (n<0) {alert("illegal maze dimensions");return;}
|
||||
var horiz=[]; for (var j= 0; j<x+1; j++) horiz[j]= [];
|
||||
var verti=[]; for (var j= 0; j<y+1; j++) verti[j]= [];
|
||||
var here= [Math.floor(Math.random()*x), Math.floor(Math.random()*y)];
|
||||
var path= [here];
|
||||
var unvisited= [];
|
||||
for (var j= 0; j<x+2; j++) {
|
||||
unvisited[j]= [];
|
||||
var horiz =[]; for (var j= 0; j<x+1; j++) horiz[j]= [],
|
||||
verti =[]; for (var j= 0; j<y+1; j++) verti[j]= [],
|
||||
here = [Math.floor(Math.random()*x), Math.floor(Math.random()*y)],
|
||||
path = [here],
|
||||
unvisited = [];
|
||||
for (var j = 0; j<x+2; j++) {
|
||||
unvisited[j] = [];
|
||||
for (var k= 0; k<y+1; k++)
|
||||
unvisited[j].push(j>0 && j<x+1 && k>0 && (j != here[0]+1 || k != here[1]+1));
|
||||
}
|
||||
while (0<n) {
|
||||
var potential= [[here[0]+1, here[1]], [here[0],here[1]+1],
|
||||
var potential = [[here[0]+1, here[1]], [here[0],here[1]+1],
|
||||
[here[0]-1, here[1]], [here[0],here[1]-1]];
|
||||
var neighbors= [];
|
||||
for (var j= 0; j < 4; j++)
|
||||
var neighbors = [];
|
||||
for (var j = 0; j < 4; j++)
|
||||
if (unvisited[potential[j][0]+1][potential[j][1]+1])
|
||||
neighbors.push(potential[j]);
|
||||
if (neighbors.length) {
|
||||
n= n-1;
|
||||
n = n-1;
|
||||
next= neighbors[Math.floor(Math.random()*neighbors.length)];
|
||||
unvisited[next[0]+1][next[1]+1]= false;
|
||||
if (next[0] == here[0])
|
||||
horiz[next[0]][(next[1]+here[1]-1)/2]= true;
|
||||
else
|
||||
verti[(next[0]+here[0]-1)/2][next[1]]= true;
|
||||
path.push(here= next);
|
||||
path.push(here = next);
|
||||
} else
|
||||
here= path.pop();
|
||||
here = path.pop();
|
||||
}
|
||||
return ({x: x, y: y, horiz: horiz, verti: verti});
|
||||
return {x: x, y: y, horiz: horiz, verti: verti};
|
||||
}
|
||||
|
||||
function display(m) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue