From c519f119908f1ce98fbfea251e65683ee37b4099 Mon Sep 17 00:00:00 2001 From: Richard Feistenauer Date: Sat, 5 Jan 2019 15:42:37 +0100 Subject: [PATCH] made state save slot count a parameter --- src/cellular_automaton/ca_cell_state.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cellular_automaton/ca_cell_state.py b/src/cellular_automaton/ca_cell_state.py index 0707f5c..2ffebcb 100644 --- a/src/cellular_automaton/ca_cell_state.py +++ b/src/cellular_automaton/ca_cell_state.py @@ -3,25 +3,27 @@ class CellState: This is the base class for all cell states. When using the cellular automaton display, inherit this class and implement get_state_draw_color. """ - def __init__(self, initial_state): - self._state = [[initial_state], [initial_state]] + def __init__(self, initial_state, state_save_slot_count=2): + 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): - """ 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 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. """ - 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): - """ Will return the status for the iteration modulo two. - :param iteration: Uses the iteration index, to differ between current and next state. + """ Will return the status for the iteration modulo number of saved states. + :param iteration: Uses the iteration index, to differ between concurrent states. :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): raise NotImplementedError