AI engine is working and I have a little BattleEngine going but the AI is working better than it should in systems.cpp. Need to find out why then make the BattleEngine avoid running entities that have END in action lists.

This commit is contained in:
Zed A. Shaw 2025-03-26 13:34:52 -04:00
parent da273cbee6
commit 47c6bfd531
13 changed files with 131 additions and 27 deletions

View file

@ -131,14 +131,14 @@ TEST_CASE("ai as a module like sound/sprites", "[ai]") {
TEST_CASE("ai autowalker ai test", "[ai]") {
ai::reset();
ai::init("assets/ai.json");
auto start = ai::load_state("Walker::initial_state");
auto goal = ai::load_state("Walker::final_state");
auto start = ai::load_state("Host::initial_state");
auto goal = ai::load_state("Host::final_state");
int enemy_count = 5;
ai::set(start, "no_more_enemies", enemy_count == 0);
// find an enemy and kill them
auto a_plan = ai::plan("Walker::actions", start, goal);
auto a_plan = ai::plan("Host::actions", start, goal);
REQUIRE(!a_plan.complete);
auto result = ai::dump_script("\n\nWALKER KILL STUFF", start, a_plan.script);
@ -154,7 +154,7 @@ TEST_CASE("ai autowalker ai test", "[ai]") {
ai::set(result, "have_item", true);
REQUIRE(!ai::test(result, "health_good"));
auto health_plan = ai::plan("Walker::actions", result, goal);
auto health_plan = ai::plan("Host::actions", result, goal);
result = ai::dump_script("\n\nWALKER NEED HEALTH", result, health_plan.script);
REQUIRE(!health_plan.complete);
REQUIRE(ai::test(result, "health_good"));
@ -163,7 +163,7 @@ TEST_CASE("ai autowalker ai test", "[ai]") {
ai::set(result, "no_more_enemies", true);
REQUIRE(ai::test(result, "no_more_enemies"));
auto new_plan = ai::plan("Walker::actions", result, goal);
auto new_plan = ai::plan("Host::actions", result, goal);
result = ai::dump_script("\n\nWALKER COMPLETE", result, new_plan.script);
REQUIRE(new_plan.complete);

View file

@ -1,9 +1,39 @@
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include "rituals.hpp"
#include "fsm.hpp"
#include "dinkyecs.hpp"
using namespace combat;
TEST_CASE("turn based combat engine sorted", "[combat]") {
dbc::log("does nothing.");
TEST_CASE("cause scared rat won't run away bug", "[combat]") {
ai::reset();
ai::init("assets/ai.json");
auto ai_start = ai::load_state("Enemy::initial_state");
auto ai_goal = ai::load_state("Enemy::final_state");
BattleEngine battle;
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();
REQUIRE(active);
// 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();
REQUIRE(rat.wants_to("run_away"));
battle.fight([&](const auto entity, auto& ai) {
fmt::println("\n\n======= FIGHT! {}", entity);
ai.dump();
});
}

View file

@ -1,10 +1,12 @@
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include "rituals.hpp"
#include "fsm.hpp"
#include "dinkyecs.hpp"
using namespace combat;
TEST_CASE("prototype combat system ideas", "[combat]") {
TEST_CASE("RitualEngine basic tests", "[rituals]") {
RitualEngine re("assets/rituals.json");
auto ritual = re.start();
@ -47,7 +49,7 @@ TEST_CASE("prototype combat system ideas", "[combat]") {
ritual.dump();
}
TEST_CASE("confirm that cycles are avoided/detected", "[combat]") {
TEST_CASE("confirm that cycles are avoided/detected", "[rituals]") {
RitualEngine re("assets/rituals.json");
auto ritual = re.start();