Beispiel #1
0
 public void Should_count_0_nodes_when_release_all_nodes()
 {
     var sequence = new Sequence("test");
     sequence.AddNode(new SequenceNodeDummy());
     sequence.RemoveAllNodes();
     Check.That(0).IsEqualTo(sequence.NodeCount);
 }
Beispiel #2
0
        public void Should_count_1_when_add_one_node()
        {
            var sequence = new Sequence("test");

            sequence.AddNode(new SequenceNodeDummy());
            Check.That(1).IsEqualTo(sequence.NodeCount);
        }
Beispiel #3
0
        public void Should_count_0_nodes_when_release_all_nodes()
        {
            var sequence = new Sequence("test");

            sequence.AddNode(new SequenceNodeDummy());
            sequence.RemoveAllNodes();
            Check.That(0).IsEqualTo(sequence.NodeCount);
        }
Beispiel #4
0
 public void Should_remove_node()
 {
     var sequence = new Sequence("test");
     var sequenceNodeDummy = new SequenceNodeDummy();
     sequence.AddNode(sequenceNodeDummy);
     sequence.RemoveNode(sequenceNodeDummy);
     Check.That(0).IsEqualTo(sequence.NodeCount);
 }
Beispiel #5
0
        public void Should_return_node_by_id()
        {
            var          sequence          = new Sequence("test");
            SequenceNode sequenceNodeDummy = new SequenceNodeDummy();

            sequence.AddNode(sequenceNodeDummy);
            Check.That(sequenceNodeDummy)
            .IsEqualTo(sequence.GetNodeById(sequenceNodeDummy.Id));
        }
Beispiel #6
0
        public void Should_remove_node()
        {
            var sequence          = new Sequence("test");
            var sequenceNodeDummy = new SequenceNodeDummy();

            sequence.AddNode(sequenceNodeDummy);
            sequence.RemoveNode(sequenceNodeDummy);
            Check.That(0).IsEqualTo(sequence.NodeCount);
        }
        /// <summary>
        ///
        /// </summary>
        public void CreateSequence()
        {
            Sequence.RemoveAllNodes();

            foreach (var node in Network.Nodes)
            {
                node.SeqNode.RemoveAllConnections();
            }

            //connect all nodes
            foreach (var link in Network.Connections)
            {
                if (link.SourceConnector != null &&
                    link.DestConnector != null)
                {
                    if (link.SourceConnector.SourceSlot is NodeSlotVar &&
                        link.DestConnector.SourceSlot is NodeSlotVar)
                    {
                        //In real time the link is in the right direction
                        if (link.SourceConnector.SourceSlot.ConnectionType == SlotType.VarIn)
                        {
                            link.SourceConnector.SourceSlot.ConnectTo(link.DestConnector.SourceSlot);
                        }
                        //When the sequence is loaded from file time the link is not in the right direction
                        else
                        {
                            link.DestConnector.SourceSlot.ConnectTo(link.SourceConnector.SourceSlot);
                        }

                        continue;
                    }

                    if (link.DestConnector.SourceSlot.ConnectionType == SlotType.NodeOut ||
                        link.DestConnector.SourceSlot.ConnectionType == SlotType.VarOut ||
                        link.DestConnector.SourceSlot.ConnectionType == SlotType.VarIn)
                    {
                        link.DestConnector.SourceSlot.ConnectTo(link.SourceConnector.SourceSlot);
                        continue;
                    }

                    if (link.SourceConnector.SourceSlot.ConnectionType == SlotType.NodeOut ||
                        link.SourceConnector.SourceSlot.ConnectionType == SlotType.VarOut ||
                        link.SourceConnector.SourceSlot.ConnectionType == SlotType.VarIn)
                    {
                        link.SourceConnector.SourceSlot.ConnectTo(link.DestConnector.SourceSlot);
                        continue;
                    }
                }
            }

            foreach (var node in Network.Nodes)
            {
                Sequence.AddNode(node.SeqNode);
            }
        }
