Skip to content

Commit

Permalink
✅ assert that GOAP plan is in the correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdd committed May 8, 2024
1 parent 3205722 commit ae17d01
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/goap.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <string>

#include "doctest.h"

#include "../include/aitoolkit/goap.hpp"
Expand All @@ -9,6 +11,7 @@ struct blackboard_type {
int food;
int gold;
int stone;
std::string plan_order;
};

bool operator==(const blackboard_type& a, const blackboard_type& b) {
Expand Down Expand Up @@ -48,6 +51,7 @@ class chop_wood final : public action<blackboard_type> {

virtual void apply_effects(blackboard_type& blackboard, bool dry_run) const override {
blackboard.wood += 1;
blackboard.plan_order += "W";
}
};

Expand All @@ -67,6 +71,7 @@ class build_storage final : public action<blackboard_type> {
virtual void apply_effects(blackboard_type& blackboard, bool dry_run) const override {
blackboard.have_storage = true;
blackboard.wood -= 10;
blackboard.plan_order += "B";
}
};

Expand All @@ -82,6 +87,7 @@ class gather_food final : public action<blackboard_type> {

virtual void apply_effects(blackboard_type& blackboard, bool dry_run) const override {
blackboard.food += 1;
blackboard.plan_order += "F";
}
};

Expand All @@ -97,6 +103,7 @@ class mine_gold final : public action<blackboard_type> {

virtual void apply_effects(blackboard_type& blackboard, bool dry_run) const override {
blackboard.gold += 1;
blackboard.plan_order += "G";
}
};

Expand All @@ -112,6 +119,7 @@ class mine_stone final : public action<blackboard_type> {

virtual void apply_effects(blackboard_type& blackboard, bool dry_run) const override {
blackboard.stone += 1;
blackboard.plan_order += "S";
}
};

Expand Down Expand Up @@ -152,6 +160,7 @@ TEST_CASE("goap planning") {
p.run_next(initial);
}
CHECK(initial == goal);
CHECK(initial.plan_order.starts_with("WWWWWWWWWWB"));
}

SUBCASE("planner fails to find a plan") {
Expand Down

0 comments on commit ae17d01

Please sign in to comment.