def traverse_core(core_area, world_size=(60, 60),
                  neighbor_func=get_moore_neighbors_toroidal):
    """
    Treat cells in core_area like a graph and traverse it to
    see how many connected components there are.
    """

    if not core_area:
        return []
    core_area = [tuple(i) for i in core_area]
    curr = core_area[0]
    core_area = set(core_area[1:])
    to_explore = []
    cores = [[curr]]

    while core_area:
        neighbors = neighbor_func(curr, world_size)

        for n in neighbors:
            if n in core_area:
                core_area.remove(n)
                to_explore.append(n)
                cores[-1].append(n)

        if to_explore:
            curr = to_explore.pop()
        else:
            curr = core_area.pop()
            cores.append([curr])

    return cores
Treat cells in core_area like a graph and traverse it to
    see how many connected components there are.