]> ruin.nu Git - popboot.git/commitdiff
only execute an action when all preconditions are are true
authorMichael Andreen <harv@ruin.nu>
Sat, 7 May 2005 11:03:42 +0000 (11:03 +0000)
committerMichael Andreen <harv@ruin.nu>
Sat, 7 May 2005 11:03:42 +0000 (11:03 +0000)
node.cpp
node.h
planner.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());
        }
 }
diff --git a/node.h b/node.h
index 3cd3a9eadd050f0de9fa5ab6cc9563386f6eaf01..0d9cae6fa0229ce432dfb21497452adfa2075e16 100644 (file)
--- a/node.h
+++ b/node.h
@@ -10,11 +10,12 @@ class Node {
                Node(Action action);
                void addChild(Node* node);
                Action action();
-               void execute();
+               void execute(literals effects);
 
        protected:
                Action _action;
                std::vector<Node*> _children;
+               literals _preconditions;
 };
 
 #endif
index 463049473fe16ce62ac9207bce287f270867da0b..a15028e29a3175e8fa316e2e6e6a37e2dc41194f 100644 (file)
@@ -61,5 +61,5 @@ void Planner::addNode(Node* node){
 
 
 void Planner::execute(){
-       _start->execute();
+       _start->execute(literals());
 }