Randomly kill or move all Neurons.
(self)
| 61 | self._grid[y][x] = Neuron() |
| 62 | |
| 63 | def tick(self) -> None: |
| 64 | """Randomly kill or move all Neurons.""" |
| 65 | for neuron_data in self.neurons: |
| 66 | neuron = neuron_data[0] |
| 67 | x, y = neuron_data[1] |
| 68 | |
| 69 | if random.randint(1, 100) <= Neuron.CHANCE_OF_DEATH: |
| 70 | self._grid[y][x] = Empty() |
| 71 | continue |
| 72 | |
| 73 | direction = random.choice(list(Direction)) |
| 74 | if direction == Direction.UP: |
| 75 | y -= 1 |
| 76 | elif direction == Direction.RIGHT: |
| 77 | x += 1 |
| 78 | elif direction == Direction.DOWN: |
| 79 | y += 1 |
| 80 | elif direction == Direction.LEFT: |
| 81 | x -= 1 |
| 82 | try: |
| 83 | self._grid[y][x] = Neuron() |
| 84 | except IndexError: |
| 85 | pass |
| 86 | |
| 87 | |
| 88 | def main() -> None: |