Пример #1
0
 def test_golly(self):
     """Test conversion from Golly and vice versa."""
     rule_str = "B3/S23"
     rule_int = LifeLike.golly2int(rule_str)
     self.assertEqual(rule_int, 6152)
     rule_converted = LifeLike.int2golly(rule_int)
     self.assertEqual(rule_converted, rule_str)
Пример #2
0
class CrossbreedingExperiment(RegularExperiment):
    """Classic experiment for legacy EvoLife, where 'Bliambas' may form."""

    word = "FUTURE BREEDING MACHINE 2041"
    size = (1920, 1080)
    zoom = 1
    fade_in = 18
    fade_out = 3
    seed_diamoeba = seeds.patterns.BigBang(
        pos=(380, 280),
        size=(440, 340),
        vals={
            "energy": 0,
            "rule": LifeLike.golly2int("B35678/S5678") * RandInt(0, 1),
            "rng": RandInt(0, 2 ** 16 - 1)
        }
    )
    seed_conway = seeds.patterns.BigBang(
        pos=(0, 0),
        size=(1280, 720),
        vals={
            "energy": 0,
            # you may use unary operators
            "rule": +RandInt(0, 1) * LifeLike.golly2int("B3/S23"),
            # as well as reflected expressions
            "rng": 0 + RandInt(0, 2 ** 16 - 1)
        }
    )
    seed_rng = seeds.patterns.PrimordialSoup(
        vals={
            "rng": RandInt(0, 2 ** 16 - 1)
        }
    )
    # chain ordering matters, since areas are rewriting each other in order
    seed = seed_rng + seed_conway + seed_diamoeba
Пример #3
0
class BigBangExperiment4D(RegularExperiment):
    """Experiment in 4D space."""
    size = (640, 360, 3, 3)
    death_speed = 1
    full_treshold = 16
    max_genes = 5
    fade_in = 1
    fade_out = 1
    smooth_ratio = 10
    rule_back = LifeLike.golly2int("B12/S124")
    seed = seeds.patterns.PrimordialSoup(
        vals={
            "energy": 2,
            "new_energy": 2,
            "rule": rule_back,
            "rng": RandInt(0, 2**16 - 1),
        })
    for i in range(6 * 3):
        add_rule = str(random.randint(4, 4)).replace("2", "")
        rule_area = LifeLike.golly2int("B12/S12" + add_rule)
        seed += seeds.patterns.BigBang(pos=(30 + (i % 6) * 100,
                                            40 + (i // 6) * 100, 0, 0),
                                       size=(80, 80, 1, 1),
                                       vals={
                                           "energy": 1 * 273 * RandInt(0, 1),
                                           "new_energy":
                                           1 * 273 * RandInt(0, 1),
                                           "rule": rule_area,
                                           "rng": RandInt(0, 2**16 - 1),
                                       })
Пример #4
0
class BigBangExperiment(RegularExperiment):
    """Experiment, with smaller field, for quicker benchmark."""
    death_speed = 1
    full_treshold = 16
    max_genes = 13
    fade_in = 255
    fade_out = 255
    smooth_ratio = 1
    rule_mask = LifeLike.golly2int("B12345678/S12345678")
    seed = seeds.patterns.PrimordialSoup(
        vals={
            "energy": 0,
            "new_energy": 0,
            "rule": random.randint(0, 2**18 - 1) & rule_mask,
            "rng": RandInt(0, 2**16 - 1),
        })
    for i in range(6 * 3):
        seed += seeds.patterns.BigBang(
            pos=(30 + (i % 6) * 100, 40 + (i // 6) * 100),
            size=(80, 80),
            vals={
                "energy": 16 * RandInt(0, 1),
                "new_energy": 16 * RandInt(0, 1),
                "rule": random.randint(0, 2**18 - 1) & rule_mask,
                "rng": RandInt(0, 2**16 - 1),
            })
Пример #5
0
class LifelikeCA(GameOfLife):
    """Lifelike CA with a flexible rule that could be changed at runtime."""
    rule = core.Parameter(
        default=LifeLike.golly2int("B3/S23"),
        interactive=True,
    )

    def absorb(self):
        """Implement parent's clone with a rule as a parameter."""
        neighbors_alive = core.IntegerVariable()
        for i in range(len(self.buffers)):
            neighbors_alive += self.neighbors[i].buffer.state
        is_born = (self.rule >> neighbors_alive) & 1
        is_sustain = (self.rule >> 9 >> neighbors_alive) & 1
        self.main.state = is_born | is_sustain & self.main.state

    def step(self):
        """Change the rule interactively after some time passed."""
        if self.timestep == 23:
            self.rule = LifeLike.golly2int("B3/S23")
        super().step()
Пример #6
0
class DiamoebaExperiment(GOLExperiment):
    """Experiment with the interactive rule."""
    rule = LifeLike.golly2int("B35678/S5678")
Пример #7
0
 def step(self):
     """Change the rule interactively after some time passed."""
     if self.timestep == 23:
         self.rule = LifeLike.golly2int("B3/S23")
     super().step()