Maze generation: Difference between revisions
→{{header|EasyLang}}
(Emacs Lisp: Avoid non-portable shebang) |
|||
Line 2,539:
<lang>size = 20
n = 2 * size + 1
endpos = n * n -
startpos =
f = 100 / n
#
Line 2,549:
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
move_pen x * f + f / 2 y * f + f / 2
draw_circle f / 4
.
len m[] n * n
#
set_background 000
func show_maze . .
clear_screen
▲ set_color 000
for i range len m[]
if m[i] = 0
Line 2,561 ⟶ 2,568:
.
call draw_square startpos 900
sleep 0.001
.
offs[] = [ 1 n -1 (-n) ]
func
c
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]
.▼
.
func visited pos . res .
call getposn pos dir posn
if posn <> -1
res += m[posn]
.
.
.
func m_maze pos . .
m[pos] = 0
call show_maze
repeat
call visited pos res
until res = 0
dir = random 4
if posn <> -1 and m[posn] <> 0
m[(pos +
call m_maze posn
.
Line 2,585 ⟶ 2,605:
for i range len m[]
m[i] = 1
▲ .
▲ for i range n
▲ m[i] = 0
.
call m_maze startpos
|