(start, end, pixels)
| 29 | |
| 30 | |
| 31 | def BFS(start, end, pixels): |
| 32 | queue = Queue() |
| 33 | queue.put([start]) # Wrapping the start tuple in a list |
| 34 | |
| 35 | while not queue.empty(): |
| 36 | |
| 37 | path = queue.get() |
| 38 | pixel = path[-1] |
| 39 | |
| 40 | if pixel == end: |
| 41 | return path |
| 42 | |
| 43 | for adjacent in getadjacent(pixel): |
| 44 | x, y = adjacent |
| 45 | if iswhite(pixels[x, y]): |
| 46 | pixels[x, y] = (127, 127, 127) # see note |
| 47 | new_path = list(path) |
| 48 | new_path.append(adjacent) |
| 49 | queue.put(new_path) |
| 50 | |
| 51 | print("Queue has been exhausted. No answer was found.") |
| 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
no test coverage detected