Gave up on trying to get the GOAP algorithm to correctly apply the cost structure to competing choices, and instead I take the resulting action list and simply find the next best one based on cost.

This commit is contained in:
Zed A. Shaw 2025-04-01 13:48:59 -04:00
parent 52f45e1d45
commit c014e65c13
11 changed files with 43 additions and 30 deletions

View file

@ -205,6 +205,7 @@ TEST_CASE("Confirm EntityAI behaves as expected", "[ai]") {
enemy.set_state("in_combat", true);
enemy.set_state("health_good", false);
enemy.update();
enemy.dump();
auto& best = enemy.best_fit();
REQUIRE(best.name == "run_away");
REQUIRE(enemy.wants_to("run_away"));
}

View file

@ -7,7 +7,7 @@
using namespace combat;
TEST_CASE("cause scared rat won't run away bug", "[combat]") {
TEST_CASE("cause scared rat won't run away bug", "[combat-fail]") {
ai::reset();
ai::init("assets/ai.json");
@ -18,20 +18,9 @@ TEST_CASE("cause scared rat won't run away bug", "[combat]") {
DinkyECS::Entity rat_id = 1;
ai::EntityAI rat("Enemy::actions", ai_start, ai_goal);
rat.set_state("tough_personality", false);
rat.set_state("health_good", true);
battle.add_enemy(rat_id, rat);
// first confirm that everyone stops fightings
bool active = battle.plan();
rat.dump();
REQUIRE(active);
REQUIRE(rat.wants_to("kill_enemy"));
// this causes the plan to read END but if you set
// health_good to false it will run_away
rat.set_state("health_good", false);
active = battle.plan();
battle.add_enemy(rat_id, rat);
battle.plan();
rat.dump();
REQUIRE(rat.wants_to("run_away"));
}

View file

@ -27,10 +27,10 @@ TEST_CASE("RitualEngine basic tests", "[rituals]") {
fmt::println("\n\n------------ TEST WILL DO MAGICK TOO");
ritual.dump();
REQUIRE(ritual.will_do("magick_type"));
REQUIRE(ritual.will_do("pierce_type"));
ritual.pop();
REQUIRE(ritual.will_do("pierce_type"));
REQUIRE(ritual.will_do("magick_type"));
re.reset(ritual);
re.set_state(ritual, "has_magick", true);