From 4c51a6053aa76288cdec07e3f1add2ef56b8b014 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 27 Mar 2024 23:12:05 +0100 Subject: [PATCH] chore(docs): commenting pass on Planner::make_plan --- src/planner.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/planner.cpp b/src/planner.cpp index 0940b95..5520c65 100644 --- a/src/planner.cpp +++ b/src/planner.cpp @@ -87,24 +87,29 @@ Array Planner::gdscript_make_plan(Ref goal) { } Vector> Planner::make_plan(Ref goal) { - UtilityFunctions::print("run"); + // ordered list of all nodes still being considered Vector open{PlannerNode::goal_node(goal->goal_state)}; PlannerNode first = open.get(0); - FromMap from{}; - ScoreMap dist_traveled{}; - ScoreMap best_guess{}; + FromMap from{}; // mapping states to the previous in the path + ScoreMap dist_traveled{}; // mapping states to the shortest found distance from start dist_traveled.insert(first, 0); + ScoreMap best_guess{}; // mapping states to the best guess of the distance to the goal best_guess.insert(first, first.open_requirements.size()); - PlannerNode current{}; + PlannerNode current{}; // state we're checking for neighbours or completion while(!open.is_empty()) { + // current is the top of the ordered list current = open.get(0); + // check if we've reached the goal if(current.open_requirements.is_empty()) return trace_path(from, current); + // current is no longer considered as it cannot be the end open.erase(current); + // find all neighbours of this state Vector neighbours = this->find_neighbours_of(current); for(PlannerNode const& node : neighbours) { - float const new_dist = dist_traveled.get(current) + 1.f; + float const new_dist = dist_traveled.get(current) + 1.f; // unweighed distance traveled to neighbour if(!dist_traveled.has(node) || new_dist < dist_traveled.get(node)) { + // store distances dist_traveled[node] = new_dist; best_guess[node] = new_dist + node.open_requirements.size(); from[node] = current;