-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
There was a problem hiding this 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"; | ||
} |
There was a problem hiding this comment.
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]);
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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 😄
Thanks 😉 |
Instead of hard-coding each separate rule, we can simply infer them from the integer's binary representation.