Maze generation: Difference between revisions

Content added Content deleted
Line 2,541: Line 2,541:
endpos = n * n - 2
endpos = n * n - 2
startpos = n + 1
startpos = n + 1
f = 100 / n
#
#
f = 100 / (n - 0.5)
func draw_square pos col . .
x = pos mod n
y = pos div n
set_color col
move_pen x * f y * f
draw_rect f * 1.05 f * 1.05
.
func mark pos . .
x = pos mod n
y = pos div n
set_color 900
move_pen x * f + f / 2 y * f + f / 2
draw_circle f / 4
.
len m[] n * n
len m[] n * n
#
#
Line 2,564: Line 2,550:
for i range len m[]
for i range len m[]
if m[i] = 0
if m[i] = 0
call draw_square i 777
x = i mod n
y = i div n
set_color 777
move_pen x * f - f / 2 y * f - f / 2
draw_rect f * 1.5 f * 1.5
.
.
.
.
call draw_square startpos 900
sleep 0.001
sleep 0.001
.
.
Line 2,577: Line 2,566:
if dir = 0 and c <> n - 2 or dir = 1 and r <> n - 2 or dir = 2 and c <> 1 or dir = 3 and r <> 1
if dir = 0 and c <> n - 2 or dir = 1 and r <> n - 2 or dir = 2 and c <> 1 or dir = 3 and r <> 1
posn = pos + 2 * offs[dir]
posn = pos + 2 * offs[dir]
.
.
func visited pos . res .
res = 0
for dir range 4
call getposn pos dir posn
if posn <> -1
res += m[posn]
.
.
.
.
.
Line 2,591: Line 2,571:
m[pos] = 0
m[pos] = 0
call show_maze
call show_maze
d[] = [ 0 1 2 3 ]
repeat
call visited pos res
for i = 3 downto 0
until res = 0
d = random (i + 1)
dir = random 4
dir = d[d]
d[d] = d[i]
call getposn pos dir posn
call getposn pos dir posn
if posn <> -1 and m[posn] <> 0
if posn <> -1 and m[posn] <> 0