Beispiel #8
0
 public void Should_reset_all_nodes()
 {
     var sequence = new Sequence("test");
     var sequenceNodeDummy = new SequenceNodeDummy();
     sequence.AddNode(sequenceNodeDummy);
     sequenceNodeDummy.CustomText = "test";
     sequenceNodeDummy.IsProcessing = true;
     sequence.ResetNodes();
     Check.That(sequenceNodeDummy.CustomText).IsEqualTo(null);
     Check.That(sequenceNodeDummy.IsProcessing).IsEqualTo(false);
 }
Beispiel #9
0
 public void Should_allocate_memory_in_MemoryStack()
 {
     var sequence = new Sequence("test");
     var stringNode = new VariableNodeString();
     stringNode.Value = "Test";
     sequence.AddNode(stringNode);
     var memoryStack = new MemoryStack();
     sequence.AllocateAllVariables(memoryStack);
     Check.That(stringNode.Value)
         .IsEqualTo(memoryStack.GetValueFromID(stringNode.Id).Value);
 }
Beispiel #10
0
        public void Should_reset_all_nodes()
        {
            var sequence          = new Sequence("test");
            var sequenceNodeDummy = new SequenceNodeDummy();

            sequence.AddNode(sequenceNodeDummy);
            sequenceNodeDummy.CustomText   = "test";
            sequenceNodeDummy.IsProcessing = true;
            sequence.ResetNodes();
            Check.That(sequenceNodeDummy.CustomText).IsEqualTo(null);
            Check.That(sequenceNodeDummy.IsProcessing).IsEqualTo(false);
        }
Beispiel #11
0
        public void Should_allocate_memory_in_MemoryStack()
        {
            var sequence   = new Sequence("test");
            var stringNode = new VariableNodeString();

            stringNode.Value = "Test";
            sequence.AddNode(stringNode);
            var memoryStack = new MemoryStack();

            sequence.AllocateAllVariables(memoryStack);
            Check.That(stringNode.Value)
            .IsEqualTo(memoryStack.GetValueFromID(stringNode.Id).Value);
        }
