Пример #1
0
def main():
    numbers = read_numbers()
    three = numbers[3][0]

    place = [[0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0],
             [0, 0, 1, 0, 0],
             [0, 0, 0, 0, 0]]
    for i in three:
        print(i)
    print()

    BUBBLE_SIZE = 7

    q = hello(three, place)
    print("SIZE: ", len(q), len(q[0]))
    for i in q:
        print(i)
    bubbled_place = make_bubble(place, BUBBLE_SIZE)
    out_matrix(bubbled_place)
    out_matrix(zip_bubbled_data(bubbled_place, BUBBLE_SIZE))

    # важно чтобы id клеток разных регионов не пересекались!!!
    r = Region(len(merge_input([make_bubble(place, BUBBLE_SIZE), hello(three, place)])), 5, 0)

    for step in range(200):
        s = 0
        x = -1
        y = -1
        for i, I in enumerate(place):
            for j, J in enumerate(I):
                if place[i][j] == 1:
                    x, y = i, j
                    break

        print("-----" * 10)
        for i in place:
            print(i)
        print("-----" * 10)
        for i, I in enumerate(place):
            for j, J in enumerate(I):
                place[i][j] = 0

        if (x == -1 and y == -1) or step < 10:
            while 1:
                x = randrange(len(place))
                y = randrange(len(place))
                place[x][y] = 1
                if get_sum(hello(three, place)):
                    break
                place[x][y] = 0
        else:
            place[x][y] = 1
        r.step_forward(merge_input([make_bubble(place, BUBBLE_SIZE), hello(three, place)]))

        r.out_prediction()
        new_place = zip_bubbled_data(do_cut(r.get_binary_prediction(), len(make_bubble(place, BUBBLE_SIZE))),
                                     BUBBLE_SIZE)
        place = new_place
Пример #2
0
    def __init__(self, gens: []):
        self.gens = gens
        self.cur_gen_ind = 0
        self.cur_gen_cnt = 0

        # вычисляем первоначальную матрицу данных
        data = []
        for i in self.gens:
            data.append(i.get_data())

        self.a = merge_input(data)
        for i, I in enumerate(self.a):
            for j, J in enumerate(I):
                self.a[i][j] = 0

        # сохрнаяем пустую матрицу, будем выводить ее в качестве разделителя
        self.empty = deepcopy(self.a)

        # считаем период каждого генератора
        self.gens_periods = []

        # количество шагов генератора для которого будет предвычисляться период
        period_calc_size = 100

        for gen in self.gens:
            a = []
            t = deepcopy(gen)
            for i in range(period_calc_size):
                a.append(zip_binary_matrix(gen.get_data()))
                gen.move()
            self.gens_periods.append(get_period(a))
            gen = t
        print(self.gens_periods)