def convert_to_sectors(region_names, world, player):
    region_list = convert_regions(region_names, world, player)
    sectors = []
    while (len(region_list) > 0):
        region = region_list.pop()
        new_sector = True
        region_chunk = [region]
        exits = []
        exits.extend(region.exits)
        outstanding_doors = []
        matching_sectors = []
        while (len(exits) > 0):
            ext = exits.pop()
            door = ext.door
            if ((ext.connected_region is not None) or ((door is not None) and (door.controller is not None))):
                if ((door is not None) and (door.controller is not None)):
                    connect_region = world.get_entrance(door.controller.name, player).parent_region
                else:
                    connect_region = ext.connected_region
                if ((connect_region not in region_chunk) and (connect_region in region_list)):
                    region_list.remove(connect_region)
                    region_chunk.append(connect_region)
                    exits.extend(connect_region.exits)
                if (connect_region not in region_chunk):
                    for existing in sectors:
                        if (connect_region in existing.regions):
                            new_sector = False
                            if (existing not in matching_sectors):
                                matching_sectors.append(existing)
            elif ((door is not None) and (door.controller is None) and (door.dest is None)):
                outstanding_doors.append(door)
        sector = Sector()
        if (not new_sector):
            for match in matching_sectors:
                sector.regions.extend(match.regions)
                sector.outstanding_doors.extend(match.outstanding_doors)
                sectors.remove(match)
        sector.regions.extend(region_chunk)
        sector.outstanding_doors.extend(outstanding_doors)
        sectors.append(sector)
    return sectors
def convert_to_sectors(region_names, world, player):
    region_list = convert_regions(region_names, world, player)
    sectors = []
    while (len(region_list) > 0):
        region = region_list.pop()
        new_sector = True
        region_chunk = [region]
        exits = []
        exits.extend(region.exits)
        outstanding_doors = []
        matching_sectors = []
        while (len(exits) > 0):
            ext = exits.pop()
            door = ext.door
            if ((ext.connected_region is not None) or ((door is not None) and (door.controller is not None))):
                if ((door is not None) and (door.controller is not None)):
                    connect_region = world.get_entrance(door.controller.name, player).parent_region
                else:
                    connect_region = ext.connected_region
                if ((connect_region not in region_chunk) and (connect_region in region_list)):
                    region_list.remove(connect_region)
                    region_chunk.append(connect_region)
                    exits.extend(connect_region.exits)
                if (connect_region not in region_chunk):
                    for existing in sectors:
                        if (connect_region in existing.regions):
                            new_sector = False
                            if (existing not in matching_sectors):
                                matching_sectors.append(existing)
            elif ((door is not None) and (door.controller is None) and (door.dest is None)):
                outstanding_doors.append(door)
        sector = Sector()
        if (not new_sector):
            for match in matching_sectors:
                sector.regions.extend(match.regions)
                sector.outstanding_doors.extend(match.outstanding_doors)
                sectors.remove(match)
        sector.regions.extend(region_chunk)
        sector.outstanding_doors.extend(outstanding_doors)
        sectors.append(sector)
    return sectors