예제 #1
0
        public void InverterNodeTest()
        {
            var root    = new Inverter();
            var stages  = new Queue <string>();
            var manager = new BehaviourTree(root);

            root.Children.Add(new TestYieldConditionNode()
            {
                PrintA = "Yield", PrintB = "A", Stages = stages, Conditional = s => s.A
            });
            foreach (var n in root.DepthFirstIterate())
            {
                n.Initialize();
            }

            Assert.AreEqual(0UL, manager.TickCount);

            // true => false
            stages.Enqueue("TICK");
            manager.Update(new State {
                A = true
            });

            Assert.AreEqual(Result.Unknown, manager.Result);
            Assert.AreEqual(0UL, manager.TickCount);

            var sequence = new List <string> {
                "TICK", "Yield"
            };

            Assert.IsTrue(stages.SequenceEqual(sequence));

            stages.Enqueue("TICK");
            manager.Update(new State {
                A = true
            });

            Assert.AreEqual(Result.Failure, manager.Result);
            Assert.AreEqual(1UL, manager.TickCount);

            sequence.AddRange(new[] { "TICK", "A" });
            Assert.IsTrue(stages.SequenceEqual(sequence));

            // false => true
            stages.Enqueue("TICK");
            manager.Update(new State {
                A = false
            });

            Assert.AreEqual(Result.Unknown, manager.Result);
            Assert.AreEqual(1UL, manager.TickCount);

            sequence.AddRange(new[] { "TICK", "Yield" });
            Assert.IsTrue(stages.SequenceEqual(sequence));

            stages.Enqueue("TICK");
            manager.Update(new State {
                A = false
            });

            Assert.AreEqual(Result.Success, manager.Result);
            Assert.AreEqual(2UL, manager.TickCount);

            sequence.AddRange(new[] { "TICK", "A" });
            Assert.IsTrue(stages.SequenceEqual(sequence));
        }