def propagate(cell): to_update = [neighbour for neighbour, _ in cell.get_neighbors()] while len(to_update) > 0: cell = to_update.pop(0) for neighbour, offset in cell.get_neighbors(): for pattern_index in cell.allowed_patterns: pattern = Pattern.from_index(pattern_index) pattern_still_compatible = False for neighbour_pattern_index in neighbour.allowed_patterns: neighbour_pattern = Pattern.from_index( neighbour_pattern_index) if pattern.is_compatible(neighbour_pattern, offset): pattern_still_compatible = True break if not pattern_still_compatible: cell.allowed_patterns.remove(pattern_index) for neigh, _ in cell.get_neighbors(): if neigh not in to_update: to_update.append(neigh)
def get_value(self): if self.is_stable(): pattern = Pattern.from_index(self.allowed_patterns[0]) return pattern.get() return -1