Example #1
0
    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();
    }
Example #2
0
 public override void OnChildSuccess()
 {
     currentNode = rootNode;
 }
Example #3
0
 public override void OnChildFailure()
 {
     currentNode = rootNode;
 }
Example #4
0
 public override void OnChildException()
 {
     currentNode = rootNode;
 }
Example #5
0
 public void LoadFromJSON(string jsonString)
 {
     Hashtable hash = (Hashtable) JSON.JsonDecode(jsonString);
     children = new PeabrainNode[]{ NodeFromJSONHash(hash, this) };
     rootNode = children[0];
 }
Example #6
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"];
    }