Beispiel #1
0
        private static async Task <Document> InvertIfElseAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            ElseClauseSyntax elseClause = ifStatement.Else;
            StatementSyntax  whenTrue   = ifStatement.Statement;
            StatementSyntax  whenFalse  = elseClause.Statement;

            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            IfStatementSyntax newIfStatement = ifStatement.Update(
                ifKeyword: ifStatement.IfKeyword,
                openParenToken: ifStatement.OpenParenToken,
                condition: Inverter.LogicallyNegate(ifStatement.Condition, semanticModel, cancellationToken),
                closeParenToken: ifStatement.CloseParenToken,
                statement: whenFalse.WithTriviaFrom(whenTrue),
                @else: elseClause.WithStatement(whenTrue.WithTriviaFrom(whenFalse)));

            newIfStatement = newIfStatement.WithFormatterAnnotation();

            return(await document.ReplaceNodeAsync(ifStatement, newIfStatement, cancellationToken).ConfigureAwait(false));
        }
        public void SUCCESS1()
        {
            myTestsFuncs.counter = 0;
            myTestsFuncs.target  = 10;

            Selector rootNode;

            ActionNode T2A;
            Inverter   T2B;
            ActionNode T2C;

            ActionNode T3;

            T3 = new ActionNode(myTestsFuncs.CounterInc);

            T2A = new ActionNode(myTestsFuncs.CounterInc);
            T2B = new Inverter(T3);
            T2C = new ActionNode(myTestsFuncs.CounterInc);

            List <Node> rootChildren = new List <Node>();

            rootChildren.Add(T2A);
            rootChildren.Add(T2B);
            rootChildren.Add(T2C);

            rootNode = new Selector(rootChildren);

            rootNode.Run();

            Assert.AreEqual(NodeStates.SUCCESS, rootNode.NodeState);
        }
Beispiel #3
0
        public FalstadCircuit(TTLGateTypeEnum gateTypes)
        {
            var andGate  = new AndGate(gateTypes, 2);
            var inverter = new Inverter(gateTypes);

            Gates.Add(andGate);
            Gates.Add(inverter);

            Connections.Add(new Connection
            {
                Source      = Input,
                Termination = andGate.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = Input,
                Termination = inverter.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = inverter,
                Termination = andGate.Inputs[1]
            });
        }
