public int Selector(callReturn finished)//if one child returns success, return success { for (int i = 0; i < children.Count; i++) { if (children[i].getStatus() == 1) { status = 1; finished(1); return(1); } else if (children[i].getStatus() == -2) { status = 0; children[i].run(returnToMe); return(0); } else if (children[i].getStatus() == 0) //if we are still waiting for a child to return { //this shouldnt happen but is a failsafe regardless status = 0; return(0); } } //if all children are -1 status = -1; finished(-1); return(-1); }
public int Sequence(callReturn finished)//all children must return success to return success { for (int i = 0; i < children.Count; i++) { if (children[i].getStatus() == -1)//if unsuccessful, return unsuccessful { status = -1; finished(-1); return(-1); } else if (children[i].getStatus() == 0)//still running { status = 0; return(0); } else if (children[i].getStatus() == -2)//-2 denotes an unstarted node { children[i].run(returnToMe); status = 0; return(0); } }//if we have gotten through all children and they have all completed succesfully return a success status = 1; finished(1); return(1); }
public int Idle(callReturn finished) { float prob = Random.Range(0f, 1f); if (prob > 0.5) { status = 0; child.run(returnToMe); return(0); } else { status = 1; finished(1); return(1); } }
public DecoratorNode(Student etudiant, callReturn parent) : base(etudiant, parent) { }
public int Parallel(callReturn finished) { children[0].run(returnToMe); return(0); }
public CompositeNode(Student etudiant, callReturn parent) : base(etudiant, parent) { children = new List <BehaviourNode>(); }
//every node saves a callReturn finished which is set by its parent in initialize(Student etudiant, callReturn finished), this is sent back to its parent upon completion //every node also sets a callReturn returnToMe which is the analog of finished: a function that it passes to its children to be returned to this upon completion public void setRoot() { finished = rootComplete; }
public BehaviourNode(Student etudiant, callReturn parent) { student = etudiant; finished = parent; status = -2; }
public int runAction(callReturn finished) { int result = action(returnToMe); return(result); }
public LeafNode(Student etudiant, callReturn parent, doSomething act) : base(etudiant, parent) { returnToMe = childCompleted; run = runAction; action = act; }