Skip to main content
. 2020 May 20;20(10):2899. doi: 10.3390/s20102899
Algorithm 1: Get the evacuation path
Input: grid, width, height, start
Output: An array with each of the positions (x, y) where the person walks (path)

wall, clear, goal = b’0’, b’*’, b’e’
queue = collections.deque([[start]])
seen = set([start])
repeat(
  path = queue.popleft()
   x, y = path[-1]
   if grid[y][x] == goal then
   ( return path
  end (
  repeat(
   if 0 <= x2 < width and 0 <= y2 < height and grid[y2][x2] != wall and (x2, y2) not in see
     then
    queue.append(path + [(x2, y2)])
    seen.add((x2, y2))
  end(
  until x2, y2 in ((x+1,y), (x-1,y), (x,y+1), (x,y-1);(
until queue;