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) {
|
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)};
|
Vector<PlannerNode> open{PlannerNode::goal_node(goal->goal_state)};
|
||||||
PlannerNode first = open.get(0);
|
PlannerNode first = open.get(0);
|
||||||
FromMap from{};
|
FromMap from{}; // mapping states to the previous in the path
|
||||||
ScoreMap dist_traveled{};
|
ScoreMap dist_traveled{}; // mapping states to the shortest found distance from start
|
||||||
ScoreMap best_guess{};
|
|
||||||
dist_traveled.insert(first, 0);
|
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());
|
best_guess.insert(first, first.open_requirements.size());
|
||||||
PlannerNode current{};
|
PlannerNode current{}; // state we're checking for neighbours or completion
|
||||||
while(!open.is_empty()) {
|
while(!open.is_empty()) {
|
||||||
|
// current is the top of the ordered list
|
||||||
current = open.get(0);
|
current = open.get(0);
|
||||||
|
// check if we've reached the goal
|
||||||
if(current.open_requirements.is_empty())
|
if(current.open_requirements.is_empty())
|
||||||
return trace_path(from, current);
|
return trace_path(from, current);
|
||||||
|
// current is no longer considered as it cannot be the end
|
||||||
open.erase(current);
|
open.erase(current);
|
||||||
|
// find all neighbours of this state
|
||||||
Vector<PlannerNode> neighbours = this->find_neighbours_of(current);
|
Vector<PlannerNode> neighbours = this->find_neighbours_of(current);
|
||||||
for(PlannerNode const& node : neighbours) {
|
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)) {
|
if(!dist_traveled.has(node) || new_dist < dist_traveled.get(node)) {
|
||||||
|
// store distances
|
||||||
dist_traveled[node] = new_dist;
|
dist_traveled[node] = new_dist;
|
||||||
best_guess[node] = new_dist + node.open_requirements.size();
|
best_guess[node] = new_dist + node.open_requirements.size();
|
||||||
from[node] = current;
|
from[node] = current;
|
||||||
|
|
Loading…
Reference in a new issue