GOAP now uses only bit operations to do its thing.

This commit is contained in:
Zed A. Shaw 2025-03-10 12:13:08 -04:00
parent 01525388ec
commit 3d8a2d4342
4 changed files with 54 additions and 41 deletions

View file

@ -7,19 +7,41 @@
namespace ailol {
constexpr const int SCORE_MAX = std::numeric_limits<int>::max();
constexpr const size_t STATE_MAX = 16;
constexpr const size_t STATE_MAX = 93;
using GOAPState = std::bitset<STATE_MAX>;
const GOAPState ALL_ZERO;
const GOAPState ALL_ONES = ~ALL_ZERO;
struct Action {
std::string name;
int cost = 0;
std::unordered_map<int, bool> preconds;
std::unordered_map<int, bool> effects;
GOAPState positive_preconds;
GOAPState negative_preconds;
GOAPState positive_effects;
GOAPState negative_effects;
Action(std::string name, int cost) :
name(name), cost(cost) {}
name(name), cost(cost) { }
void set_precond(int name, bool val) {
if(val) {
positive_preconds[name] = true;
} else {
negative_preconds[name] = true;
}
}
void set_effect(int name, bool val) {
if(val) {
positive_effects[name] = true;
} else {
negative_effects[name] = true;
}
}
bool can_effect(GOAPState& state);
GOAPState apply_effect(GOAPState& state);