Beispiel #4
0
    public BTEnemy(Agent ownerBrain) : base(ownerBrain)
    {
        rootSelector = new Selector();

        enemyCheck          = new Sequence();
        patrolSequence      = new Sequence();
        suspiciousSequence  = new Sequence();
        ChaseSequence       = new Sequence();
        DistractionSequence = new Sequence();

        parallelDetection = new Parallel();
        checkInverter     = new Inverter();

        turnToPoint = new TurnToPoint(GetOwner());
        patrol      = new Patrol(GetOwner());
        wait        = new Wait(GetOwner());

        detection   = new Detection(GetOwner());
        distraction = new Distraction(GetOwner());

        suspicious      = new Suspicious(GetOwner());
        suspiciousAlert = new SuspiciousAlert(GetOwner());
        moveToLKP       = new MoveToLKP(GetOwner());

        seen  = new Seen(GetOwner());
        chase = new Chase(GetOwner());

        //Root -> Patrol and Check
        rootSelector.AddChild(parallelDetection);
        parallelDetection.AddChild(checkInverter);

        //A parallel to check for the player
        checkInverter.AddChild(detection);

        //Patrol alongside checking for the player
        parallelDetection.AddChild(patrolSequence);
        patrolSequence.AddChild(patrol);
        patrolSequence.AddChild(wait);
        patrolSequence.AddChild(turnToPoint);

        //Root -> Adding sequences
        rootSelector.AddChild(suspiciousSequence);
        rootSelector.AddChild(ChaseSequence);
        rootSelector.AddChild(DistractionSequence);

        //Distraction State
        DistractionSequence.AddChild(distraction);
        DistractionSequence.AddChild(wait);

        //Suspicious state
        suspiciousSequence.AddChild(suspicious);
        suspiciousSequence.AddChild(suspiciousAlert);
        suspiciousSequence.AddChild(moveToLKP);
        suspiciousSequence.AddChild(wait);

        //Chase state
        ChaseSequence.AddChild(seen);
        ChaseSequence.AddChild(chase);
        ChaseSequence.AddChild(wait);
    }
        public void Update(int id, Inverter entity)
        {
            if (OpenConnection())
            {
                try
                {
                    SqlConnection Connection = this.Connection;
                    SqlCommand    command    = Connection.CreateCommand();
                    command.CommandText = "EXECUTE updateInverter @Naam,@Merk,@Omschrijving,@Garantie,@Vermogen,@Monitoring,@lengte,@Breedte,@Hoogte,@Serienummer,@Prijs,@Kleur,@ProductId";
                    command.Parameters.AddWithValue("@Naam", entity.Name);
                    command.Parameters.AddWithValue("@Merk", entity.Brand);
                    command.Parameters.AddWithValue("@Omschrijving", entity.Description);
                    command.Parameters.AddWithValue("@Garantie", entity.Warranty);
                    command.Parameters.AddWithValue("@Vermogen", entity.Power);
                    command.Parameters.AddWithValue("@Monitoring", Convert.ToInt32(entity.Monitoring));
                    command.Parameters.AddWithValue("@lengte", entity.Length);
                    command.Parameters.AddWithValue("@Breedte", entity.Width);
                    command.Parameters.AddWithValue("@Hoogte", entity.Height);
                    command.Parameters.AddWithValue("@Serienummer", entity.Serial);
                    command.Parameters.AddWithValue("@Prijs", entity.Price);
                    command.Parameters.AddWithValue("@Kleur", entity.Color);
                    command.Parameters.AddWithValue("@ProductId", entity.Id);

                    command.ExecuteNonQuery();
                }
                catch (SqlException exception)
                {
                }
                finally
                {
                    CloseConnection();
                }
            }
        }
Beispiel #6
0
        void StartUp()
        {
            Thread.Sleep(300);
            ChangeLabel("Loading Database");
            try {
                //throw new Exception();
                invt = Inverter.Load("Inverter.invt");
                Inverter.LogMovement("^^^^^^^^^Succesfully loaded previous Inverter: ");
            } catch (Exception ex) {
                ChangeLabel("Loading Database failed. Creating new one");
                Inverter.LogMovement("!!!!!!!!!Error loading previous Inverter: " + ex.Message);
                invt = new Inverter("../../../Resources/stopwords.txt", "../../../Resources/Dictionary.txt"
                                    , "../../../Resources/commonSfw.txt", "../../../Resources/Formats.txt", new List <string> {
                    "../../../Resources/Sherlock.txt"
                });
            }

            ChangeLabel("Loading Interface");
            this.Invoke(new Action(() => gui = new UNILAG()));
            Querier.Invt = invt;
            //gui = new UNILAG();
            ChangeLabel("Updating Database");
            skippable = true;
            //Crawler
            Thread a = new Thread(new ThreadStart(FirstInvtUpdate));

            a.Start();
        }
Beispiel #7
0
        private static async Task <ExpressionSyntax> CreateNewNodeAsync(
            Document document,
            BinaryExpressionSyntax binaryExpression,
            CancellationToken cancellationToken)
        {
            ExpressionSyntax left  = binaryExpression.Left;
            ExpressionSyntax right = binaryExpression.Right;

            SyntaxTriviaList trivia = binaryExpression
                                      .DescendantTrivia(TextSpan.FromBounds(left.Span.End, right.SpanStart))
                                      .ToSyntaxTriviaList()
                                      .EmptyIfWhitespace();

            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            if (CSharpFacts.IsBooleanLiteralExpression(left.Kind()))
            {
                SyntaxTriviaList leadingTrivia = binaryExpression.GetLeadingTrivia().AddRange(trivia);

                if (right.IsKind(SyntaxKind.LogicalNotExpression))
                {
                    var logicalNot = (PrefixUnaryExpressionSyntax)right;

                    ExpressionSyntax operand = logicalNot.Operand;

                    if (semanticModel.GetTypeInfo(operand, cancellationToken).ConvertedType.IsNullableOf(SpecialType.System_Boolean))
                    {
                        return(binaryExpression
                               .WithLeft(Inverter.LogicallyNegate(left, semanticModel, cancellationToken))
                               .WithRight(operand.WithTriviaFrom(right)));
                    }
                }

                return(Inverter.LogicallyNegate(right, semanticModel, cancellationToken)
                       .WithLeadingTrivia(leadingTrivia));
            }
            else if (CSharpFacts.IsBooleanLiteralExpression(right.Kind()))
            {
                SyntaxTriviaList trailingTrivia = trivia.AddRange(binaryExpression.GetTrailingTrivia());

                if (left.IsKind(SyntaxKind.LogicalNotExpression))
                {
                    var logicalNot = (PrefixUnaryExpressionSyntax)left;

                    ExpressionSyntax operand = logicalNot.Operand;

                    if (semanticModel.GetTypeInfo(operand, cancellationToken).ConvertedType.IsNullableOf(SpecialType.System_Boolean))
                    {
                        return(binaryExpression
                               .WithLeft(operand.WithTriviaFrom(left))
                               .WithRight(Inverter.LogicallyNegate(right, semanticModel, cancellationToken)));
                    }
                }

                return(Inverter.LogicallyNegate(left, semanticModel, cancellationToken)
                       .WithTrailingTrivia(trailingTrivia));
            }

            throw new InvalidOperationException();
        }
        public IActionResult Put(int id, Inverter model)
        {
            var inverter = _repositoryBLL.GetInverter(id);

            _repositoryBLL.PutInverters(inverter);
            return(Ok(inverter));
        }
        private Node MakeDecoratorNode(DecoratorNodeType decorator, uint childNodeID, uint extra = 0)
        {
            Node newNode;

            if (!m_nodeDic.TryGetValue(childNodeID, out Node result))
            {
                return(null);   // failed to get childNodeID
            }
            switch (decorator)
            {
            case DecoratorNodeType.Inverter:
                newNode = new Inverter(result);
                break;

            case DecoratorNodeType.Repeater:
                newNode = new Repeater(result, extra);
                break;

            case DecoratorNodeType.RepeatTillFail:
                newNode = new RepeatTillFail(result);
                break;

            case DecoratorNodeType.Limiter:
                newNode = new Limiter(result);
                break;

            default:
                return(null);    // tried to create unknown decorator node
            }

            return(newNode);
        }
Beispiel #10
0
        private static async Task MakeInvertRequestAsync <T>(Inverter <Box <T> > .InverterClient client, params T[] requests)
        {
            Console.WriteLine($"Starting Invert for type {typeof(T).Name}.");

            using (var clientStream = client.InvertAsync())
            {
                foreach (var request in requests)
                {
                    await clientStream.RequestStream.WriteAsync(Message.From(Box.Create(request)));

                    if (await clientStream.ResponseStream.MoveNext())
                    {
                        var result = clientStream.ResponseStream.Current.Payload.Deserialize().value;
                        Console.WriteLine($"{request} inverted is {result}");
                    }
                    else
                    {
                        throw new Exception($"Unexpected end of response stream after request {request}");
                    }
                }
            }

            Console.WriteLine($"Invert for type {typeof(T).Name} done.");
            Console.WriteLine();
        }
Beispiel #11
0
 public MqttWorker(ILogger <Worker> logger, AppSettings appSettings)
 {
     _logger        = logger;
     config         = appSettings.MQTT;
     inverterConfig = appSettings.Inverter;
     MqttClient     = new MqttClient(config.server);
 }
Beispiel #12
0
 public Group(Equator <X> Equator, Combiner <X> Combiner, X Zero, Inverter <X> Inverter)
 {
     this.Equator  = Equator;
     this.Combiner = Combiner;
     this.zero     = Zero;
     this.Inverter = Inverter;
 }
Beispiel #13
0
    /* We instantiate our nodes from the bottom up, and assign the children
     * in that order */
    void Start()
    {
        /** The deepest-level node is Node 3, which has no children. */
        m_node3 = new ActionNode(NotEqualToTarget, "m_node3");

        /** Next up, we create the level 2 nodes. */
        m_node2A = new ActionNode(AddTen, "m_node2A");

        /** Node 2B is a selector which has node 3 as a child, so we'll pass
         * node 3 to the constructor */
        m_node2B = new Inverter(m_node3, "m_node3");

        m_node2C = new ActionNode(AddTen, "m_node2C");

        /** Lastly, we have our root node. First, we prepare our list of children
         * nodes to pass in */
        List <Node> rootChildren = new List <Node>();

        rootChildren.Add(m_node2A);
        rootChildren.Add(m_node2B);
        rootChildren.Add(m_node2C);

        /** Then we create our root node object and pass in the list */
        m_rootNode = new Selector(rootChildren, "rootNode");

        m_valueLabel.text = m_currentValue.ToString();

        m_rootNode.Evaluate();

        //UpdateBoxes();
    }
        public Inverter GetById(int id)
        {
            string query = "select p.Id,Serienummer,Naam,Prijs,Merk,Omschrijving,Garantie,Voorraad,kleur,lengte,breedte,hoogte,monitoring,vermogen from Product p inner join ProductEigenschappen pe on pe.Id = p.EigenschappenID where TypeID = 2 and p.id = @id";

            if (OpenConnection())
            {
                try
                {
                    using (SqlCommand command = new SqlCommand(query, Connection))
                    {
                        command.Parameters.AddWithValue("@id", id);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Inverter inverter = CreateFromReader(reader);
                                return(inverter);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                }
                finally
                {
                    CloseConnection();
                }
            }
            throw new Exception();
        }
Beispiel #15
0
    // Use this for initialization
    void Start()
    {
        node3LihatMusuh            = new ActionNode(isLihatMusuh, "Node 3 Lihat Musuh");
        node3MusuhMenembak         = new ActionNode(isMusuhMenembak, "Node 3 Musuh Menembak");
        node2InverterLihatMusuh    = new Inverter(node3LihatMusuh, "Node 3 Lihat Musuh");
        node2InverterMusuhMenembak = new Inverter(node3MusuhMenembak, "Node 3 Musuh Menembak");
        node2Tembak = new ActionNode(Serang, "Node 2 Tembak");

        List <Node> seqMenghindar = new List <Node>();

        seqMenghindar.Add(node2InverterMusuhMenembak);
        seqMenghindar.Add(node2Tembak);
        List <Node> seqPatroli = new List <Node>();

        seqPatroli.Add(node2InverterLihatMusuh);

        node1Menghindar = new Selector(seqMenghindar, "");
        node1Patroli    = new Selector(seqPatroli, "");

        List <Node> rootChildren = new List <Node>();

        rootChildren.Add(node2InverterLihatMusuh);
        rootChildren.Add(node2InverterMusuhMenembak);
        rootChildren.Add(node2Tembak);

        rootNode = new Selector(rootChildren, "Root Node");
        rootNode.Evaluate();
    }
            public void Returns_failure_when_child_returns_success()
            {
                var inverter = new Inverter();

                inverter.AddChild(A.TaskStub().Build());

                Assert.AreEqual(TaskStatus.Failure, inverter.Update());
            }
Beispiel #17
0
        public void UnchangedIfDisabled()
        {
            var inverter = new Inverter();

            inverter.IsEnabled = false;

            Assert.AreEqual(1, inverter.Process(1));
        }
            public void Returns_continue_when_child_returns_continue()
            {
                var inverter = new Inverter();

                inverter.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Continue).Build());

                Assert.AreEqual(TaskStatus.Continue, inverter.Update());
            }
