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();
|
||||
}
|
||||
|
|
|
@ -1,43 +1,7 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <iostream>
|
||||
#include "ai.hpp"
|
||||
#include "ai_debug.hpp"
|
||||
#include "rituals.hpp"
|
||||
|
||||
struct RitualAI {
|
||||
std::string script;
|
||||
ai::State start;
|
||||
ai::State original;
|
||||
ai::State goal;
|
||||
ai::ActionPlan plan;
|
||||
|
||||
RitualAI(std::string script, ai::State start, ai::State goal) :
|
||||
script(script), start(start), original(start), goal(goal)
|
||||
{
|
||||
}
|
||||
|
||||
RitualAI() {};
|
||||
|
||||
void reset() {
|
||||
start = original;
|
||||
}
|
||||
|
||||
bool will_do(std::string name) {
|
||||
ai::check_valid_action(name, "RitualAI::is_able_to");
|
||||
return plan.script[0].name == name;
|
||||
}
|
||||
|
||||
void set_state(std::string name, bool setting) {
|
||||
ai::set(start, name, setting);
|
||||
}
|
||||
|
||||
void update() {
|
||||
plan = ai::plan(script, start, goal);
|
||||
}
|
||||
|
||||
void dump() {
|
||||
dump_script(script, start, plan.script);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("prototype combat system ideas", "[combat]") {
|
||||
ai::reset();
|
Loading…
Add table
Add a link
Reference in a new issue