Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse all the 256 Elementary Cellular Automata rules #1

Merged
merged 5 commits into from
Apr 29, 2019

Conversation

Sedictious
Copy link

Instead of hard-coding each separate rule, we can simply infer them from the integer's binary representation.

Copy link
Member

@cardinot cardinot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!
Could you also update the text in README to refer to this new version?

plugin.cpp Outdated
} else if (!left && !center && right) {
r = m_binrule.at(6) == "1";
} else if (!left && !center && !right) {
r = m_binrule.at(7) == "1";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could replace all those if-else statements by:

return Value(m_binrule[left*4 + center*2 + right]);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really clever and elegant! I wanted to use some sort of hash to access the cell state, but decided against it since I figured it would be an overkill (and an inefficient one at that).

plugin.cpp Outdated
@@ -38,6 +38,8 @@ bool CellularAutomata1D::init()

// determines which rule to use
m_rule = attr("rule").toInt();
m_binrule = QString::number(m_rule, 2);
m_binrule.prepend(QString("0").repeated(8 - m_binrule.length()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an elegant solution using QString 👏
However, I think we should just use a std::bitset here.

m_binrule = std::bitset<8>(attr("rule").toInt());

Please, fix the type of m_binrule to std::bitset<8> m_binrule in the plugin.h file. Also, we can now remove the m_rule member.

metadata.json Outdated
@@ -6,7 +6,7 @@
"author": "Ethan Padden and Marcos Cardinot",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to add your name here 😄

@cardinot cardinot merged commit 9eb99ca into evoplex:master Apr 29, 2019
@cardinot
Copy link
Member

Thanks 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants