feat: put PlannerNode member fns in planner.cpp

This commit is contained in:
Sara 2024-03-27 23:11:47 +01:00
parent fdfde706e0
commit 971c2dd2ff
2 changed files with 21 additions and 17 deletions

View file

@ -31,6 +31,25 @@ Dictionary Goal::get_goal_state() const {
#undef CLASSNAME // !Goal #undef CLASSNAME // !Goal
PlannerNode PlannerNode::goal_node(WorldState const &goal) {
return PlannerNode{
goal, {}, {}
};
}
PlannerNode PlannerNode::new_node_along(Ref<Action> action) const {
PlannerNode new_node{
action->prerequisites,
action->effects,
action,
};
for(WorldProperty const &prop : this->state)
new_node.state.insert(prop.key, prop.value);
for(WorldProperty const &prop : this->open_requirements)
new_node.open_requirements.insert(prop.key, prop.value);
return new_node;
}
void Planner::_bind_methods() { void Planner::_bind_methods() {
#define CLASSNAME Planner #define CLASSNAME Planner
GDPROPERTY_HINTED(actions, Variant::ARRAY, PROPERTY_HINT_ARRAY_TYPE, GDRESOURCETYPE(Action)); GDPROPERTY_HINTED(actions, Variant::ARRAY, PROPERTY_HINT_ARRAY_TYPE, GDRESOURCETYPE(Action));

View file

@ -49,24 +49,9 @@ struct PlannerNode {
PlannerNode() = default; PlannerNode() = default;
PlannerNode(PlannerNode const &src) = default; PlannerNode(PlannerNode const &src) = default;
static PlannerNode goal_node(WorldState goal) { static PlannerNode goal_node(WorldState const &goal);
return PlannerNode{
goal, {}, {}
};
}
PlannerNode new_node_along(Ref<Action> action) const { PlannerNode new_node_along(Ref<Action> action) const;
PlannerNode new_node{
action->prerequisites,
action->effects,
action,
};
for(WorldProperty const &prop : this->state)
new_node.state.insert(prop.key, prop.value);
for(WorldProperty const &prop : this->open_requirements)
new_node.open_requirements.insert(prop.key, prop.value);
return new_node;
}
}; };
class Planner : public Node { class Planner : public Node {