Maze solving: Difference between revisions

Line 1,437:
 
<syntaxhighlight lang="text">
size = 2015
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 777999
move x * f - f / 2 y * f - f / 2
rect f * 1.5 f * 1.5
.
.
sleep 0.00101
.
offs[] = [ 1 n -1 (-n) ]
brdc[] = [ n - 2 -1 1 -1 ]
brdr[] = [ -1 n - 2 -1 1 ]
#
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]
rif m[pos + dir] = (1 and m[pos -+ 1)2 * dir] div<> n0
c = ( m[pos -+ 1)dir] mod= n0
posn = call m_maze pos + 2 * offs[dir]
if c <> brdc[dir] and r <> brdr[dir] and m[posn] <> 0
posn = pos + 2 * offs[dir]
m[pos + offs[dir]] = 0
call m_maze posn
.
.
.
endpos = n * n - 1
startpos = n + 2
proc make_maze . .
for i = 1 to len m[]
m[i] = 1
.
for diri = 1 to 4n
m[i] = 2
m[posn +* offs[dir]i] = 02
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 / 42.5
.
proc solve dir0 pos . found .
call mark pos 900
sleep 0.0508
if pos = endpos
found = 1
else break 1
.
for dir = 1 to 4
for posndir = pos1 +to offs[dir]4
posn = pos if+ offs[dir <> dir0 and m[posn] = 0 and found = 0
if dir <> dir0 and m[posn] call= solve0 (dirand +found 1)= mod 4 + 1 posn found0
posn if found += 0offs[dir]
call solve (dir + 1) mod call4 + mark1 posn 777found
if found sleep= 0.05
.call mark posn 777
sleep 0.08
.
.
.
.
sleep 21
call solve 0 startpos found
</syntaxhighlight>
2,069

edits