Beispiel #19
0
    private static void LoadInverter(GameObject LoadedObject, SavedObject save)
    {
        object[] data    = save.CustomDataArray;
        Inverter notgate = LoadedObject.GetComponent <Inverter>();

        notgate.Input.On  = (bool)data[0];
        notgate.Output.On = (bool)data[1];
    }
            public void Returns_true_when_child_returns_false()
            {
                var inverter = new Inverter();

                inverter.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Failure).Build());

                Assert.AreEqual(TaskStatus.Success, inverter.Update());
            }
        public void NoChild()
        {
            var inverter = new Inverter();

            inverter.Start();
            inverter.Update();

            Assert.AreEqual(NodeState.Error, inverter.Status);
        }
Beispiel #22
0
        public void WhenChildReturnFailure_ReturnSuccess()
        {
            var sut = new Inverter <MockContext>(new MockBehaviour {
                ReturnStatus = BehaviourStatus.Failed
            });

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Succeeded));
        }
Beispiel #23
0
        public void WhenChildReturnRunning_ReturnRunning()
        {
            var sut = new Inverter <MockContext>(new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            });

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
        }
Beispiel #24
0
        public void Inverter_FailureWhenChildSucess()
        {
            INode node = Substitute.For <INode>();

            node.Tick().Returns(NodeStatus.Sucess);

            Inverter inverter = new Inverter(node);

            Assert.AreEqual(NodeStatus.Failure, inverter.Tick());
        }
Beispiel #25
0
        public void Inverter()
        {
            var i = new Inverter();

            i.Inputs[0] = t;
            Assert.IsFalse(i[0]);

            i.Inputs[0] = f;
            Assert.IsTrue(i[0]);
        }
Beispiel #26
0
    //builds the characters behaviour tree
    private void constructBehaviourTree()
    {
        //health node checks if health is below threshold
        HealthNode healthNode = new HealthNode(this, m_lowHealthThreshold);

        //inverted health checks if health is above threshhold
        Inverter invertHealth = new Inverter(healthNode);

        //Cover

        GetCoverNode getCoverNode = new GetCoverNode(target.transform, this);

        GoToCoverNode goToCoverNode = new GoToCoverNode(this, m_speed);

        HealNode Heal = new HealNode(20, this, m_healthRegenRate);

        Sequence CoverSequence = new Sequence(new List <BNode> {
            healthNode, getCoverNode, goToCoverNode, Heal
        });

        //chase
        Range = new RangeNode(m_detectionRange, target.transform, gameObject.transform, this);

        Chase = new ChaseNode(target.transform, this, m_speed);

        Sequence ChaseSequence = new Sequence(new List <BNode> {
            invertHealth, Range, Chase
        });

        //wander
        RangeNode wanderRange = new RangeNode(m_detectionRange, target.transform, gameObject.transform, this);

        Inverter invertWanderRange = new Inverter(wanderRange);

        WanderNode wander = new WanderNode(this, m_speed);

        Sequence WanderSequence = new Sequence(new List <BNode> {
            invertWanderRange, wander
        });

        //attack
        attackRange = new RangeNode(m_attackRange, target.transform, gameObject.transform, this);

        attack = new AttackNode(target.transform, this);

        Sequence AttackSequence = new Sequence(new List <BNode> {
            attackRange, attack
        });


        //root node
        topNode = new Selector(new List <BNode> {
            CoverSequence, AttackSequence, ChaseSequence, WanderSequence
        });
    }