Beispiel #12
0
    public void InitBehaviourTree()
    {
        // ********************
        // Initialise Blackboard and store data for later use
        // ********************
        bb = new Blackboard();
        bb.AddData(_agentData.EnemyFlagName, GameObject.Find(_agentData.EnemyFlagName));
        bb.AddData(_agentData.FriendlyFlagName, GameObject.Find(_agentData.FriendlyFlagName));
        bb.AddData(_agentData.EnemyBase.name, GameObject.Find(_agentData.EnemyBase.name));
        bb.AddData(_agentData.FriendlyBase.name, GameObject.Find(_agentData.FriendlyBase.name));
        bb.AddData(Names.HealthKit, GameObject.Find(Names.HealthKit));
        bb.AddData(Names.PowerUp, GameObject.Find(Names.PowerUp));
        bb.AddData("HasEnemyFlag", _agentData.HasEnemyFlag);
        bb.AddData("HasFriendlyFlag", _agentData.HasFriendlyFlag);
        bb.AddData("EnemyFlagCarrier", enemyFlagCarrier);

        enemyFlag    = (GameObject)bb.GetData(_agentData.EnemyFlagName);
        friendlyFlag = (GameObject)bb.GetData(_agentData.FriendlyFlagName);
        enemyBase    = (GameObject)bb.GetData(_agentData.EnemyBase.name);
        friendlyBase = (GameObject)bb.GetData(_agentData.FriendlyBase.name);

        // ********************
        // Composite Nodes
        // ********************
        Sequence mainEntryLoop  = new Sequence(true);
        Selector selecMainEntry = new Selector();
        Sequence seqStealFlag   = new Sequence();
        Sequence seqCarryFlag   = new Sequence();
        Sequence seqAttack      = new Sequence();

        Sequence seqRecoverFlag   = new Sequence();
        Selector selecRecoverFlag = new Selector();
        Sequence seqRecoverPathA  = new Sequence();
        Sequence seqRecoverPathB  = new Sequence();

        // ********************
        // Node connections
        // ********************
        mainEntryLoop.AddNode(selecMainEntry);
        mainEntryLoop.AddNode(new Repeater(mainEntryLoop));

        selecMainEntry.AddNode(seqStealFlag);
        selecMainEntry.AddNode(seqCarryFlag);
        selecMainEntry.AddNode(seqRecoverFlag);

        AttackNearbyEnemy attackNode = new AttackNearbyEnemy(_agentActions, _agentSenses, 0);

        seqAttack.AddNode(attackNode);
        seqAttack.AddNode(new RepeatUntilNodeFails(attackNode));

        seqStealFlag.AddNode(new GoToRandomPos(_agentActions));
        seqStealFlag.AddNode(new Wait(2));
        seqStealFlag.AddNode(new ComparePosition(enemyFlag, enemyBase, 5));
        seqStealFlag.AddNode(new GoToPos(this, _agentActions, enemyBase, 2, seqAttack));
        seqStealFlag.AddNode(new IsItemInView(_agentSenses, enemyFlag));
        seqStealFlag.AddNode(new GoToPos(this, _agentActions, enemyFlag));
        seqStealFlag.AddNode(new CollectItem(_agentActions, _agentSenses, _agentInventory, enemyFlag));

        seqCarryFlag.AddNode(new IsCarryingEnemyFlag(_agentData));
        seqCarryFlag.AddNode(new GoToRandomPos(_agentActions));
        seqCarryFlag.AddNode(new Wait(1));
        seqCarryFlag.AddNode(new GoToPos(this, _agentActions, friendlyBase, 2));
        seqCarryFlag.AddNode(new DropItem(_agentActions, enemyFlag));

        seqRecoverFlag.AddNode(new Inverter(new ComparePosition(friendlyFlag, friendlyBase, 5)));
        seqRecoverFlag.AddNode(selecRecoverFlag);
        selecRecoverFlag.AddNode(seqRecoverPathA);
        selecRecoverFlag.AddNode(seqRecoverPathB);

        seqRecoverPathA.AddNode(new GetEnemyFlagCarrier(this, bb));
        seqRecoverPathA.AddNode(new GoToPos(this, _agentActions, "EnemyFlagCarrier", bb));
        seqRecoverPathA.AddNode(attackNode);

        seqRecoverPathB.AddNode(new GoToPos(this, _agentActions, friendlyFlag));
        seqRecoverPathB.AddNode(new IsItemInView(_agentSenses, friendlyFlag));
        seqRecoverPathB.AddNode(new CollectItem(_agentActions, _agentSenses, _agentInventory, friendlyFlag));
        seqRecoverPathB.AddNode(new GoToPos(this, _agentActions, friendlyBase, 2));
        seqRecoverPathB.AddNode(new DropItem(_agentActions, friendlyFlag));

        // ********************
        // Set root node here and start tree
        // ********************
        myTree = new BehaviourTree(mainEntryLoop, this);
        myTree.Traverse();
    }
Beispiel #13
0
 public void Should_return_node_by_id()
 {
     var sequence = new Sequence("test");
     SequenceNode sequenceNodeDummy = new SequenceNodeDummy();
     sequence.AddNode(sequenceNodeDummy);
     Check.That(sequenceNodeDummy)
         .IsEqualTo(sequence.GetNodeById(sequenceNodeDummy.Id));
 }
Beispiel #14
0
 public void Should_count_1_when_add_one_node()
 {
     var sequence = new Sequence("test");
     sequence.AddNode(new SequenceNodeDummy());
     Check.That(1).IsEqualTo(sequence.NodeCount);
 }