import utils def add_neighbors(the_map, neighbors, closed, near_y, near_x): points = utils.compass(near_x, near_y) for x,y in points: if the_map.inbounds(x,y) and closed[y, x] == utils.SPACE: closed[y, x] = utils.WALL neighbors.append([x,y]) def calculate_paths(the_map, paths, in_grid): height, width = paths.shape paths.fill(utils.PATH_LIMIT) closed = the_map.map.copy() starting_pixels = [] open_pixels = [] counter = 0 while counter < height * width: x = counter % width y = counter // width if in_grid[y, x] == 0: paths[y, x] = 0 closed[y, x] = utils.WALL starting_pixels.append([x,y]) counter += 1 for x, y in starting_pixels: add_neighbors(the_map, open_pixels, closed, y, x) counter = 1 while counter < utils.PATH_LIMIT and open_pixels: next_open = [] for x,y in open_pixels: paths[y, x] = counter add_neighbors(the_map, next_open, closed, y, x) open_pixels = next_open counter += 1 for x, y in open_pixels: paths[y, x] = counter