From 461752a2b0a5ca689b3d57ce2a83305bcf77f2b8 Mon Sep 17 00:00:00 2001 From: EthanPadden Date: Wed, 15 Aug 2018 11:53:12 +0100 Subject: [PATCH] Wrap next state logic in switch case based on selected rule --- plugin.cpp | 15 +++++++++++++-- plugin.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin.cpp b/plugin.cpp index bc4538e..fbd2cfa 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -16,6 +16,8 @@ bool MinimalModel::init() m_toroidal = attr("toroidal").toBool(); // if the structure is toroidal, this attribute is irrelevant m_edgeCaseValue = attr("edgeCaseValue").toBool(); + // determines which rule to use + m_rule = attr("rule").toInt(); return m_stateAttrId >= 0; } @@ -51,8 +53,17 @@ bool MinimalModel::algorithmStep() bool central_cell = node.attr(m_stateAttrId).toBool(); - // next state of central cell = [left_cell XOR (central_cell OR right_cell)] - bool central_cell_next_state = left_cell ^ (central_cell || right_cell); + bool central_cell_next_state; + + switch (m_rule) { + case 30: + // next state of central cell = [left_cell XOR (central_cell OR right_cell)] + central_cell_next_state = left_cell ^ (central_cell || right_cell); + break; + default: + break; + } + nextStates.emplace_back(central_cell_next_state); } diff --git a/plugin.h b/plugin.h index 258ca57..2c72164 100644 --- a/plugin.h +++ b/plugin.h @@ -41,6 +41,7 @@ class MinimalModel: public AbstractModel // Values customOutputs(const Values& inputs) const override; private: int m_stateAttrId; + int m_rule; bool m_toroidal; bool m_edgeCaseValue; };