예제 #1
0
    [Test] public void TreeA()
    {
        MockCondition isSafe = new MockCondition(BehaviorStatus.Failure);
        MockCondition isFoodNearby = new MockCondition(BehaviorStatus.Success);
        MockAction run = new MockAction(BehaviorStatus.Running);
        MockAction eat = new MockAction(BehaviorStatus.Running);

        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Selector())
            .Sequence("Run")
                .Decorator(new Invert())
                    .Condition(isSafe)
                .Action(run)
            .End()
            .Sequence("Eat")
                .Condition(isFoodNearby)
                .Action(eat)
            .End()
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Running);

        run.status = BehaviorStatus.Success;
        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Success);

        isSafe.status = BehaviorStatus.Success;
        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Running);

        eat.status = BehaviorStatus.Success;
        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Success);

        isFoodNearby.status = BehaviorStatus.Failure;
        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Failure);
    }
예제 #2
0
    [Test] public void Sequence_FirstChildRunningAndNextChildSuccess()
    {
        MockAction mockActionA = new MockAction(BehaviorStatus.Running);

        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Sequence())
            .Action(mockActionA)
            .Condition(new MockCondition(BehaviorStatus.Success))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Running);

        mockActionA.status = BehaviorStatus.Failure;
        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Failure);
    }
예제 #3
0
    [Test] public void Condition_Failure()
    {
        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Selector())
            .Condition(new MockCondition(BehaviorStatus.Failure))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Failure);
    }
예제 #4
0
    [Test] public void Action_Success()
    {
        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Selector())
            .Action(new MockAction(BehaviorStatus.Success))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Success);
    }
예제 #5
0
    [Test] public void Selector_BothChildrenSuccess()
    {
        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Selector())
            .Condition(new MockCondition(BehaviorStatus.Success))
            .Condition(new MockCondition(BehaviorStatus.Success))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Success);
    }
예제 #6
0
    [Test] public void Decorator_Invert_ChildFailure()
    {
        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Selector())
            .Decorator(new Invert())
                .Condition(new MockCondition(BehaviorStatus.Failure))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Success);
    }
예제 #7
0
    [Test] public void Sequence_FirstChildFailureAndNextChildSuccess()
    {
        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Sequence())
            .Condition(new MockCondition(BehaviorStatus.Failure))
            .Condition(new MockCondition(BehaviorStatus.Success))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Failure);
    }
예제 #8
0
    [Test] public void Sequence_BothChildrenFailure()
    {
        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Sequence())
            .Condition(new MockCondition(BehaviorStatus.Failure))
            .Condition(new MockCondition(BehaviorStatus.Failure))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Failure);
    }
예제 #9
0
    [Test] public void Decorator_Repeat_ChildFailure()
    {
        Repeat repeat = new Repeat(10);

        BehaviorTree behaviorTree = new BehaviorTreeBuilder<BehaviorTree>(new Selector())
            .Decorator(repeat)
                .Condition(new MockCondition(BehaviorStatus.Failure))
        .Build();

        Assert.IsTrue(behaviorTree.Tick() == BehaviorStatus.Failure);
        Assert.IsTrue(repeat.repetitionCount == 0);
    }
        public void It_should_run_the_custom_action()
        {
            var result = false;
            var tree   = new BehaviorTreeBuilder(null)
                         .Sequence()
                         .ExampleAction("test", () => result = true)
                         .End()
                         .Build();

            tree.Tick();

            Assert.IsTrue(result);
        }
예제 #11
0
        public void It_should_run_the_custom_action()
        {
            var result = false;
            var tree   = new BehaviorTreeBuilder(null)
                         .CustomSequence("test")
                         .Do(() => {
                result = true;
                return(TaskStatus.Success);
            })
                         .End()
                         .Build();

            tree.Tick();

            Assert.IsTrue(result);
        }