]> ruin.nu Git - popboot.git/blobdiff - node.cpp
only execute an action when all preconditions are are true
[popboot.git] / node.cpp
index ed72a7f60c5a5e289c33fe36592a715d4ec29cc1..dbb099cf47bc5c30fe14b03fe83aad6cd5d53ca9 100644 (file)
--- a/node.cpp
+++ b/node.cpp
@@ -1,8 +1,10 @@
 #include "node.h"
+#include <algorithm>
 using namespace std;
 
 Node::Node(Action action){
        _action = action;
+       _preconditions = _action.preconditions();
 }
 
 Action Node::action(){
@@ -15,10 +17,15 @@ void Node::addChild(Node* node){
 }
 
 
-void Node::execute(){
+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();
+               (*child)->execute(_action.effects());
        }
 }