def vanilla_key_logic(world, player):
    builders = []
    world.dungeon_layouts[player] = {}
    for dungeon in [dungeon for dungeon in world.dungeons if (dungeon.player == player)]:
        sector = Sector()
        sector.name = dungeon.name
        sector.regions.extend(convert_regions(dungeon.regions, world, player))
        builder = simple_dungeon_builder(sector.name, [sector])
        builder.master_sector = sector
        builders.append(builder)
        world.dungeon_layouts[player][builder.name] = builder
    overworld_prep(world, player)
    (entrances_map, potentials, connections) = determine_entrance_list(world, player)
    enabled_entrances = {}
    sector_queue = deque(builders)
    (last_key, loops) = (None, 0)
    while (len(sector_queue) > 0):
        builder = sector_queue.popleft()
        origin_list = list(entrances_map[builder.name])
        find_enabled_origins(builder.sectors, enabled_entrances, origin_list, entrances_map, builder.name)
        origin_list_sans_drops = remove_drop_origins(origin_list)
        if (len(origin_list_sans_drops) <= 0):
            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:
            find_new_entrances(builder.master_sector, entrances_map, connections, potentials, enabled_entrances, world, player)
            start_regions = convert_regions(origin_list, world, player)
            doors = convert_key_doors(default_small_key_doors[builder.name], world, player)
            key_layout = build_key_layout(builder, start_regions, doors, world, player)
            valid = validate_key_layout(key_layout, world, player)
            if (not valid):
                logging.getLogger('').warning('Vanilla key layout not valid %s', builder.name)
            if (player not in world.key_logic.keys()):
                world.key_logic[player] = {}
            analyze_dungeon(key_layout, world, player)
            world.key_logic[player][builder.name] = key_layout.key_logic
            log_key_logic(builder.name, key_layout.key_logic)
            last_key = None
    if ((world.shuffle[player] == 'vanilla') and (world.accessibility[player] == 'items') and (not world.retro[player])):
        validate_vanilla_key_logic(world, player)
def vanilla_key_logic(world, player):
    builders = []
    world.dungeon_layouts[player] = {}
    for dungeon in [dungeon for dungeon in world.dungeons if (dungeon.player == player)]:
        sector = Sector()
        sector.name = dungeon.name
        sector.regions.extend(convert_regions(dungeon.regions, world, player))
        builder = simple_dungeon_builder(sector.name, [sector])
        builder.master_sector = sector
        builders.append(builder)
        world.dungeon_layouts[player][builder.name] = builder
    overworld_prep(world, player)
    (entrances_map, potentials, connections) = determine_entrance_list(world, player)
    enabled_entrances = {}
    sector_queue = deque(builders)
    (last_key, loops) = (None, 0)
    while (len(sector_queue) > 0):
        builder = sector_queue.popleft()
        origin_list = list(entrances_map[builder.name])
        find_enabled_origins(builder.sectors, enabled_entrances, origin_list, entrances_map, builder.name)
        origin_list_sans_drops = remove_drop_origins(origin_list)
        if (len(origin_list_sans_drops) <= 0):
            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:
            find_new_entrances(builder.master_sector, entrances_map, connections, potentials, enabled_entrances, world, player)
            start_regions = convert_regions(origin_list, world, player)
            doors = convert_key_doors(default_small_key_doors[builder.name], world, player)
            key_layout = build_key_layout(builder, start_regions, doors, world, player)
            valid = validate_key_layout(key_layout, world, player)
            if (not valid):
                logging.getLogger().warning('Vanilla key layout not valid %s', builder.name)
            if (player not in world.key_logic.keys()):
                world.key_logic[player] = {}
            analyze_dungeon(key_layout, world, player)
            world.key_logic[player][builder.name] = key_layout.key_logic
            log_key_logic(builder.name, key_layout.key_logic)
            last_key = None
    if ((world.shuffle[player] == 'vanilla') and (world.accessibility[player] == 'items') and (not world.retro[player])):
        validate_vanilla_key_logic(world, player)