Support for cloning battles for AI purposes.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2021-04-11 15:20:50 +02:00
parent a3b7002cd4
commit 84a14cff2b
19 changed files with 236 additions and 30 deletions

View File

@@ -0,0 +1,50 @@
#ifdef TESTS_BUILD
#include "../../extern/doctest.hpp"
#include "../../src/Battling/History/HistoryElements/AttackUseHistory.hpp"
#include "../../src/Battling/Models/Battle.hpp"
#include "../../src/Battling/Models/BattleSide.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib::Battling;
TEST_CASE("Clone battle, test basic functionality") {
auto lib = TestLibrary::Get();
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto party = CreatureParty(6);
party.SwapInto(0, creature);
auto bp = ArbUt::List<BattleParty*>();
bp.Append(new BattleParty(&party, {CreatureIndex(0, 0)}));
auto battle = Battle(lib, bp);
battle.SwitchCreature(0, 0, creature);
auto clone = battle.Clone();
REQUIRE_NE(battle.GetCreature(0, 0), clone->GetCreature(0, 0));
REQUIRE(battle.GetCreature(0, 0).GetValue()->GetSpecies() == clone->GetCreature(0, 0).GetValue()->GetSpecies());
auto clonedParty = clone->GetParties().At(0)->GetParty().GetRaw();
delete clone;
delete clonedParty;
}
TEST_CASE("Clone battle, test history history holder") {
auto lib = TestLibrary::Get();
auto battle = Battle(lib, {});
auto side = BattleSide(0, &battle, 1);
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c, 0);
auto clone = battle.Clone();
clone->RegisterHistoryElement<AttackUseHistory>(nullptr);
clone->RegisterHistoryElement<AttackUseHistory>(nullptr);
delete c;
delete clone;
}
#endif

View File

@@ -12,10 +12,11 @@ private:
ArbUt::StringView _name;
public:
explicit TestScript(const std::string& name) : _name(name.c_str(), name.length()){};
explicit TestScript(const ArbUt::StringView& name) : _name(name){};
const ArbUt::StringView& GetName() const noexcept override { return _name; }
void TestMethod(int& runCount) { runCount++; }
BattleScript* Clone() override { return new TestScript(_name); }
};
TEST_CASE("Script Aggregator properly iterates containing script.") {

View File

@@ -12,8 +12,10 @@ private:
ArbUt::StringView _name;
public:
explicit TestScript(const std::string& name) : _name(name.c_str(), name.length()){};
explicit TestScript(const ArbUt::StringView& name) : _name(name){};
const ArbUt::StringView& GetName() const noexcept override { return _name; }
BattleScript* Clone() override { return new TestScript(_name); }
};
TEST_CASE("Empty script set count == 0") {

View File

@@ -11,10 +11,11 @@ private:
ArbUt::StringView _name;
public:
explicit TestScript(const std::string& name) : _name(name.c_str(), name.length()){};
explicit TestScript(const ArbUt::StringView& name) : _name(name){};
const ArbUt::StringView& GetName() const noexcept override { return _name; }
void TestMethod(int& runCount) { runCount++; }
BattleScript* Clone() override { return new TestScript(_name); }
};
class ScriptSourceWithScriptPtr : public ScriptSource {