Maze solving: Difference between revisions
→{{header|EasyLang}}
(Emacs Lisp: Avoid non-portable shebang) |
|||
Line 1,438:
<lang>size = 20
n = 2 * size + 1
endpos = n * n -
startpos =
f = 100 / n
#
Line 1,458:
len m[] n * n
#
set_background 000
func show_maze . .
clear_screen
for i range len m[]
if m[i] = 0
Line 1,467:
.
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 1,491 ⟶ 1,504:
for i range len m[]
m[i] = 1
▲ .
▲ for i range n
▲ m[i] = 0
.
call m_maze startpos
Line 1,522 ⟶ 1,529:
call make_maze
call show_maze
sleep
call solve -1 startpos found</lang>
|