Added a check to see if a found state is already in a closed_set so I can skip it.
This commit is contained in:
parent
63f032ff12
commit
7984540c0c
2 changed files with 5 additions and 0 deletions
4
goap.cpp
4
goap.cpp
|
@ -90,6 +90,7 @@ namespace ai {
|
|||
|
||||
ActionPlan plan_actions(std::vector<Action>& actions, State start, State goal) {
|
||||
std::unordered_map<ActionState, int> open_set;
|
||||
std::unordered_map<State, bool> closed_set;
|
||||
std::unordered_map<Action, Action> came_from;
|
||||
std::unordered_map<State, int> g_score;
|
||||
ActionState current{FINAL_ACTION, start};
|
||||
|
@ -106,6 +107,7 @@ namespace ai {
|
|||
}
|
||||
|
||||
open_set.erase(current);
|
||||
closed_set.insert_or_assign(current.state, true);
|
||||
|
||||
for(auto& neighbor_action : actions) {
|
||||
// calculate the State being current/neighbor
|
||||
|
@ -114,6 +116,8 @@ namespace ai {
|
|||
}
|
||||
|
||||
auto neighbor = neighbor_action.apply_effect(current.state);
|
||||
if(closed_set.contains(neighbor)) continue;
|
||||
|
||||
int d_score = d(current.state, neighbor, current.action);
|
||||
int tentative_g_score = g_score[current.state] + d_score;
|
||||
int neighbor_g_score = g_score.contains(neighbor) ? g_score[neighbor] : SCORE_MAX;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue