public void Think() { // Run filters if (currentFilters.Count > 0) { for (int f = 0; f < currentFilters.Count; f++) { if (((PeabrainFilter) currentFilters[f]).Filter()) { //PeabrainNode filterParent = ((PeabrainNode) currentFilters[f]).parent; PeabrainFilter filter = (PeabrainFilter) currentFilters[f]; // Remove this and all later filters from stack currentFilters.RemoveRange(f, currentFilters.Count - f); filter.OnFilter(); // Move action to node just above filter //filterParent.OnChildFailure(); } } } if (currentNode == null) currentNode = rootNode; currentNode.Execute(); }
public override void OnChildSuccess() { currentNode = rootNode; }
public override void OnChildFailure() { currentNode = rootNode; }
public override void OnChildException() { currentNode = rootNode; }
public void LoadFromJSON(string jsonString) { Hashtable hash = (Hashtable) JSON.JsonDecode(jsonString); children = new PeabrainNode[]{ NodeFromJSONHash(hash, this) }; rootNode = children[0]; }
protected virtual void ConfigureFromJSONHash(Hashtable hash, Peabrain brain) { this.brain = brain; ArrayList childrenJson = (ArrayList) hash["children"]; if (childrenJson != null) { PeabrainNode[] nodes = new PeabrainNode[childrenJson.Count]; for (int c = 0; c < childrenJson.Count; c++) { nodes[c] = NodeFromJSONHash((Hashtable) childrenJson[c], brain); } children = nodes; } description = (string) hash["description"]; }