+<<<<<<< HEAD
+class Room:
+ def __init__(self, region):
+ """
+ """
+ self.regions = [region]
+ self.max_connections = 1
+ self.passages = []
+ self.tunnels = []
+
+ def is_linked(self):
+ """
+ Check if the room is linked to another room
+ :return: Whether the room has any links or not
+ """
+ return len(self.passages) + len(self.tunnels) > 0
+
+ def add_passage(self, room_region, new_region):
+ """ Add a passage link between rooms
+ :param room_region: coordinate of region from which we are linking
+ :param new_region: coordinate of region to which we are linking
+ :return:
+ """
+ pass
+
+ def add_region(self, region):
+ """
+ Add a new region into an existing room
+ :param region: region coordinates to be added to room
+ :return:
+ """
+ self.regions.append(region)
+
+ def connect_rooms(self, other_rooms):
+ """ Find the nearest rooms to this room
+ :param other_rooms: list of Rooms objects that we are searching
+ :return:
+ """
+ distance = []
+ other_tile = []
+ this_tile = []
+ target_rooms = []
+ for local_region in self.regions:
+ for room in other_rooms:
+ if self == room:
+ continue
+ for new_region in room.regions:
+ distance.append(
+ math.sqrt((local_region[0] - new_region[0]) ** 2 +
+ (local_region[1] - new_region[1]) ** 2))
+ other_tile.append(new_region)
+ this_tile.append(local_region)
+ target_rooms.append(room)
+
+ sorted_indices = [i[0] for i in sorted(enumerate(distance),
+ key=lambda x:x[0])]
+ for index in sorted_indices:
+ if len(self.passages) + len(self.tunnels) >= self.max_connections:
+ break
+ if not target_rooms[index].is_linked():
+ self.link_passage(this_tile[index], other_tile[index])
+ target_rooms[index].link_passage(
+ other_tile[index], this_tile[index])
+
+ def link_passage(self, local_tile, foriegn_tile):
+ """ Link a passage between two rooms
+ :param local_tile: tile in this room to which we wish to link
+ :param foriegn_tile: tile in another room to which we wish to link
+ :return:
+ """
+ self.passages.append([local_tile, foriegn_tile])
+=======