예제 #1
0
        public void MatchingNoVariablesTest()
        {
            var t = new CompoundTask("test", 1);

            t.Flags |= CompoundTask.TaskFlags.Fallible;
            t.AddMethod(1, new object[] { 1 }, new LocalVariableName[0], new EmitStep(new [] { "1", "matched" }, null), 0, null, 1);
            t.AddMethod(1, new object[] { 2 }, new LocalVariableName[0], new EmitStep(new [] { "2", "matched" }, null), 0, null, 1);

            Assert.AreEqual("1 matched", new Call(t, new object[] { 1 }, null).Expand());
            Assert.AreEqual("2 matched", new Call(t, new object[] { 2 }, null).Expand());
            Assert.AreEqual(null, new Call(t, new object[] { 3 }, null).Expand());
        }
예제 #2
0
        public void UpwardUnifyTest1()
        {
            var up = new CompoundTask("up", 1);

            up.AddMethod(1, new object[] { "xyz" }, new LocalVariableName[0],
                         null, 0, null, 1);

            var down = new CompoundTask("down", 1);
            // ReSharper disable once InconsistentNaming
            var X = new LocalVariableName("X", 0);

            down.AddMethod(1, new object[] { X }, new[] { X },
                           TestUtils.Sequence(new object[] { toString, X }, new[] { "matched" }), 0,
                           null, 1);

            var test = new CompoundTask("test", 0);
            // ReSharper disable once InconsistentNaming
            var Y = new LocalVariableName("Y", 0);

            test.AddMethod(1, new object[0], new [] { Y },
                           TestUtils.Sequence(new object[] { up, Y }, new object[] { down, Y }), 0,
                           null, 1);

            Assert.AreEqual("Xyz matched", new Call(test, new object[0], null).Expand());
        }
예제 #3
0
        public void DownwardUnifyTest1()
        {
            var t = new CompoundTask("test", 1);
            // ReSharper disable once InconsistentNaming
            var X      = new LocalVariableName("X", 0);
            var locals = new[] { X };

            t.AddMethod(1, new object[] { X }, locals,
                        TestUtils.Sequence(new object[] { toString, X }, new[] { "matched" }), 0,
                        null, 1);

            Assert.AreEqual("1 matched", new Call(t, new object[] { 1 }, null).Expand());
            Assert.AreEqual("2 matched", new Call(t, new object[] { 2 }, null).Expand());
        }
예제 #4
0
    // Start is called before the first frame update
    void Start()
    {
        lvlMgr = FindObjectOfType <LevelManager>();
        player = FindObjectOfType <Self>();
        agent  = GetComponent <NavMeshAgent>();
        /* Build a HTN */
        // var root = new CompoundTask();
        // htn = new HTNPlanner(root);

        // var ApproachCrate = new ApproachObject("crate");
        // var PickUpCrate = new ObstaclePickUp("crate");
        // var ApproachPlayer = new ApproachPlayer();
        // var ThrowObstacle = new ThrowObstacle();

        // var ApproachRock = new ApproachObject("rock");
        // var PickUpRock = new ObstaclePickUp("rock");
        // var ApproachRandom = new ApproachRandom();

        // var getCrate = new CompoundTask();
        // getCrate.AddMethod(new List<Task>() { ApproachCrate, PickUpCrate});

        // var getRock = new CompoundTask();
        // getRock.AddMethod(new List<Task>() { ApproachRock, PickUpRock });

        // root.AddMethod(new List<Task>() { getCrate, ApproachPlayer, ThrowObstacle, ApproachRandom });
        // root.AddMethod(new List<Task>() { getRock, ApproachPlayer, ThrowObstacle, ApproachRandom });

        var root = new CompoundTask();

        htn = new HTNPlanner(root);

        var ApproachCrate  = new ApproachObject("crate");
        var PickUpCrate    = new ObstaclePickUp("crate");
        var ApproachPlayer = new ApproachPlayer();
        var ThrowObstacle  = new ThrowObstacle();

        var ApproachRock = new ApproachObject("rock");
        var PickUpRock   = new ObstaclePickUp("rock");

        var ApproachRandom = new ApproachRandom();

        var attackUsingCrate = new CompoundTask();

        attackUsingCrate.AddMethod(new List <Task>()
        {
            ApproachCrate, PickUpCrate, ApproachPlayer, ThrowObstacle
        });
        attackUsingCrate.AddMethod(new List <Task>()
        {
            ApproachPlayer, ThrowObstacle
        });

        var attackUsingRock = new CompoundTask();

        attackUsingRock.AddMethod(new List <Task>()
        {
            ApproachRock, PickUpRock, ApproachPlayer, ThrowObstacle
        });
        attackUsingRock.AddMethod(new List <Task>()
        {
            ApproachPlayer, ThrowObstacle
        });

        var move = new CompoundTask();

        move.AddMethod(new List <Task>()
        {
            ApproachRandom
        });
        move.AddMethod(new List <Task>()
        {
            ApproachPlayer
        });

        root.AddMethod(new List <Task>()
        {
            attackUsingCrate
        });
        root.AddMethod(new List <Task>()
        {
            attackUsingRock
        });
        root.AddMethod(new List <Task>()
        {
            move
        });
    }