Exemple #1
0
        public void AddExistingStringBehaviourReturnsFalseTest()
        {
            _aic.Clear();
            var ai = new UtilityAi("testai", _aic);

            Assert.That(ai.AddBehaviour("b1"), Is.True);
            Assert.That(ai.AddBehaviour("b1"), Is.False);
        }
Exemple #2
0
        public void DuplicateIsNotAddedTest()
        {
            var ai = new UtilityAi();
            var b  = new Behaviour();

            b.NameId = "some";
            Assert.That(ai.AddBehaviour(b), Is.True);
            Assert.That(ai.AddBehaviour(b), Is.False);
        }
Exemple #3
0
        public void ThinkRecursionDetectionTest()
        {
            _aic.ClearAll();
            var s = new Scheduler();
            // The main AI
            var ta            = new AiTransition("TransitionToCircularAi", "circularAi", _aic);
            var circularAi    = new UtilityAi("circularAi", _aic);
            var coreBehaviour = new Behaviour("cb", _bc);

            coreBehaviour.Selector = new MaxUtilitySelector();
            var circularOption = new ConstantUtilityOption("recursive", _oc);

            circularOption.DefaultUtility = new Utility(1f, 1f);
            circularOption.SetAction("TransitionToCircularAi");

            Assert.That(coreBehaviour.AddOption("recursive"), Is.True);
            Assert.That(circularAi.AddBehaviour(coreBehaviour.NameId), Is.True);

            var dm = new DecisionMaker(circularAi, _toon, s);

            Assert.Throws <DecisionMakerBase.PotentialCircularDependencyException>(dm.Think);
            try {
                dm.Think();
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #4
0
        public void AddNonExistentBehaviourReturnsFalseTest()
        {
            _aic.Clear();
            var ai = new UtilityAi("testai", _aic);

            Assert.That(ai.AddBehaviour("some"), Is.False);
        }
Exemple #5
0
        public void RemoveStringBehaviourReturnsTrueTest()
        {
            _aic.Clear();
            var ai = new UtilityAi("testai", _aic);

            Assert.That(ai.AddBehaviour("b1"), Is.True);
            Assert.That(ai.RemoveBehaviour("b1"), Is.True);
        }
Exemple #6
0
        public void BehaviourSelectionTest()
        {
            var ai      = new UtilityAi();
            var context = new UaiContext();
            var b1      = new Behaviour();

            b1.NameId = "b1";
            var b2 = new Behaviour();

            b2.NameId = "b2";
            var consideration1 = new BehaviourConsideration1();
            var consideration2 = new BehaviourConsideration2();

            b1.AddConsideration(consideration1);
            b2.AddConsideration(consideration2);

            var a1 = new MockAction();

            a1.NameId = "a1";
            var fo1 = new ConstantUtilityOption();

            fo1.SetAction(a1);
            b1.AddOption(fo1);
            var a2 = new MockAction();

            a2.NameId = "a2";
            var fo2 = new ConstantUtilityOption();

            fo2.SetAction(a2);
            b2.AddOption(fo2);

            ai.AddBehaviour(b1);
            ai.AddBehaviour(b2);

            context.Val1 = 1.0f;
            context.Val2 = 0.0f;
            var sel1 = ai.Select(context);

            Assert.That(sel1 == a1);
            context.Val1 = 0.0f;
            context.Val2 = 1.0f;
            var sel2 = ai.Select(context);

            Assert.That(sel2 == a2);
        }
Exemple #7
0
        public void RepeatedDeletionIsOkayTest()
        {
            var ai = new UtilityAi();
            var b  = new Behaviour();

            b.NameId = "beh";
            Assert.That(ai.AddBehaviour(b), Is.True);
            Assert.That(ai.RemoveBehaviour(b), Is.True);
            Assert.That(ai.RemoveBehaviour(b), Is.False);
        }
Exemple #8
0
        public void AddStringBehaviourReturnsFalseWithNullCollectionTest()
        {
            var ai = new UtilityAi();

            Assert.That(ai.AddBehaviour("SomeBehaviour"), Is.False);
        }
Exemple #9
0
        public void AddNullBehaviourReturnsFalseTest()
        {
            var ai = new UtilityAi();

            Assert.That(ai.AddBehaviour((Behaviour)null), Is.False);
        }
Exemple #10
0
 protected override void ConfigureAi()
 {
     Ai = new UtilityAi(AiDefs.ToonAi, AIs);
     Ai.AddBehaviour(BehaviourDefs.LiveLong);
     Ai.AddBehaviour(BehaviourDefs.Prosper);
 }