made state save slot count a parameter

This commit is contained in:
Richard Feistenauer 2019-01-05 15:42:37 +01:00
parent 5d86bd10cf
commit c519f11990

View File

@ -3,25 +3,27 @@ class CellState:
This is the base class for all cell states. This is the base class for all cell states.
When using the cellular automaton display, inherit this class and implement get_state_draw_color. When using the cellular automaton display, inherit this class and implement get_state_draw_color.
""" """
def __init__(self, initial_state): def __init__(self, initial_state, state_save_slot_count=2):
self._state = [[initial_state], [initial_state]] self._state_save_slot_count = state_save_slot_count
self._state = [[initial_state]] * state_save_slot_count
def set_status_of_iteration(self, new_status, iteration): def set_status_of_iteration(self, new_status, iteration):
""" Will set the new status for the iteration modulo two. """ Will set the new status for the iteration modulo number of saved states.
:param new_status: The new status to set. :param new_status: The new status to set.
:param iteration: Uses the iteration index, to differ between current and next state. :param iteration: Uses the iteration index, to differ between concurrent states.
:return True if status has changed. :return True if status has changed.
""" """
self._state[iteration % 2] = new_status self._state[iteration % self._state_save_slot_count] = new_status
return self._state[0] != self._state[1] return self._state[(iteration - 1) % self._state_save_slot_count] \
!= self._state[iteration % self._state_save_slot_count]
def get_status_of_iteration(self, iteration): def get_status_of_iteration(self, iteration):
""" Will return the status for the iteration modulo two. """ Will return the status for the iteration modulo number of saved states.
:param iteration: Uses the iteration index, to differ between current and next state. :param iteration: Uses the iteration index, to differ between concurrent states.
:return The status for this iteration. :return The status for this iteration.
""" """
return self._state[iteration % 2] return self._state[iteration % self._state_save_slot_count]
def get_state_draw_color(self, iteration): def get_state_draw_color(self, iteration):
raise NotImplementedError raise NotImplementedError