def avg_pc(runs):
    """
    Given specified number of runs will calculate an average pc value on 50x50 lattice
    """
    pc = []

    for i in range(runs):
        lat10 = Lattice(50)

        while not common_cluster(lat10):
            pos1 = rand_pos(len(lat10.get_lattice()))
            search_neighbours(lat10, pos1)
            if lat10.filled():
                print("No spanning cluster found")
                break

        pc.append(lat10.perc_value())

    return sum(pc) / len(pc)
    return sum(pc) / len(pc)


if __name__ == "__main__":

    # used for obtaining an average pc
    print("Average pc value: ", avg_pc(1000))

    # create lattice with specified size
    lattice = Lattice(10)

    error = False  # used if not span is found
    while not common_cluster(lattice):
        pos = rand_pos(len(lattice.get_lattice()))  # get random position
        search_neighbours(lattice,
                          pos)  # pass neighbours to cluster assignment
        # precautionary measure
        if lattice.filled():
            print("Error: No spanning cluster found")
            error = True
            break

    # displaying of results
    if not error:
        print(lattice.get_lattice())
        print(lattice.perc_value())
        plt.imshow(lattice.get_lattice(), cmap="Greys", vmax=1)
        plt.colorbar()
        plt.title("p = " + str(lattice.perc_value()))
        plt.show()