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
1
Makefile
1
Makefile
|
@ -23,6 +23,7 @@ tracy_build:
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
./builddir/runtests "[ai]"
|
./builddir/runtests "[ai]"
|
||||||
|
./builddir/runtests "[combat]"
|
||||||
|
|
||||||
run: build test
|
run: build test
|
||||||
powershell "cp ./builddir/zedcaster.exe ."
|
powershell "cp ./builddir/zedcaster.exe ."
|
||||||
|
|
4
goap.cpp
4
goap.cpp
|
@ -90,6 +90,7 @@ namespace ai {
|
||||||
|
|
||||||
ActionPlan plan_actions(std::vector<Action>& actions, State start, State goal) {
|
ActionPlan plan_actions(std::vector<Action>& actions, State start, State goal) {
|
||||||
std::unordered_map<ActionState, int> open_set;
|
std::unordered_map<ActionState, int> open_set;
|
||||||
|
std::unordered_map<State, bool> closed_set;
|
||||||
std::unordered_map<Action, Action> came_from;
|
std::unordered_map<Action, Action> came_from;
|
||||||
std::unordered_map<State, int> g_score;
|
std::unordered_map<State, int> g_score;
|
||||||
ActionState current{FINAL_ACTION, start};
|
ActionState current{FINAL_ACTION, start};
|
||||||
|
@ -106,6 +107,7 @@ namespace ai {
|
||||||
}
|
}
|
||||||
|
|
||||||
open_set.erase(current);
|
open_set.erase(current);
|
||||||
|
closed_set.insert_or_assign(current.state, true);
|
||||||
|
|
||||||
for(auto& neighbor_action : actions) {
|
for(auto& neighbor_action : actions) {
|
||||||
// calculate the State being current/neighbor
|
// calculate the State being current/neighbor
|
||||||
|
@ -114,6 +116,8 @@ namespace ai {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto neighbor = neighbor_action.apply_effect(current.state);
|
auto neighbor = neighbor_action.apply_effect(current.state);
|
||||||
|
if(closed_set.contains(neighbor)) continue;
|
||||||
|
|
||||||
int d_score = d(current.state, neighbor, current.action);
|
int d_score = d(current.state, neighbor, current.action);
|
||||||
int tentative_g_score = g_score[current.state] + d_score;
|
int tentative_g_score = g_score[current.state] + d_score;
|
||||||
int neighbor_g_score = g_score.contains(neighbor) ? g_score[neighbor] : SCORE_MAX;
|
int neighbor_g_score = g_score.contains(neighbor) ? g_score[neighbor] : SCORE_MAX;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue