chore(docs): commenting pass on Planner::make_plan
This commit is contained in:
parent
971c2dd2ff
commit
4c51a6053a
|
@ -87,24 +87,29 @@ Array Planner::gdscript_make_plan(Ref<Goal> goal) {
|
|||
}
|
||||
|
||||
Vector<Ref<Action>> Planner::make_plan(Ref<Goal> goal) {
|
||||
UtilityFunctions::print("run");
|
||||
// ordered list of all nodes still being considered
|
||||
Vector<PlannerNode> 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<PlannerNode> 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;
|
||||
|
|
Loading…
Reference in a new issue