Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_string_example(
*,
seed_string=None,
seed_name=None,
num_gens=10
):
seed_game = GameOfLife.from_str(seed_string)
if seed_name is None:
seed_name = f'A {seed_game.height}x{seed_game.width} grid'
print(dedent(f'''
=========================
| Conway's Game of Life |
{'':=^50}
| {f'Starting with seed: "{seed_name:.10}"': <46.46} |
| {f'Running for {str(num_gens):1.3} generations.': <46.46} |
{'':=^50}
'''))
latest_generation = seed_game
for gen_num in range(1, num_gens + 1):
print(f'Generation {gen_num}:')
print(str(latest_generation))
latest_generation = latest_generation.next_generation()
print('Done')
def next_generation(self):
next_grid = [
[
cell.next_state(neighbor_count)
for cell, neighbor_count in row
]
for row in self.grid_with_live_neighbor_counts()
]
return GameOfLife(grid=next_grid)