예제 #1
0
        public void Run()
        {
            bool leafNode   = LeafNode();
            bool rightGuess = RightGuess();

            if (leafNode)
            {
                if (rightGuess)
                {
                    Console.WriteLine("Acertei de novo!");
                }
                else
                {
                    PlayerWin();
                }
                return;
            }

            if (rightGuess)
            {
                TrueNode.Run();
            }
            else
            {
                FalseNode.Run();
            }
        }
예제 #2
0
        public bool Evaluate(Client client)
        {
            var conditionResult = Condition(client);

            Console.WriteLine("Condition is={0} Result={1}", ConditionDesc, conditionResult);
            return(conditionResult ? (TrueNode == null ? conditionResult: TrueNode.Evaluate(client))
                                    : FalseNode == null ? conditionResult : FalseNode.Evaluate(client));
        }
예제 #3
0
 override public void addToModel()
 {
     base.addToModel();
     TrueNode.addToModel();
     BackNode.addToModel();
     //Controller.Model.Shapes.Add(holderTag,holderNode.Shape);
     //  Model.Lines.Add(backConnectorTag, backConnector.Connector);
 }
예제 #4
0
        public void Should_evaluate_true_for_true()
        {
            var inputNode = new TrueNode();
            var evaluator = new BooleanEvaluator();
            var result    = evaluator.Eval(inputNode);

            result.ShouldBeOfType <TrueNode>();
        }
예제 #5
0
 internal override void Walk(NodeWalker walker, int depth, bool wrap)
 {
     walker("(", TestValue ? TrueValue : FalseValue, depth);
     Condition.Walk(walker, depth + 1, false);
     walker(" ? ");
     TrueNode.Walk(walker, depth + 1, false);
     walker(" : ");
     FalseNode.Walk(walker, depth + 1, false);
     walker(")");
 }
예제 #6
0
 public IAIAction GetAction()
 {
     if (Condition.Resolve())
     {
         return(TrueNode.GetAction());
     }
     else
     {
         return(FalseNode.GetAction());
     }
 }
예제 #7
0
 private void FalseActionOnStopped_Listener(bool success)
 {
     if (_isConditionMetFunc() && State == NodeState.ACTIVE)
     {
         TrueNode.StartNodeOnNextTick();
     }
     else
     {
         StopNodeOnNextTick(success);
     }
 }
예제 #8
0
 private void OnStarted_Listener()
 {
     if (_isConditionMetFunc())
     {
         TrueNode.StartNodeOnNextTick();
     }
     else
     {
         FalseNode.StartNodeOnNextTick();
     }
 }
예제 #9
0
        override public void setText(String label)
        {
            float oldWidth = Shape.Width;

            base.setText(label);
            //if the shape is bigger then move nodes to right by the difference
            if (!Controller.LoadingProject)
            {
                TrueNode.shiftRight((int)(Shape.Width - oldWidth));
                BackNode.shiftRight((int)(Shape.Width - oldWidth));
            }
        }
예제 #10
0
        public override void Update(UpdateType updateType = UpdateType.DEFAULT)
        {
            base.Update(updateType);

            if (_isConditionMetFunc() && IsFalseNodeMode())
            {
                FalseNode.RequestStopNode();
            }
            else if (!_isConditionMetFunc() && IsTrueNodeMode())
            {
                TrueNode.RequestStopNode();
            }
        }
        public void ShouldSerialiseTrueCorrectly()
        {
            // arrange
            var node = new TrueNode();
            var doc  = new XmlDocument();

            var snf = new StalkNodeFactory(this.phabExternalMock.Object);

            // act
            var result = snf.ToXml(doc, node);

            // assert
            Assert.AreEqual("<true />", result.OuterXml);
        }
예제 #12
0
 private void OnStopping_Listener()
 {
     if (TrueNode.State == NodeState.ACTIVE)
     {
         TrueNode.RequestStopNodeOnNextTick();
     }
     else if (FalseNode.State == NodeState.ACTIVE)
     {
         FalseNode.RequestStopNodeOnNextTick();
     }
     else
     {
         StopNodeOnNextTick(false);
     }
 }
        public override dynamic Execute(ScriptContext context)
        {
            dynamic c = Condition.Execute(context);
            dynamic r;

            if (c)
            {
                r = TrueNode.Execute(context);
            }
            else
            {
                r = FalseNode.Execute(context);
            }
            return(r);
        }
예제 #14
0
 protected void attachToTrue(BaseNode newNode, bool addToEnd)
 {
     if (addToEnd) //this means that the clicked link is between holder and loop
     {
         //add this node to last node in true link
         BaseNode lastNode = TrueNode;
         while (!(lastNode.OutConnector.EndNode is HolderNode))
         {
             lastNode = lastNode.OutConnector.EndNode;
         }
         lastNode.attachNode(newNode);
     }
     else
     {
         TrueNode.attachNode(newNode);
     }
 }
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            ScriptVariableType retType1, retType2;

            Condition = TypeCastExecutionNode.ImplicitCast(parser, level + 1, ScriptVariableType.Bool, Condition);

            retType1 = TrueNode.Process(parser, level + 1);
            retType2 = FalseNode.Process(parser, level + 1);

            if (retType1 != retType2)
            {
                parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.TrueAndFalseNodesMustBeOfSameValueInTernaryOperation, this, retType1, retType2));
            }

            return(retType1);
        }
