]> ruin.nu Git - popboot.git/blob - node.cpp
only execute an action when all preconditions are are true
[popboot.git] / node.cpp
1 #include "node.h"
2 #include <algorithm>
3 using namespace std;
4
5 Node::Node(Action action){
6         _action = action;
7         _preconditions = _action.preconditions();
8 }
9
10 Action Node::action(){
11         return _action;
12 }
13
14
15 void Node::addChild(Node* node){
16         _children.push_back(node);
17 }
18
19
20 void Node::execute(literals effects){
21         for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
22                 _preconditions.erase(find(_preconditions.begin(),_preconditions.end(), *effect));
23         }
24         if (_preconditions.size() != 0)
25                 return;
26         _action.execute();
27         
28         for(vector<Node*>::iterator child = _children.begin(); child != _children.end(); ++child){
29                 (*child)->execute(_action.effects());
30         }
31 }