Beispiel #27
0
        public static BComponent BuildComponent(XmlNode xmlDoc, BComponent parent, Behaviors behavior)
        {
            string name = xmlDoc.Name;

            if (ActionBool.NAME == name)
            {
                return(ActionBool.Build(xmlDoc, parent, behavior));
            }
            else if (ActionProperty.NAME == name)
            {
                return(ActionProperty.Build(xmlDoc, parent, behavior));
            }
            else if (ActionVoid.NAME == name)
            {
                return(ActionVoid.Build(xmlDoc, parent, behavior));
            }
            else if (ActionEnumerator.NAME == name)
            {
                return(ActionEnumerator.Build(xmlDoc, parent, behavior));
            }
            else if (RandomSelector.NAME == name)
            {
                return(RandomSelector.Build(xmlDoc, parent, behavior));
            }
            else if (RootSelector.NAME == name)
            {
                return(RootSelector.Build(xmlDoc, parent, behavior));
            }
            else if (Selector.NAME == name)
            {
                return(Selector.Build(xmlDoc, parent, behavior));
            }
            else if (Sequence.NAME == name)
            {
                return(Sequence.Build(xmlDoc, parent, behavior));
            }
            else if (Inverter.NAME == name)
            {
                return(Inverter.Build(xmlDoc, parent, behavior));
            }
            else if (UntilTrue.NAME == name)
            {
                return(UntilTrue.Build(xmlDoc, parent, behavior));
            }
            else if (UntilFalse.NAME == name)
            {
                return(UntilFalse.Build(xmlDoc, parent, behavior));
            }
            else
            {
                Debug.LogErrorFormat("I did not find the item: {0}", name);
                return(null);
            }
        }
Beispiel #28
0
 private void CreateInverter(INode node)
 {
     try
     {
         Inverter inverter = new Inverter(node);
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is ArgumentNullException);
     }
 }
Beispiel #29
0
        public void InverterTest()
        {
            var a   = new Switch();
            var inv = new Inverter();

            a.AttachTo(inv, 0);
            Assert.IsTrue(inv.OutState());

            a.State = true;
            Assert.IsFalse(inv.OutState());
        }
        public void SUCCESS1()
        {
            myTestsFuncs.counter = 0;
            myTestsFuncs.target  = 10;
            ActionNode IncAction = new ActionNode(myTestsFuncs.CounterInc);
            Inverter   test      = new Inverter(IncAction);

            test.Run();

            Assert.AreEqual(NodeStates.SUCCESS, test.NodeState);
        }
	// Use this for initialization
	void Start () 
    {
        mRoot = new RepeatUntilFail(null);

        //Level 0 (Not normally a thing but I didnt think it through ...
        //normally starts at root then level 1 comes next
        Sequence l0_sequence = new Sequence(mRoot);

        //level 1
        GetStackOfPOIs l1_getStack = new GetStackOfPOIs(l0_sequence, "poiStack");
        RepeatUntilFail l1_RepeatUntilFail = new RepeatUntilFail(l0_sequence);
        SpawnPOIs l1_spawnPOIs = new SpawnPOIs(l0_sequence, mPOIPrefab);

        //level 2
        Sequence l2_sequence = new Sequence(l1_RepeatUntilFail);

        //level 3
        Inverter l3_inverter = new Inverter(l2_sequence);
        RepeatUntilFail l3_ruf = new RepeatUntilFail(l2_sequence);
        WalkToObject l3_walkToObject = new WalkToObject(l2_sequence, "Basket");
        DropPOI l3_dropPOI = new DropPOI(l2_sequence);

        //level 4
        IsStackEmpty l4_isStackEmpty = new IsStackEmpty(l3_inverter, "poiStack");
        Sequence l4_sequence = new Sequence(l3_ruf);

        //level 5
        CanCarryPOI l5_canCarry = new CanCarryPOI(l4_sequence);
        Sequence l5_sequence = new Sequence(l4_sequence);

        //level 6
        PopFromStack l6_popFromStack = new PopFromStack(l5_sequence, "poiStack", "item");
        WalkToPOI l6_walkTo = new WalkToPOI(l5_sequence, "item");
        PickupPOI l6_pickup = new PickupPOI(l5_sequence, "item");

        if(mBehaveOnStart) Begin();
	}
Beispiel #32
0
 public void DrawInspector(Inverter node)
 {
     EditorGUILayout.LabelField(new GUIContent("Inveter"), TitleStyle);
     EditorGUILayout.Space ();
     string message = "Like the NOT operator, the inverter decorator negates the result of its child node, i.e., SUCCESS state becomes FAILURE, and FAILURE becomes SUCCESS. RUNNING or ERROR states are returned as is.";
     EditorGUILayout.HelpBox(message, MessageType.Info);
     EditorGUILayout.HelpBox("Not yet implemented!", MessageType.Error);
 }