def main_dungeon_generation(dungeon_builders, recombinant_builders, connections_tuple, world, player):
    (entrances_map, potentials, connections) = connections_tuple
    enabled_entrances = {}
    sector_queue = deque(dungeon_builders.values())
    (last_key, loops) = (None, 0)
    while (len(sector_queue) > 0):
        builder = sector_queue.popleft()
        split_dungeon = (builder.name.startswith('Desert Palace') or builder.name.startswith('Skull Woods'))
        name = builder.name
        if split_dungeon:
            name = ' '.join(builder.name.split(' ')[:(- 1)])
        origin_list = list(builder.entrance_list)
        find_enabled_origins(builder.sectors, enabled_entrances, origin_list, entrances_map, name)
        origin_list_sans_drops = remove_drop_origins(origin_list)
        if ((len(origin_list_sans_drops) <= 0) or ((name == 'Turtle Rock') and (not validate_tr(builder, origin_list_sans_drops, world, player)))):
            if ((last_key == builder.name) or (loops > 1000)):
                origin_name = world.get_region(origin_list[0], player).entrances[0].parent_region.name
                raise Exception(('Infinite loop detected for "%s" located at %s' % builder.name), origin_name)
            sector_queue.append(builder)
            last_key = builder.name
            loops += 1
        else:
            logging.getLogger('').info('Generating dungeon: %s', builder.name)
            ds = generate_dungeon(builder, origin_list_sans_drops, split_dungeon, world, player)
            find_new_entrances(ds, entrances_map, connections, potentials, enabled_entrances, world, player)
            ds.name = name
            builder.master_sector = ds
            builder.layout_starts = (origin_list if (len(builder.entrance_list) <= 0) else builder.entrance_list)
            last_key = None
    combine_layouts(recombinant_builders, dungeon_builders, entrances_map)
    world.dungeon_layouts[player] = {}
    for builder in dungeon_builders.values():
        find_enabled_origins([builder.master_sector], enabled_entrances, builder.layout_starts, entrances_map, builder.name)
        builder.path_entrances = entrances_map[builder.name]
    world.dungeon_layouts[player] = dungeon_builders
def main_dungeon_generation(dungeon_builders, recombinant_builders, connections_tuple, world, player):
    (entrances_map, potentials, connections) = connections_tuple
    enabled_entrances = {}
    sector_queue = deque(dungeon_builders.values())
    (last_key, loops) = (None, 0)
    while (len(sector_queue) > 0):
        builder = sector_queue.popleft()
        split_dungeon = (builder.name.startswith('Desert Palace') or builder.name.startswith('Skull Woods'))
        name = builder.name
        if split_dungeon:
            name = ' '.join(builder.name.split(' ')[:(- 1)])
        origin_list = list(builder.entrance_list)
        find_enabled_origins(builder.sectors, enabled_entrances, origin_list, entrances_map, name)
        origin_list_sans_drops = remove_drop_origins(origin_list)
        if ((len(origin_list_sans_drops) <= 0) or ((name == 'Turtle Rock') and (not validate_tr(builder, origin_list_sans_drops, world, player)))):
            if ((last_key == builder.name) or (loops > 1000)):
                origin_name = world.get_region(origin_list[0], player).entrances[0].parent_region.name
                raise Exception(('Infinite loop detected for "%s" located at %s' % builder.name), origin_name)
            sector_queue.append(builder)
            last_key = builder.name
            loops += 1
        else:
            logging.getLogger().info('Generating dungeon: %s', builder.name)
            ds = generate_dungeon(builder, origin_list_sans_drops, split_dungeon, world, player)
            find_new_entrances(ds, entrances_map, connections, potentials, enabled_entrances, world, player)
            ds.name = name
            builder.master_sector = ds
            builder.layout_starts = (origin_list if (len(builder.entrance_list) <= 0) else builder.entrance_list)
            last_key = None
    combine_layouts(recombinant_builders, dungeon_builders, entrances_map)
    world.dungeon_layouts[player] = {}
    for builder in dungeon_builders.values():
        find_enabled_origins([builder.master_sector], enabled_entrances, builder.layout_starts, entrances_map, builder.name)
        builder.path_entrances = entrances_map[builder.name]
    world.dungeon_layouts[player] = dungeon_builders