| Algorithm 2: Get the distance to walk with BFS |
| Input: , , , , Output: Exit’s x-position (), exit’s y-position (), distance the person must walk - # of boxes (), An array with each of the positions (x, y) where the person walks () = QItem( -1, -1,0); = np.zeros((int(),int()), dtype=int) repeat repeat if [i][j] == b’0’ then [i][j] = 1 else [i][j] = 0 end until range(0, int(); until range(0, int(); q = queue.Queue(); q.put(); [.row][.col] = 1 repeat p = q.get() if room[][] == b’e’ then return +1, +1, , bfsPathExit(, , , ( -1, -1)) end The function bfsPathExit is calculated with the Algorithm 2. if p.row - 1 >= 0 and [p.row - 1][p.col] == 0 then q.put(QItem(p.row - 1, p.col, p.dist + 1)) [p.row - 1][p.col] = 1 end if p.row + 1 < int() and [p.row + 1][p.col] == 0 then q.put(QItem(p.row + 1, p.col, p.dist + 1)) [p.row + 1][p.col] = 1 end if p.col - 1 >= 0 and [p.row][p.col - 1] == 0 then q.put(QItem(p.row, p.col - 1, p.dist + 1)) [p.row][p.col - 1] = 1 end if p.col + 1 < int() and [p.row][p.col + 1] == 0 then q.put(QItem(p.row,p.col + 1, p.dist + 1)) [p.row][p.col + 1] = 1 end until q.empty() == False; return -1 |