Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
BFS + deque solution in Clear category for Open Labyrinth by spoty
from collections import deque
def checkio(maze_map, start=(1, 1), goal=(10, 10)):
def get_adjacent(n):
x, y = n
n = [(x - 1, y, "N"), (x, y - 1, "W"),
(x + 1, y, "S"), (x, y + 1, "E")]
return [((x, y), c) for x, y, c in n if maze_map[x][y] != 1]
q, v = deque([(start, "")]), set()
while q:
cords, path = q.popleft()
if cords == goal:
return path + mark
if cords in v:
continue
v.add(cords)
for pos, mark in get_adjacent(cords):
if pos in v:
continue
else:
q.append((pos, path + mark))
Nov. 23, 2014
Comments: