aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2019-09-26 14:00:35 +0200
committerRenaud G <renaud@rolisteam.org>2019-09-26 14:00:35 +0200
commitd94207bc22768e579766b281c28f211d25d2d9d4 (patch)
tree0bd17e71b96e624080581eca6fc213f68c97bf0c /node
parent69a238f0d1937fe5bc97b69e3cc4af0bf0ddde2b (diff)
downloadOneRoll-d94207bc22768e579766b281c28f211d25d2d9d4.tar.gz
OneRoll-d94207bc22768e579766b281c28f211d25d2d9d4.zip
Add operator T
Diffstat (limited to 'node')
-rw-r--r--node/allsamenode.cpp82
-rw-r--r--node/allsamenode.h33
2 files changed, 115 insertions, 0 deletions
diff --git a/node/allsamenode.cpp b/node/allsamenode.cpp
new file mode 100644
index 0000000..96f5616
--- /dev/null
+++ b/node/allsamenode.cpp
@@ -0,0 +1,82 @@
+#include "allsamenode.h"
+
+
+AllSameNode::AllSameNode() : m_diceResult(new DiceResult())
+{
+ m_result= m_diceResult;
+}
+
+void AllSameNode::run(ExecutionNode* previous)
+{
+ m_previousNode= previous;
+ if(nullptr != previous)
+ {
+ DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult());
+ if(nullptr != previous_result)
+ {
+ m_result->setPrevious(previous_result);
+ bool allSame=true;
+ int i=0;
+ quint64 previousValue;
+ for(auto& die : previous_result->getResultList())
+ {
+ if(i == 0)
+ previousValue=die->getValue();
+ Die* tmpdie= new Die(*die);
+ m_diceResult->insertResult(tmpdie);
+ die->displayed();
+ if(previousValue != die->getValue())
+ allSame=false;
+ ++i;
+ }
+
+ while(allSame)
+ {
+ QList<Die*> list= m_diceResult->getResultList();
+ qint64 pValue;
+ int i =0;
+ for(auto& die: list)
+ {
+ die->roll(true);
+ if(i==0)
+ pValue=die->getValue();
+ if(pValue != die->getValue())
+ allSame = false;
+ ++i;
+ }
+ }
+ }
+ }
+ if(nullptr != m_nextNode)
+ {
+ m_nextNode->run(this);
+ }
+}
+
+
+QString AllSameNode::toString(bool withLabel) const
+{
+ if(withLabel)
+ {
+ return QString("%1 [label=\"AllSameNode\"]").arg(m_id);
+ }
+ else
+ {
+ return m_id;
+ }
+}
+
+qint64 AllSameNode::getPriority() const
+{
+ qint64 priority= 0;
+ if(nullptr != m_nextNode)
+ {
+ priority= m_nextNode->getPriority();
+ }
+ return priority;
+}
+
+ExecutionNode* AllSameNode::getCopy() const
+{
+ return new AllSameNode();
+}
diff --git a/node/allsamenode.h b/node/allsamenode.h
new file mode 100644
index 0000000..e5c1dc2
--- /dev/null
+++ b/node/allsamenode.h
@@ -0,0 +1,33 @@
+#ifndef ALLSAMENODE_H
+#define ALLSAMENODE_H
+
+#include "executionnode.h"
+
+#include "result/diceresult.h"
+#include "validator.h"
+
+class AllSameNode : public ExecutionNode
+{
+public:
+ AllSameNode();
+// virtual ~AllSameNode();
+
+ virtual void run(ExecutionNode* previous);
+ /**
+ * @brief toString
+ * @return
+ */
+ virtual QString toString(bool withLabel) const;
+ /**
+ * @brief getPriority
+ * @return
+ */
+ virtual qint64 getPriority() const;
+
+ virtual ExecutionNode* getCopy() const;
+
+private:
+ DiceResult* m_diceResult;
+};
+
+#endif // FILTERNODE_H