How to use the cellular-automaton.conways_game_of_life.Cell 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
if is_within_rows and is_within_cols:
            return self.grid[row][col]
        return default


class Cell:
    @classmethod
    def from_str(cls, string):
        if string == Live.string_form:
            return Live()
        return Dead()

    def __str__(self):
        return self.string_form

class Dead(Cell):
    string_form = '·'
    is_alive = False

    def next_state(self, neighbor_count):
        if neighbor_count == 3:
            return Live()
        return Dead()

class Live(Cell):
    string_form = '0'
    is_alive = True

    def next_state(self, neighbor_count):
        if neighbor_count in [2, 3]:
            return Live()
        return Dead()
github AllAlgorithms / python / cellular-automaton / conways_game_of_life.py View on Github external
return Live()
        return Dead()

    def __str__(self):
        return self.string_form

class Dead(Cell):
    string_form = '·'
    is_alive = False

    def next_state(self, neighbor_count):
        if neighbor_count == 3:
            return Live()
        return Dead()

class Live(Cell):
    string_form = '0'
    is_alive = True

    def next_state(self, neighbor_count):
        if neighbor_count in [2, 3]:
            return Live()
        return Dead()


from textwrap import dedent

def run_string_example(
    *,
    seed_string=None,
    seed_name=None,
    num_gens=10