def propagate(point: Point, to: [Directions]): # print("Propagating from", point) soil[point.tuple()] = RUNNING_WATER if point.y == bottom: return True down = point + Directions.DOWN.value if soil.get(down.tuple()) is RUNNING_WATER: return True elif soil.get(down.tuple()) is None: if propagate(down, to=(Directions.LEFT, Directions.RIGHT)): return True propagations = [flow_to(point, direction) for direction in to] if not any(propagations): soil[point.tuple()] = STAGNANT_WATER return False not_stagant(point, Directions.LEFT) not_stagant(point, Directions.RIGHT) return True
def get_neighbors(self, point: Point): for x, y in neighbors: pos = Point(point.x + x, point.y + y) if pos.tuple() in self.grid: yield pos