Now have the ability to do partial solutions that will create potential paths to the goal, and a test that runs the scripts from plans in different scenarios. Also, this ai_debug thing needs some work.
This commit is contained in:
parent
3f83d3f0bb
commit
fc66d221d4
11 changed files with 252 additions and 107 deletions
15
goap.cpp
15
goap.cpp
|
@ -1,5 +1,6 @@
|
|||
#include "dbc.hpp"
|
||||
#include "goap.hpp"
|
||||
#include "ai_debug.hpp"
|
||||
|
||||
namespace ai {
|
||||
using namespace nlohmann;
|
||||
|
@ -82,21 +83,21 @@ namespace ai {
|
|||
return *result;
|
||||
}
|
||||
|
||||
std::optional<Script> 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<Action, Action> came_from;
|
||||
std::unordered_map<State, int> g_score;
|
||||
|
||||
ActionState start_state{FINAL_ACTION, start};
|
||||
ActionState current{FINAL_ACTION, start};
|
||||
|
||||
g_score[start] = 0;
|
||||
open_set[start_state] = g_score[start] + h(start, goal);
|
||||
open_set[current] = g_score[start] + h(start, goal);
|
||||
|
||||
while(!open_set.empty()) {
|
||||
auto current = find_lowest(open_set);
|
||||
current = find_lowest(open_set);
|
||||
|
||||
if(is_subset(current.state, goal)) {
|
||||
return std::make_optional<Script>(reconstruct_path(came_from, current.action));
|
||||
return {true,
|
||||
reconstruct_path(came_from, current.action)};
|
||||
}
|
||||
|
||||
open_set.erase(current);
|
||||
|
@ -122,6 +123,6 @@ namespace ai {
|
|||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
return {false, reconstruct_path(came_from, current.action)};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue