Rituals are more or less sorted out in theory, and they helped find a cycle in the GOAP algorithm that I'm detecting/preventing.
This commit is contained in:
parent
8368d2e751
commit
49531ba148
9 changed files with 94 additions and 48 deletions
23
tests/ai.cpp
23
tests/ai.cpp
|
@ -3,6 +3,7 @@
|
|||
#include "ai.hpp"
|
||||
#include <iostream>
|
||||
#include "ai_debug.hpp"
|
||||
#include "rituals.hpp"
|
||||
|
||||
using namespace dbc;
|
||||
using namespace nlohmann;
|
||||
|
@ -207,5 +208,25 @@ TEST_CASE("Confirm EntityAI behaves as expected", "[ai]") {
|
|||
enemy.set_state("health_good", false);
|
||||
enemy.update();
|
||||
REQUIRE(enemy.wants_to("run_away"));
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("confirm that cycles are avoided/detected", "[ai]") {
|
||||
ai::reset();
|
||||
ai::init("tests/cyclic_rituals.json");
|
||||
|
||||
auto start = ai::load_state("initial");
|
||||
auto goal = ai::load_state("final");
|
||||
|
||||
RitualAI ritual("actions", start, goal);
|
||||
ritual.reset();
|
||||
ritual.set_state("has_magick", true);
|
||||
ritual.set_state("cursed_item", true);
|
||||
ritual.set_state("shiny_bauble", true);
|
||||
|
||||
bool it_throws = false;
|
||||
try { ritual.update(); } catch(...) { it_throws = true; }
|
||||
REQUIRE(it_throws);
|
||||
|
||||
fmt::println("\n\n------------ CYCLES AVOIDED");
|
||||
ritual.dump();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue