/// <summary>
        /// This method will go through the inputs, and determine if each node needs further evaluation.
        /// If not then we will fill the result stack and get ready for expression evaluation
        /// </summary>
        /// <param name="connectedBlock"></param>
        /// <returns></returns>
        public override bool EvaluateInternalData(BaseNodeBlock connectedBlock)
        {
            Console.WriteLine(String.Format("From {0} -> {1}", this.GetType().Name, connectedBlock.GetType().Name));
            bool temp = true;

            if (connectedBlock is GetConstantNodeBlock block)
            {
                ResultsStack.Push(block?.InternalData.VarData);
                Console.WriteLine(String.Format("Result: {0}", ResultsStack.Peek()));
                return(true);
            }
            else
            {
                if (connectedBlock.AnswerToOutput != null)
                {
                    ResultsStack.Push(connectedBlock.AnswerToOutput);
                    Console.WriteLine(String.Format("Result: {0}", ResultsStack.Peek()));
                    connectedBlock.AnswerToOutput = null;
                }
                else
                {
                    temp &= connectedBlock.OnStartEvaluateInternalData();                     //it's not a constant thus we MUST evaluate this node.
                    if (temp)
                    {
                        this.ResultsStack.Push(connectedBlock.AnswerToOutput);
                        Console.WriteLine(String.Format("Result: {0}", ResultsStack.Peek()));
                        connectedBlock.AnswerToOutput = null;
                    }
                }
            }

            return(temp);
        }
        /// <summary>
        /// This method is here to check to make sure that all the inputs on this current block
        /// are/have a valid connection.
        /// </summary>
        /// <returns></returns>
        public override bool OnStartEvaluateInternalData()
        {
            bool temp = true;
            int  i    = 0;

            this.ActiveStatus = EActiveStatus.Active;
            foreach (ConnectionNode cn in InputNodes)
            {
                if (!(cn.ConnectedNodes.Count > 0))
                {
                    if (InputNodes.Count - 1 == i && (!newvalconnected && NewValue_Constant != ""))
                    {
                        continue;
                    }
                    temp = false;
                    ErrorStack.Push(new InputNodeConnectionException(i, this.GetType().Name));
                }
                i++;
            }

            if (!temp)
            {
                this.ActiveStatus = EActiveStatus.Error;
                return(temp);
            }
            else
            {
                //no error found we can evaluate
                foreach (ConnectionNode cn in this.InputNodes)
                {
                    if (cn.ConnectedNodes.Count != 0)
                    {
                        temp &= EvaluateInternalData(cn.ConnectedNodes[0].ParentBlock);
                    }
                    else                     //this is here for the constants that one can manually enter.
                    {
                        if (this.NewValue_Constant == "T")
                        {
                            ResultsStack.Push(true);
                        }
                        else if (this.NewValue_Constant == "F")
                        {
                            ResultsStack.Push(false);
                        }
                        Console.WriteLine(String.Format("Result: {0}", ResultsStack.Peek()));
                    }
                }

                if (!temp)
                {
                    this.ActiveStatus = EActiveStatus.Error;
                    return(temp);
                }
                else
                {
                    temp &= OnEndEvaluateInternalData();
                }
            }
            return(temp);
        }
Exemplo n.º 3
0
        public override bool OnEndEvaluateInternalData()
        {
            bool result = true;

            //make sure result stack is not empty!
            if (ResultsStack.Count == 0)
            {
                return(false);
            }
            else
            {
                result = !(bool)(ResultsStack.Pop());
            }
            AnswerToOutput = result;
            return(true);
        }
Exemplo n.º 4
0
        public override bool OnEndEvaluateInternalData()
        {
            int result = 0;

            //make sure result stack is not empty!
            if (ResultsStack.Count == 0)
            {
                return(false);
            }
            else
            {
                while (ResultsStack.Count != 0)
                {
                    result += (int)ResultsStack.Pop();
                }
            }
            AnswerToOutput = result;
            return(true);
        }
Exemplo n.º 5
0
        public override bool OnEndEvaluateInternalData()
        {
            int result = (int)ResultsStack.ToArray().Last();

            //make sure result stack is not empty!
            if (ResultsStack.Count == 0)
            {
                return(false);
            }
            else
            {
                while (ResultsStack.Count > 1)
                {
                    result /= (int)ResultsStack.Pop();
                }
            }
            ResultsStack.Clear();
            AnswerToOutput = result;
            return(true);
        }
        public void DodajWynikiANastepnieWykonajUndoIRedo(int ileWynikow, int ileUndo, int ileRedo, int expected)
        {
            var rs = new ResultsStack();

            for (int i = 0; i < ileWynikow; ++i)
            {
                rs.AppendNewResult(0, "+");
            }
            for (int i = 0; i < ileUndo; ++i)
            {
                rs.Undo();
            }
            for (int i = 0; i < ileRedo; ++i)
            {
                rs.Redo();
            }
            var actual = rs.GetActiveResultId();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public override bool OnEndEvaluateInternalData()
        {
            if (ResultsStack.Count == 2)
            {
                UnlockingVar = ResultsStack.Pop();
                ChoiceVar    = (int)ResultsStack.Pop();
            }
            else if (ResultsStack.Count == 1)
            {
                ChoiceVar = (int)ResultsStack.Pop();
            }
            else
            {
                ResultsStack.Clear();
            }

            if (ChoiceVar > this.OutputNodes.Count - 1)
            {
                ErrorStack.Push(new DialogueChoiceInvalidException(this.ChoiceVar, this.OutputNodes));
                return(false);
            }
            return(true);
        }
Exemplo n.º 8
0
        public override bool OnEndEvaluateInternalData()
        {
            object in1, in2 = null;

            //there should ALWAYS be 2 in the result stack
            in2 = ResultsStack.Pop();
            in1 = ResultsStack.Pop();

            if (DType == ECOnnectionType.Bool)
            {
                if (CondType == EConditionalTypes.Equals)
                {
                    bOutputTrue = (bool)in1 == (bool)in2;
                }
                else if (CondType == EConditionalTypes.NotEquals)
                {
                    bOutputTrue = (bool)in1 != (bool)in2;
                }
                else
                {
                    ErrorStack.Push(new NodeEditorException("INVALID Conditional type for conditional block: Expected"));
                    return(false);
                }
            }
            else if (DType == ECOnnectionType.Int)
            {
                switch (CondType)
                {
                case (EConditionalTypes.Equals):
                    bOutputTrue = (int)in1 == (int)in2;
                    break;

                case (EConditionalTypes.NotEquals):
                    bOutputTrue = (int)in1 != (int)in2;
                    break;

                case (EConditionalTypes.Greater):
                    bOutputTrue = (int)in1 > (int)in2;
                    break;

                case (EConditionalTypes.GreaterEquals):
                    bOutputTrue = (int)in1 >= (int)in2;
                    break;

                case (EConditionalTypes.Less):
                    bOutputTrue = (int)in1 < (int)in2;
                    break;

                case (EConditionalTypes.LessEquals):
                    bOutputTrue = (int)in1 <= (int)in2;
                    break;

                default:
                    ErrorStack.Push(new NodeEditorException("INVALID Conditional type for conditional block: Expected"));
                    return(false);
                }
            }
            else
            {
                ErrorStack.Push(new NodeEditorException("INVALID data type for conditional block: [NOT SET]"));
                return(false);
            }
            return(true);
        }