X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=node.cpp;h=1fb2b2e3ee9448eeb50a7f0657e23f1082f72895;hb=7b9821d42d980e5788bbc65563973eddd6e4c40d;hp=a9cb4539431d6d1f959339f9e042d867ba68fb74;hpb=066d3c3659f52a73a0344c3e08989cc73a15164b;p=popboot.git diff --git a/node.cpp b/node.cpp index a9cb453..1fb2b2e 100644 --- a/node.cpp +++ b/node.cpp @@ -1,6 +1,31 @@ #include "node.h" +#include +using namespace std; -Node::Node(Action action, std::vector children){ +Node::Node(Action action){ _action = action; - _children = children; + _preconditions = _action.preconditions(); +} + +const Action& Node::action() const{ + return _action; +} + + +void Node::addChild(Node* node){ + _children.push_back(node); +} + + +void Node::execute(const literals& effects){ + for (literals::const_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::iterator child = _children.begin(); child != _children.end(); ++child){ + (*child)->execute(_action.effects()); + } }