How to use the cellular-automaton.conways_game_of_life.GameOfLife function in cellular-automaton

To help you get started, we’ve selected a few cellular-automaton examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AllAlgorithms / python / cellular-automaton / conways_game_of_life.py View on Github external
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')
github AllAlgorithms / python / cellular-automaton / conways_game_of_life.py View on Github external
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)