Add init state argument

This commit is contained in:
timofej 2023-08-24 21:47:56 +02:00
parent 1903bed60e
commit 7a5b7eae6e
2 changed files with 12 additions and 6 deletions

View File

@ -37,10 +37,12 @@ class CellularAutomatonCreator(abc.ABC):
def __init__(self, def __init__(self,
dimension, dimension,
neighborhood: Neighborhood, neighborhood: Neighborhood,
init,
*args, **kwargs): *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._dimension = dimension self._dimension = dimension
self._neighborhood = neighborhood self._neighborhood = neighborhood
self.init = init
self._current_state = {} self._current_state = {}
self._next_state = {} self._next_state = {}
@ -229,15 +231,16 @@ class Neuropercolation(CellularAutomatonCreator, abc.ABC):
class NeuropercolationCoupled(CellularAutomatonCreator, abc.ABC): class NeuropercolationCoupled(CellularAutomatonCreator, abc.ABC):
def __init__(self, dim, eps, coupling=[], *args, **kwargs): def __init__(self, dim, eps, coupling=[], init=[[0,0],[0,0]], *args, **kwargs):
super().__init__(dimension=[dim, dim, 2, 2], super().__init__(dimension=[dim, dim, 2, 2],
init=init,
neighborhood=VonNeumannNeighborhood(EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS)) neighborhood=VonNeumannNeighborhood(EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS))
self._evolution_step = 0 self._evolution_step = 0
self.epsilon = eps self.epsilon = eps
self.coupling = coupling self.coupling = coupling
def init_cell_state(self, coord): # pylint: disable=no-self-use def init_cell_state(self, coord): # pylint: disable=no-self-use
return DEAD return [self.init[coord[3]][coord[2]]]
def get_cells(self): def get_cells(self):
return self._current_state return self._current_state

View File

@ -70,6 +70,7 @@ class Simulate1Layer:
def __init__(self, def __init__(self,
dim, dim,
eps, eps,
init=0,
steps=100, steps=100,
draw='pygame', draw='pygame',
res=4, res=4,
@ -88,7 +89,7 @@ class Simulate1Layer:
:param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0) :param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0)
""" """
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._cellular_automaton = Neurolattice(dim,eps) self._cellular_automaton = Neurolattice(dim,eps,init=init)
self.__active = True self.__active = True
self.__cell_size = [res,res] self.__cell_size = [res,res]
self.__dimension = dim self.__dimension = dim
@ -239,6 +240,7 @@ class Simulate2Layers:
def __init__(self, def __init__(self,
dim, dim,
eps, eps,
init=[0,0],
steps=100, steps=100,
draw='pygame', draw='pygame',
res=4, res=4,
@ -257,7 +259,7 @@ class Simulate2Layers:
:param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0) :param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0)
""" """
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._cellular_automaton = Neuropercolation(dim,eps) self._cellular_automaton = Neuropercolation(dim,eps,init=init)
self.__active = True self.__active = True
self.__cell_size = [res,res] self.__cell_size = [res,res]
self.__dimension = dim self.__dimension = dim
@ -422,6 +424,7 @@ class Simulate4Layers:
dim, dim,
eps, eps,
coupling=[], coupling=[],
init=[[0,0],[0,0]],
steps=100, steps=100,
draw='pygame', draw='pygame',
res=4, res=4,
@ -440,7 +443,7 @@ class Simulate4Layers:
:param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0) :param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0)
""" """
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._cellular_automaton = NeuropercolationCoupled(dim,eps,coupling) self._cellular_automaton = NeuropercolationCoupled(dim,eps,coupling,init)
self.__active = True self.__active = True
self.__cell_size = [res,res] self.__cell_size = [res,res]
self.__dimension = dim self.__dimension = dim