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

@ -8,22 +8,12 @@ namespace ailol {
}
bool Action::can_effect(GOAPState& state) {
for(auto [name, setting] : preconds) {
if(state[name] != setting) return false;
}
return true;
return ((state & positive_preconds) == positive_preconds) &&
((state & negative_preconds) == ALL_ZERO);
}
GOAPState Action::apply_effect(GOAPState& state) {
// RCR SUGGEST: state = (state & ~write_mask) | effect
auto state_cp = state;
for(auto [name, setting] : effects) {
state_cp[name] = setting;
}
return state_cp;
return (state | positive_effects) & ~negative_effects;
}
int distance_to_goal(GOAPState& from, GOAPState& to) {