Package org.terasology.logic.behavior.tree

Examples of org.terasology.logic.behavior.tree.Interpreter$Debugger


        }
        save(tree);
    }

    private void addEntity(EntityRef entityRef, BehaviorComponent behaviorComponent) {
        Interpreter interpreter = entityInterpreters.get(entityRef);
        if (interpreter == null) {
            interpreter = new Interpreter(new Actor(entityRef));
            BehaviorTree tree = behaviorComponent.tree;
            entityInterpreters.put(entityRef, interpreter);
            if (tree != null) {
                interpreter.start(tree.getRoot());
            }
        }
    }
View Full Code Here


* @author synopia
*/
public class RepeatTest {
    @Test
    public void test0() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(0);
        RepeatNode repeatNode = new RepeatNode(debugNode);
        interpreter.start(repeatNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask first = debugNode.lastTask2;
        Assert.assertTrue(first.updateCalled);
        Assert.assertTrue(first.initializeCalled);
        Assert.assertTrue(first.terminateCalled);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask second = debugNode.lastTask2;
        Assert.assertTrue(second.updateCalled);
        Assert.assertTrue(second.initializeCalled);
        Assert.assertTrue(second.terminateCalled);
        Assert.assertNotSame(first, second);

        Assert.assertTrue(interpreter.tick(0) > 0);
    }
View Full Code Here

        Assert.assertTrue(interpreter.tick(0) > 0);
    }

    @Test
    public void test1() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(1);
        RepeatNode repeatNode = new RepeatNode(debugNode);

        interpreter.start(repeatNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask first = debugNode.lastTask;
        Assert.assertTrue(first.updateCalled);
        Assert.assertTrue(first.initializeCalled);
        Assert.assertTrue(!first.terminateCalled);
        first.reset();

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask last = debugNode.lastTask2;
        Assert.assertTrue(last.updateCalled);
        Assert.assertTrue(!last.initializeCalled);
        Assert.assertTrue(last.terminateCalled);
        Assert.assertSame(first, last);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask second = debugNode.lastTask;
        Assert.assertTrue(second.updateCalled);
        Assert.assertTrue(second.initializeCalled);
        Assert.assertTrue(!second.terminateCalled);
        Assert.assertNotSame(first, second);

        Assert.assertTrue(interpreter.tick(0) > 0);
    }
View Full Code Here

        Assert.assertTrue(interpreter.tick(0) > 0);
    }

    @Test
    public void testRepeatEndless() {
        Interpreter interpreter = new Interpreter(null);
        RepeatNode repeat = new RepeatNode(create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.SUCCESS);
            }
        }));

        Task task = interpreter.start(repeat);
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
    }
View Full Code Here

        Assert.assertEquals(Status.RUNNING, task.getStatus());
    }

    @Test
    public void testRepeat() {
        Interpreter interpreter = new Interpreter(null);
        RepeatNode repeat = new RepeatNode(create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.SUCCESS);
            }
        }));

        Task task = interpreter.start(repeat);
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
    }
View Full Code Here

        Assert.assertEquals(Status.RUNNING, task.getStatus());
    }

    @Test
    public void testFilter() {
        Interpreter interpreter = new Interpreter(null);
        Node mock = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING);
            }
        });

        ParallelNode move = new ParallelNode(ParallelNode.Policy.RequireOne, ParallelNode.Policy.RequireOne);

        move.children().add(new DebugNode(3));
        move.children().add(mock);
        Task task = interpreter.start(move);
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.SUCCESS, task.getStatus());
    }
View Full Code Here

*/
public class CounterTest {

    @Test
    public void test00() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(0);
        CounterNode counterNode = new CounterNode(0, debugNode);
        interpreter.start(counterNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        Assert.assertNull(debugNode.lastTask);
        Assert.assertTrue(interpreter.tick(0) == 0);
    }
View Full Code Here

        Assert.assertTrue(interpreter.tick(0) == 0);
    }

    @Test
    public void test01() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(0);
        CounterNode counterNode = new CounterNode(1, debugNode);

        interpreter.start(counterNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        Assert.assertTrue(debugNode.lastTask.updateCalled);
        Assert.assertTrue(debugNode.lastTask.initializeCalled);
        Assert.assertTrue(debugNode.lastTask.terminateCalled);
        debugNode.lastTask = null;

        Assert.assertTrue(interpreter.tick(0) == 0);
    }
View Full Code Here

        Assert.assertTrue(interpreter.tick(0) == 0);
    }

    @Test
    public void test11() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(1);
        CounterNode counterNode = new CounterNode(1, debugNode);

        interpreter.start(counterNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask first = debugNode.lastTask;
        Assert.assertTrue(first.updateCalled);
        Assert.assertTrue(first.initializeCalled);
        Assert.assertTrue(!first.terminateCalled);
        first.reset();

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask last = debugNode.lastTask;
        Assert.assertTrue(last.updateCalled);
        Assert.assertTrue(!last.initializeCalled);
        Assert.assertTrue(last.terminateCalled);
        Assert.assertSame(first, last);

        Assert.assertTrue(interpreter.tick(0) == 0);
    }
View Full Code Here

        Assert.assertTrue(interpreter.tick(0) == 0);
    }

    @Test
    public void testX() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(10);

        interpreter.start(debugNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask first = debugNode.lastTask;
        Assert.assertTrue(first.updateCalled);
        Assert.assertTrue(first.initializeCalled);
        Assert.assertTrue(!first.terminateCalled);
        first.reset();

        for (int i = 0; i < 9; i++) {
            Assert.assertTrue(interpreter.tick(0) > 0);
            DebugNode.DebugTask current = debugNode.lastTask;
            Assert.assertSame(first, current);
            Assert.assertTrue(current.updateCalled);
            Assert.assertTrue(!current.initializeCalled);
            Assert.assertTrue(!current.terminateCalled);
            current.reset();
        }

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask last = debugNode.lastTask;
        Assert.assertTrue(last.updateCalled);
        Assert.assertTrue(!last.initializeCalled);
        Assert.assertTrue(last.terminateCalled);
        Assert.assertSame(first, last);

        Assert.assertTrue(interpreter.tick(0) == 0);
    }
View Full Code Here

TOP

Related Classes of org.terasology.logic.behavior.tree.Interpreter$Debugger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.