Gave up on trying to get the GOAP algorithm to correctly apply the cost structure to competing choices, and instead I take the resulting action list and simply find the next best one based on cost.
This commit is contained in:
parent
52f45e1d45
commit
c014e65c13
11 changed files with 43 additions and 30 deletions
11
goap.cpp
11
goap.cpp
|
@ -40,8 +40,9 @@ namespace ai {
|
|||
}
|
||||
|
||||
bool Action::can_effect(State& state) {
|
||||
return ((state & $positive_preconds) == $positive_preconds) &&
|
||||
((state & $negative_preconds) == ALL_ZERO);
|
||||
bool posbit_match = (state & $positive_preconds) == $positive_preconds;
|
||||
bool negbit_match = (state & $negative_preconds) == ALL_ZERO;
|
||||
return posbit_match && negbit_match;
|
||||
}
|
||||
|
||||
State Action::apply_effect(State& state) {
|
||||
|
@ -113,11 +114,11 @@ namespace ai {
|
|||
|
||||
ActionState find_lowest(std::unordered_map<ActionState, int>& open_set) {
|
||||
check(!open_set.empty(), "open set can't be empty in find_lowest");
|
||||
int found_score = SCORE_MAX;
|
||||
int found_score = std::numeric_limits<int>::max();
|
||||
ActionState found_as;
|
||||
|
||||
for(auto& kv : open_set) {
|
||||
if(kv.second < found_score) {
|
||||
if(kv.second <= found_score) {
|
||||
found_score = kv.second;
|
||||
found_as = kv.first;
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ namespace ai {
|
|||
g_score.insert_or_assign(neighbor, tentative_g_score);
|
||||
ActionState neighbor_as{neighbor_action, neighbor};
|
||||
|
||||
int score = tentative_g_score + h(neighbor, goal) + neighbor_action.cost;
|
||||
int score = tentative_g_score + h(neighbor, goal);
|
||||
|
||||
// this maybe doesn't need score
|
||||
open_set.insert_or_assign(neighbor_as, score);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue