Synthia
Generic and flexible data structure generator
BehaviorTreeExample.java
Go to the documentation of this file.
1 package examples.sequences;
2 
8 
9 /**
10  * Generates a random sequence of strings whose content is defined by
11  * a behavior tree. In this example, the behavior tree corresponds to this
12  * picture:
13  * <p>
14  * <img src="./doc-files/Tree.png" alt="Tree">
15  * @author Sylvain HallĂ©
16  * @ingroup Examples
17  */
18 public class BehaviorTreeExample
19 {
20  @SuppressWarnings("unchecked")
21  public static void main(String[] args)
22  {
23  RandomFloat picker = new RandomFloat();
24  picker.setSeed(10);
25  BehaviorTree<String> tree = new Sequence<String>(
26  new Selector<String>(picker)
27  .add(new Leaf<String>("A"), 0.5)
28  .add(new Sequence<String>(new Leaf<String>("B"), new Leaf<String>("C")), 0.5),
29  new Selector<String>(picker)
30  .add(new Leaf<String>("D"), 0.25)
31  .add(new Sequence<String>(new Leaf<String>("E"), new Leaf<String>("F")), 0.75)
32  );
33  String s = null;
34  do
35  {
36  s = tree.pick();
37  if (s == null)
38  {
39  break;
40  }
41  System.out.println(s);
42  } while (s != null);
43  }
44 }
ca.uqac.lif.synthia.sequence.BehaviorTree
Generates a sequence of objects by following a behavior tree.
Definition: BehaviorTree.java:48
examples.sequences.BehaviorTreeExample.main
static void main(String[] args)
Definition: BehaviorTreeExample.java:21
ca.uqac
ca.uqac.lif.synthia.random
Pickers that produce pseudo-random objects such as numbers.
Definition: AffineTransform.java:19
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.sequence.BehaviorTree.Selector
Selector node in a behavior tree.
Definition: BehaviorTree.java:176
ca.uqac.lif.synthia.sequence.BehaviorTree.Leaf
Leaf node of a behavior tree.
Definition: BehaviorTree.java:335
ca.uqac.lif.synthia.random.RandomFloat.setSeed
RandomFloat setSeed(int seed)
Definition: RandomFloat.java:85
ca.uqac.lif
ca
ca.uqac.lif.synthia.Picker.pick
T pick()
Picks an object.
examples.sequences.BehaviorTreeExample
Generates a random sequence of strings whose content is defined by a behavior tree.
Definition: BehaviorTreeExample.java:18
ca.uqac.lif.synthia.random.RandomFloat
Picks a floating point number uniformly in an interval.
Definition: RandomFloat.java:30
ca.uqac.lif.synthia.sequence.BehaviorTree.Sequence
Sequence node in a behavior tree.
Definition: BehaviorTree.java:57
ca.uqac.lif.synthia.sequence
Pickers related to the generation of a sequence of values.
Definition: BehaviorTree.java:19