예제 #16
0
        protected override void moveConnections()
        {
            Shape.Location = new PointF(nodeLocation.X, nodeLocation.Y + shiftY);
            PointF point    = new PointF(Shape.Width + Shape.Location.X + horizontalSpace, startNode.Shape.Center.Y - TrueNode.Shape.Size.Height / 2);
            PointF oldPlace = TrueNode.NodeLocation;

            TrueNode.NodeLocation = point;
            // backNode.NodeLocation = new PointF(point.X, point.Y + 100);
            if (TrueConnector.EndNode == null)
            {
                TrueConnector.EndNode = TrueNode;
                //this.OutConnector.EndNode.shiftDown();
                TrueNode.attachNode(BackNode);
                return;
                //      holderNode.attachNode(this, backConnector);
            }
            BackNode.NodeLocation = new PointF(point.X, BackNode.NodeLocation.Y);
            if (moveDirection == MOVE_DOWN)
            {
                TrueNode.OutConnector.EndNode.shiftDown(moreShift);
            }
            else if (moveDirection == MOVE_UP)
            {
                TrueNode.OutConnector.EndNode.shiftUp(oldPlace.Y - point.Y);
                //   OutConnector.EndNode.shiftUp(); //shift main track
            }

            /* if (TrueNode.OutConnector.EndNode is HolderNode)
             * {
             *   BackNode.NodeLocation = new PointF(point.X, point.Y + 60);
             *   shiftMainTrack();
             * }
             *
             * else
             * {
             *   TrueNode.OutConnector.EndNode.shiftDown(moreShift);
             *
             * }*/
        }
예제 #17
0
        public Node SimpleLiteral()
        {
            switch (CurrentToken)
            {
            case TokenCategory.INT_LITERAL:
                var intLiteral = new IntLiteralNode()
                {
                    AnchorToken = Expect(TokenCategory.INT_LITERAL)
                };
                return(intLiteral);


            case TokenCategory.STR_LITERAL:
                var str_literal = Expect(TokenCategory.STR_LITERAL);
                var strLiteral  = new StrLiteralNode()
                {
                };
                strLiteral.AnchorToken = str_literal;
                return(strLiteral);

            case TokenCategory.TRUE:
                var trueLiteral = new TrueNode()
                {
                    AnchorToken = Expect(TokenCategory.TRUE)
                };
                return(trueLiteral);

            case TokenCategory.FALSE:
                var falseLiteral = new FalseNode()
                {
                    AnchorToken = Expect(TokenCategory.FALSE)
                };
                return(falseLiteral);

            default:
                throw new SyntaxError(firstOfDeclaration,
                                      tokenStream.Current);
            }
        }
예제 #18
0
 public void Visit(TrueNode node)
 {
 }
예제 #19
0
        public IStalkNode NewFromXmlFragment(XmlElement fragment)
        {
            IStalkNode node;

            switch (fragment.Name)
            {
            case "and":
            case "or":
            case "x-of":
                node = this.NewMultiChildNode(fragment);
                break;

            case "xor":
                node = this.NewDoubleChildNode(fragment);
                break;

            case "not":
            case "external":
            case "expiry":
                node = this.NewSingleChildNode(fragment);
                break;

            case "user":
            case "page":
            case "summary":
            case "flag":
            case "usergroup":
            case "incategory":
            case "log":
            case "additionaldata":
            case "targetuser":
            case "actinguser":
                node = this.NewLeafNode(fragment);
                break;

            case "infixnumeric":
                node = this.NewInfixNumeric(fragment);
                break;

            case "true":
                node = new TrueNode();
                break;

            case "false":
                node = new FalseNode();
                break;


            default:
                throw new XmlException("Unknown element " + fragment.Name);
            }

            var fragmentAttribute = fragment.Attributes["comment"];

            if (fragmentAttribute != null)
            {
                node.Comment = fragmentAttribute.Value;
            }

            return(node);
        }
예제 #20
0
        public void TrueNodeTest()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);

            TrueNode sut = new TrueNode(expectedLocation);

            Assert.AreEqual(TNode.TRUE, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("TRUE"));

            Assert.AreEqual(ExpressionType.Constant, sut.SubExpression.NodeType);
            Assert.IsInstanceOfType(sut.SubExpression, typeof(ConstantExpression));
            Assert.AreEqual(typeof(bool), ((ConstantExpression)sut.SubExpression).Type);
            Assert.AreEqual(true, ((ConstantExpression)sut.SubExpression).Value);
        }