Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class CompositeNode : Node {
- public List<Node> childs;
- public override NodeState Run() {
- // will be implement on derivered classes
- throw new NotImplementedException();
- }
- }
- public class Sequence : Composite {
- public override BH_Status Run() {
- // no child -> then failed (sometime designer forgot to add Leaf nodes)
- if(childs.Count == 0) return NodeState.Failure;
- // evaluate childs
- for(int n = 0, amount = childs.Count; n < amount; n++) {
- var state = childs[n].Run();
- // break when reach any child that return Failure or Running
- if(state != NodeState.Success) return state;
- }
- // all child are Success, then return Success
- return NodeState.Success;
- }
- }
- public class Selector : Composite {
- public override NodeState Run() {
- // no child -> then failed (sometime designer forgot to add Leaf node in tree)
- if(childs.Count == 0) return NodeState.Failure;
- // evaluate childs
- for(int n = 0, amount = childs.Count; n < amount; n++) {
- var state = childs[n].Run();
- // break when reach the first child with status = Sucess or Running (not Failure)
- if(state != NodeState.Failure) return state;
- }
- // no child success or running, then return failed
- return NodeState.Failure;
- }
- }
Add Comment
Please, Sign In to add comment