Java 类com.badlogic.gdx.ai.btree.branch.Parallel 实例源码

项目:gdx-ai    文件:ParallelVsSequenceTest.java   
private Predator createPredator (boolean parallel) {
    Predator predator = new Predator(parallel ? badlogicTextureRegion : greenFishTextureRegion, this);
    predator.setPosition(MathUtils.random(stage.getWidth()), MathUtils.random(stage.getHeight()), Align.center);
    predator.setMaxLinearSpeed(100);
    predator.setMaxLinearAcceleration(600);

    final Pursue<Vector2> pursueSB = new Pursue<Vector2>(predator, null, .5f);
    predator.setSteeringBehavior(pursueSB);
    testTable.addActor(predator);

    BranchTask<Predator> branch = parallel ? new Parallel<Predator>() : new Sequence<Predator>();
    branch.addChild(new SelectTargetTask());
    branch.addChild(new PursueTask());
    predator.btree = new BehaviorTree<Predator>(branch, predator);

    return predator;
}
项目:gdx-ai    文件:ResumeVsJoinTest.java   
private Predator createPredator (boolean join) {
    Predator predator = new Predator(join ? badlogicTextureRegion : greenFishTextureRegion, this);
    predator.setPosition(MathUtils.random(stage.getWidth()), MathUtils.random(stage.getHeight()), Align.center);
    predator.setMaxLinearSpeed(100);
    predator.setMaxLinearAcceleration(600);

    final Pursue<Vector2> pursueSB = new Pursue<Vector2>(predator, null, .5f);
    predator.setSteeringBehavior(pursueSB);
    testTable.addActor(predator);

    BranchTask<Predator> branch = join ? new Parallel<Predator>(Orchestrator.Join) : new Parallel<Predator>(Orchestrator.Resume);
    branch.addChild(new SpinAroundTask());
    branch.addChild(new SelectTargetTask());
    branch.addChild(new PursueTask());
    predator.btree = new BehaviorTree<Predator>(branch, predator);

    return predator;
}
项目:gdx-ai    文件:ProgrammaticallyCreatedTreeTest.java   
private static Task<Dog> createDogBehavior () {
    Selector<Dog> selector = new Selector<Dog>();

    Parallel<Dog> parallel = new Parallel<Dog>();
    selector.addChild(parallel);

    CareTask care = new CareTask();
    care.urgentProb = 0.8f;
    parallel.addChild(care);
    parallel.addChild(new AlwaysFail<Dog>(new RestTask()));

    Sequence<Dog> sequence = new Sequence<Dog>();
    selector.addChild(sequence);

    BarkTask bark1 = new BarkTask();
    bark1.times = new TriangularIntegerDistribution(1, 5, 2);
    sequence.addChild(bark1);
    sequence.addChild(new WalkTask());
    sequence.addChild(new BarkTask());
    sequence.addChild(new MarkTask());

    return selector;
}
项目:cocos2d-java    文件:BhTree.java   
@SuppressWarnings("unchecked")
Task<T> createTask(String type, String name, String args) {
    switch(type) {
    case "leaf":
        BhLeafTask<T> leaf;// = new RcLeafTask<T>();
        //相同的name会缓存
        if(name != null) {
            leaf = tasksMap.get(name);
            if(leaf != null) {
                CCLog.debug(TAG, "find same leaf task : " + name);
                return leaf;
            }
            if("debug".equals(args)) {
                leaf = new DebugTask(name);
            } else {
                leaf = new BhLeafTask<T>();
            }
            tasksMap.put(name, leaf);
            return leaf;
        } else {
            if("debug".equals(args)) {
                leaf = new DebugTask(name);
            } else {
                leaf = new BhLeafTask<T>();
            }
        }
        return leaf;
    case "parallel":
        if(args == null) {
            return new Parallel<T>();
        } else {
            switch(args) {
            case "selector":
                return new Parallel<T>(Policy.Selector);
            case "sequence":
                return new Parallel<T>(Policy.Sequence);
            }
            CCLog.error(TAG, "pattern fail args = " + args + "  need selector or sequence");
            return null;
        }
    case "selector":
        return new Selector<T>();
    case "sequence":
        return new Sequence<T>();
    }
    CCLog.error(TAG, "not found type : " + type);
    return null;
}