Maze solving: Difference between revisions
→{{header|EasyLang}}
Line 1,437:
<syntaxhighlight lang="text">
size =
n = 2 * size + 1
endpos = n * n - 1▼
startpos = n + 2▼
f = 100 / (n - 0.5)
len m[] n * n
Line 1,452 ⟶ 1,449:
x = (i - 1) mod n
y = (i - 1) div n
color
move x * f - f / 2 y * f - f / 2
rect f * 1.5 f * 1.5
.
.
sleep 0.
.
offs[] = [ 1 n -1 (-n) ]
#
proc m_maze pos . .
Line 1,469 ⟶ 1,464:
for i = 4 downto 1
d = random i
dir = offs[d[d]]
d[d] = d[i]
m[pos + offs[dir]] = 0▼
.
.
.
▲endpos = n * n - 1
▲startpos = n + 2
proc make_maze . .
for i = 1 to len m[]
m[i] = 1
.
m[i] = 2
m[n * i - n + 1] = 2
m[n * n - n + i] = 2
.
call m_maze startpos
m[endpos] = 0
endpos += n
.
call make_maze
Line 1,496:
color col
move x * f + f / 4 y * f + f / 4
circle f /
.
proc solve dir0 pos . found .
call mark pos 900
sleep 0.
if pos = endpos
found = 1
.
▲ for dir = 1 to 4
for
posn = pos
if dir <> dir0 and m[posn]
posn
call solve (dir + 1) mod
if found
sleep 0.08
.
.
.
.
sleep
call solve 0 startpos found
</syntaxhighlight>
|