def door_allowed(self, pos): if not pos in self.walls: return False n, e, s, w = geometry.adjacent(pos) return (n in self.walls and s in self.walls) or (e in self.walls and w in self.walls)
def flood_find(self, start, points=None, is_connected=None): """returns a set of points connected to the given point (including it), optionally using a provided is_connection function """ if not points: points = self.region.empty_points() if not is_connected: is_connected = lambda point: self.board[point].terrain is None points = set(points) connected = set() processed = set() to_process = [start] while to_process: for point in to_process[:]: to_process.remove(point) if point not in processed: processed.add(point) if point in points and (point == start or is_connected(point)): connected.add(point) to_process.extend(geometry.adjacent(point)) return connected
def find_outside_connections(self, outside_zone): connection_set = set() for point in self.door_candidates(): for n in geometry.adjacent(point): if n in outside_zone: connection_set.add(point) if connection_set: self.potential_outside_connections.append((outside_zone, connection_set))
def border(self): b = set() neighbors = geometry.adjacent(self.point) for neighbor in neighbors: if neighbor in self.region.shape.points: b.add(neighbor) return b
def possible_moves(node): point = node.data['point'] moves = [] for p in geometry.adjacent(point): if p in self.region.shape.points and p not in blocked: moves.append(p) return moves
def find_outside_connections(self, outside_zone): connection_set = set() for point in self.door_candidates(): for n in geometry.adjacent(point): if n in outside_zone: connection_set.add(point) if connection_set: self.potential_outside_connections.append( (outside_zone, connection_set))
def find_adjacency(self, region): adjacency = {} for point in self.shape.border & region.shape.outline: for neighbor in geometry.adjacent(point): if not neighbor in region.shape.points: continue if not adjacency.get(point): adjacency[point] = [neighbor] else: adjacency[point].append(neighbor) if adjacency: self.adjacent[region] = adjacency
def doorstep(self, position): """returns the position immediately outside the room, and next to the supplied position""" for p in geometry.adjacent(position): if p in self.interior: continue if p in self.walls: continue if p in self.doors: continue return p return None
def is_viable_connection_point(self, point): # points not on the border are right out if not point in self.shape.border: return False north, east, south, west = geometry.adjacent(point) # points on corners are undesirable if not ((east in self.shape.border and west in self.shape.border) or (north in self.shape.border and south in self.shape.border)): return False # we also don't want points next to other connections for neighbor in north, east, south, west: if neighbor in self.connections: return False return True