Maze generation: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 2,516: Line 2,516:
[https://easylang.online/apps/_r_maze0.html Run it]
[https://easylang.online/apps/_r_maze0.html Run it]


<syntaxhighlight lang="text">size = 20
<syntaxhighlight lang="text">
size = 20
n = 2 * size + 1
n = 2 * size + 1
endpos = n * n - 2
endpos = n * n - 1
startpos = n + 1
startpos = n + 2
#
#
f = 100 / (n - 0.5)
f = 100 / (n - 0.5)
Line 2,527: Line 2,528:
func show_maze . .
func show_maze . .
clear
clear
for i range len m[]
for i = 1 to len m[]
if m[i] = 0
if m[i] = 0
x = i mod n
x = (i - 1) mod n
y = i div n
y = (i - 1) div n
color 777
color 777
move x * f - f / 2 y * f - f / 2
move x * f - f / 2 y * f - f / 2
Line 2,545: Line 2,546:
m[pos] = 0
m[pos] = 0
call show_maze
call show_maze
d[] = [ 0 1 2 3 ]
d[] = [ 1 2 3 4 ]
for i = 3 downto 0
for i = 4 downto 1
d = random (i + 1)
d = random i
dir = d[d]
dir = d[d]
d[d] = d[i]
d[d] = d[i]
r = pos div n
r = (pos - 1) div n
c = pos mod n
c = (pos - 1) mod n
posn = pos + 2 * offs[dir]
posn = pos + 2 * offs[dir]
if c <> brdc[dir] and r <> brdr[dir] and m[posn] <> 0
if c <> brdc[dir] and r <> brdr[dir] and m[posn] <> 0
Line 2,561: Line 2,562:
.
.
func make_maze . .
func make_maze . .
for i range len m[]
for i = 1 to len m[]
m[i] = 1
m[i] = 1
.
.
Line 2,568: Line 2,569:
.
.
call make_maze
call make_maze
call show_maze</syntaxhighlight>
call show_maze
</syntaxhighlight>


=={{header|EGL}}==
=={{header|EGL}}==