X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=blobdiff_plain;f=node.cpp;h=b4d22fb9569c28cea70176abce6ce585c2b8b8c1;hp=9bedf3834d34c4786dddbd46354f4879af759f07;hb=d385ba13a2ded8ce22b83c82d8a50c89a5d1d63e;hpb=716fc4e282ce52fe953867171c046acd3b614d3b diff --git a/node.cpp b/node.cpp index 9bedf38..b4d22fb 100644 --- a/node.cpp +++ b/node.cpp @@ -1,10 +1,11 @@ #include "node.h" #include +#include using namespace std; -Node::Node(const Action& action){ +Node::Node(const Action* action){ _action = action; - _preconditions = _action.preconditions(); + _preconditions = _action->preconditions(); _executed = false; } Node::Node(){ @@ -17,7 +18,7 @@ Node::Node(const Node& node){ _executed = node._executed; } -const Action& Node::action() const{ +const Action* Node::action() const{ return _action; } @@ -33,41 +34,44 @@ bool Node::executed() const{ const Literals& Node::effects() const{ return _effects; } +void Node::satisfyCondition(std::string effect){ + _preconditions.erase(_preconditions.find(effect)); +} -void Node::execute(bool strict, const Literals& effects){ +void Node::execute(const Literals& effects){ + cerr << "Executing: " << _action->name() << endl; for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){ + cerr << "Satisfied effect: " << *effect << endl; _preconditions.erase(_preconditions.find(*effect)); } - if ((_preconditions.size() != 0 && strict) || _executed) + cerr << "Number of preconditions left: " << _preconditions.size() << endl; + if(_executed) + cerr << "Already executed" << endl; + if ((_preconditions.size() != 0) || _executed) return; - if (_preconditions.size() != 0){ - for (Preconditions::iterator precond = _preconditions.begin(); precond != _preconditions.end(); ++precond){ - if (precond->second) - return; - } - } - _executed = true; - int value = _action.execute(); - _effects = _action.effects(value); + int value = _action->execute(); + _effects = _action->effects(value); + + cerr << "Got returnvalue: " << value << ", number of effects: " << _effects.size() << endl; for(vector::iterator child = _children.begin(); child != _children.end(); ++child){ - (*child)->execute(strict,effects); + (*child)->execute(_effects); } } StartNode::StartNode(const Literals& init){ EffectsMap initial; initial[0] = init; - _action = Action("start",Preconditions(),"", initial); + _action = new Action("start",Preconditions(),"", initial); } EndNode::EndNode(const Literals& goal){ Preconditions goalState; for(Literals::const_iterator g = goal.begin(); g != goal.end(); ++g) goalState[*g] = true; - _action = Action("finish",goalState,"",EffectsMap()); - _preconditions = _action.preconditions(); + _action = new Action("finish",goalState,"",EffectsMap()); + _preconditions = _action->preconditions(); }