Maze generation: Difference between revisions

Javascript: added a small bit of documentation
m (Switch from draft to complete task)
(Javascript: added a small bit of documentation)
Line 118:
if (0 == k%4)
line[k]= '+';
else {
if (j>0 && m.verti[j/2-1][Math.floor(k/4)])
line[k]= ' ';
else
line[k]= '-';
}
else
for (var k=0; k<m.y*4+1; k++)
if (0 == k%4) {
if (k>0 && m.horiz[(j-1)/2][k/4-1])
line[k]= ' ';
else
line[k]= '|';
} else
line[k]= ' ';
if (0 == j) line[1]= line[2]= line[3]= ' ';
Line 139 ⟶ 138:
return text.join('');
}</lang>
 
Variable meanings in function <code>maze</code>:
 
# <code>x</code>,<code>y</code> -- dimensions of maze
# <code>n</code> -- number of openings to be generated
# <code>horiz</code> -- two dimensional array of location of horizontal openings
# <code>verti</code> -- two dimensional array of location of vertical openings
# <code>here</code> -- current location under consideration
# <code>path</code> -- history (stack) of locations that might need to be revisited
# <code>unvisited</code> -- two dimensional array of locations that have not been visited (padded to avoid need for boundary tests)
# <code>potential</code> -- locations adjacent to <code>here</code>
# <code>neighbors</code> -- unvisited locations adjacent to <code>here</code>
 
Variable meanings in function <code>display</code>:
# <code>m</code> -- maze to be drawn
# <code>text</code> -- lines of text representing maze
# <code>line</code> -- text of current line
 
Example use:
6,962

edits