Skip to content

Commit

Permalink
Wrap next state logic in switch case based on selected rule
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanPadden committed Aug 15, 2018
1 parent 430db1b commit 461752a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 461752a

Please sign in to comment.