]> ruin.nu Git - popboot.git/blobdiff - node.cpp
only execute an action when all preconditions are are true
[popboot.git] / node.cpp
index 11fed08507b52bfe5953a1558aed3c3e2be6818a..dbb099cf47bc5c30fe14b03fe83aad6cd5d53ca9 100644 (file)
--- a/node.cpp
+++ b/node.cpp
@@ -1,5 +1,31 @@
 #include "node.h"
+#include <algorithm>
+using namespace std;
 
 Node::Node(Action action){
        _action = action;
+       _preconditions = _action.preconditions();
+}
+
+Action Node::action(){
+       return _action;
+}
+
+
+void Node::addChild(Node* node){
+       _children.push_back(node);
+}
+
+
+void Node::execute(literals effects){
+       for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
+               _preconditions.erase(find(_preconditions.begin(),_preconditions.end(), *effect));
+       }
+       if (_preconditions.size() != 0)
+               return;
+       _action.execute();
+       
+       for(vector<Node*>::iterator child = _children.begin(); child != _children.end(); ++child){
+               (*child)->execute(_action.effects());
+       }
 }