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

项目: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;
}