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; }
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; }
@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; }
public void initTest() { Sequence<Blackboard> seq = new Sequence<>(); seq.addChild((new RandomTest()).setDebug("1")); seq.addChild((new RandomTest()).setDebug("2")); seq.addChild((new RandomTest()).setDebug("3")); bt = new BehaviorTree<Blackboard>(seq); bt.setObject(agent.getBlackboard()); }