Autowalker is now using the GOAP AI system and works way better. Still quite a lot of jank in the code but that'll get removed over time. Next thing is being able to detect when its near an item/enemy and properly react.
This commit is contained in:
parent
ff81c78d13
commit
d15c9b12fd
9 changed files with 84 additions and 47 deletions
14
goap.hpp
14
goap.hpp
|
@ -12,6 +12,7 @@ namespace ai {
|
|||
using AIProfile = std::unordered_map<std::string, int>;
|
||||
|
||||
constexpr const int SCORE_MAX = std::numeric_limits<int>::max();
|
||||
|
||||
constexpr const size_t STATE_MAX = 32;
|
||||
|
||||
using State = std::bitset<STATE_MAX>;
|
||||
|
@ -20,8 +21,8 @@ namespace ai {
|
|||
const State ALL_ONES = ~ALL_ZERO;
|
||||
|
||||
struct Action {
|
||||
std::string $name;
|
||||
int $cost = 0;
|
||||
std::string name;
|
||||
int cost = 0;
|
||||
|
||||
State $positive_preconds;
|
||||
State $negative_preconds;
|
||||
|
@ -30,16 +31,17 @@ namespace ai {
|
|||
State $negative_effects;
|
||||
|
||||
Action(std::string name, int cost) :
|
||||
$name(name), $cost(cost) { }
|
||||
name(name), cost(cost) { }
|
||||
|
||||
void needs(int name, bool val);
|
||||
void effect(int name, bool val);
|
||||
void ignore(int name);
|
||||
|
||||
bool can_effect(State& state);
|
||||
State apply_effect(State& state);
|
||||
|
||||
bool operator==(const Action& other) const {
|
||||
return other.$name == $name;
|
||||
return other.name == name;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -66,14 +68,14 @@ namespace ai {
|
|||
|
||||
bool is_subset(State& source, State& target);
|
||||
|
||||
int distance_to_goal(State& from, State& to);
|
||||
int distance_to_goal(State from, State to, Action& action);
|
||||
|
||||
ActionPlan plan_actions(std::vector<Action>& actions, State start, State goal);
|
||||
}
|
||||
|
||||
template<> struct std::hash<ai::Action> {
|
||||
size_t operator()(const ai::Action& p) const {
|
||||
return std::hash<std::string>{}(p.$name);
|
||||
return std::hash<std::string>{}(p.name);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue