From: Michael Andreen Date: Sat, 7 May 2005 11:03:42 +0000 (+0000) Subject: only execute an action when all preconditions are are true X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=commitdiff_plain;h=09f6dfa65b66103c27dc831271d961de9ab0109e only execute an action when all preconditions are are true --- diff --git a/node.cpp b/node.cpp index ed72a7f..dbb099c 100644 --- a/node.cpp +++ b/node.cpp @@ -1,8 +1,10 @@ #include "node.h" +#include 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::iterator child = _children.begin(); child != _children.end(); ++child){ - (*child)->execute(); + (*child)->execute(_action.effects()); } } diff --git a/node.h b/node.h index 3cd3a9e..0d9cae6 100644 --- 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 _children; + literals _preconditions; }; #endif diff --git a/planner.cpp b/planner.cpp index 4630494..a15028e 100644 --- a/planner.cpp +++ b/planner.cpp @@ -61,5 +61,5 @@ void Planner::addNode(Node* node){ void Planner::execute(){ - _start->execute(); + _start->execute(literals()); }