aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/allsamenode.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2019-10-01 23:26:21 +0200
committerRenaud G <renaud@rolisteam.org>2019-10-01 23:26:21 +0200
commit5e28288120abb5a4c0ee3f303dd1b98515807df9 (patch)
tree6bd0c1f79152bb54ed989c7e73daaa747ee8efe2 /node/allsamenode.cpp
parentd94207bc22768e579766b281c28f211d25d2d9d4 (diff)
downloadOneRoll-5e28288120abb5a4c0ee3f303dd1b98515807df9.tar.gz
OneRoll-5e28288120abb5a4c0ee3f303dd1b98515807df9.zip
Fix endless loop t operator.
Diffstat (limited to 'node/allsamenode.cpp')
-rw-r--r--node/allsamenode.cpp74
1 files changed, 39 insertions, 35 deletions
diff --git a/node/allsamenode.cpp b/node/allsamenode.cpp
index 96f5616..3b2f10f 100644
--- a/node/allsamenode.cpp
+++ b/node/allsamenode.cpp
@@ -1,6 +1,5 @@
#include "allsamenode.h"
-
AllSameNode::AllSameNode() : m_diceResult(new DiceResult())
{
m_result= m_diceResult;
@@ -12,40 +11,46 @@ void AllSameNode::run(ExecutionNode* previous)
if(nullptr != previous)
{
DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult());
- if(nullptr != previous_result)
+ 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();
+ m_result->setPrevious(previous_result);
+ bool allSame= true;
+ int i= 0;
+ qint64 previousValue= 0;
+ if(previous_result->getResultList().size() < 2)
+ {
+ m_errors.insert(Dice::ERROR_CODE::ENDLESS_LOOP_ERROR,
+ QStringLiteral("T operator must operate on more than 1 die"));
+ return;
+ }
+ 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;
+ 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;
- }
- }
- }
+ while(allSame)
+ {
+ QList<Die*> list= m_diceResult->getResultList();
+ qint64 pValue= 0;
+ 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)
{
@@ -53,7 +58,6 @@ void AllSameNode::run(ExecutionNode* previous)
}
}
-
QString AllSameNode::toString(bool withLabel) const
{
if(withLabel)
@@ -68,12 +72,12 @@ QString AllSameNode::toString(bool withLabel) const
qint64 AllSameNode::getPriority() const
{
- qint64 priority= 0;
- if(nullptr != m_nextNode)
- {
+ qint64 priority= 0;
+ if(nullptr != m_nextNode)
+ {
priority= m_nextNode->getPriority();
- }
- return priority;
+ }
+ return priority;
}
ExecutionNode* AllSameNode::getCopy() const