Quick renaming of stuff to be more generic as 'AI'. Now maybe I can get some sweet sweet investor money.
This commit is contained in:
parent
9d6dc2f5dd
commit
a079f882df
7 changed files with 95 additions and 289 deletions
76
goap.hpp
76
goap.hpp
|
@ -1,76 +0,0 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include "matrix.hpp"
|
||||
#include <bitset>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace ailol {
|
||||
constexpr const int SCORE_MAX = std::numeric_limits<int>::max();
|
||||
constexpr const size_t STATE_MAX = 32;
|
||||
|
||||
using GOAPState = std::bitset<STATE_MAX>;
|
||||
|
||||
const GOAPState ALL_ZERO;
|
||||
const GOAPState ALL_ONES = ~ALL_ZERO;
|
||||
|
||||
struct Action {
|
||||
std::string $name;
|
||||
int $cost = 0;
|
||||
|
||||
GOAPState $positive_preconds;
|
||||
GOAPState $negative_preconds;
|
||||
|
||||
GOAPState $positive_effects;
|
||||
GOAPState $negative_effects;
|
||||
|
||||
Action(std::string name, int cost) :
|
||||
$name(name), $cost(cost) { }
|
||||
|
||||
void needs(int name, bool val);
|
||||
void effect(int name, bool val);
|
||||
void load(nlohmann::json &profile, nlohmann::json& config);
|
||||
|
||||
bool can_effect(GOAPState& state);
|
||||
GOAPState apply_effect(GOAPState& state);
|
||||
|
||||
bool operator==(const Action& other) const {
|
||||
return other.$name == $name;
|
||||
}
|
||||
};
|
||||
|
||||
using AStarPath = std::deque<Action>;
|
||||
|
||||
const Action FINAL_ACTION("END", SCORE_MAX);
|
||||
|
||||
struct ActionState {
|
||||
Action action;
|
||||
GOAPState state;
|
||||
|
||||
ActionState(Action action, GOAPState state) :
|
||||
action(action), state(state) {}
|
||||
|
||||
bool operator==(const ActionState& other) const {
|
||||
return other.action == action && other.state == state;
|
||||
}
|
||||
};
|
||||
|
||||
bool is_subset(GOAPState& source, GOAPState& target);
|
||||
|
||||
int distance_to_goal(GOAPState& from, GOAPState& to);
|
||||
|
||||
std::optional<AStarPath> plan_actions(std::vector<Action>& actions, GOAPState& start, GOAPState& goal);
|
||||
}
|
||||
|
||||
template<> struct std::hash<ailol::Action> {
|
||||
size_t operator()(const ailol::Action& p) const {
|
||||
return std::hash<std::string>{}(p.$name);
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct std::hash<ailol::ActionState> {
|
||||
size_t operator()(const ailol::ActionState& p) const {
|
||||
return std::hash<ailol::Action>{}(p.action) ^ std::hash<ailol::GOAPState>{}(p.state);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue