121 lines
5.1 KiB
C++
121 lines
5.1 KiB
C++
#ifdef TESTS_BUILD
|
|
|
|
#include "../../extern/doctest.hpp"
|
|
#include "../../src/Battling/Flow/TurnOrdering.hpp"
|
|
#include "../../src/Battling/Models/CreateCreature.hpp"
|
|
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
|
|
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
|
|
|
using namespace CreatureLib;
|
|
using namespace CreatureLib::Battling;
|
|
|
|
TEST_CASE("Turn ordering: Attack before pass") {
|
|
auto lib = TestLibrary::Get();
|
|
auto learnedAttack =
|
|
LearnedAttack(lib->GetAttackLibrary()->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
|
|
|
|
auto choice1 = std::make_shared<PassTurnChoice>(creature);
|
|
auto choice2 = std::make_shared<AttackTurnChoice>(creature, &learnedAttack, CreatureIndex(0, 0));
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Turn ordering: High priority goes before no priority") {
|
|
auto lib = TestLibrary::Get();
|
|
const auto& l = lib->GetAttackLibrary();
|
|
auto a1 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
|
|
|
|
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
|
|
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
|
|
delete a1;
|
|
delete a2;
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Turn ordering: Higher priority goes before high priority") {
|
|
auto lib = TestLibrary::Get();
|
|
const auto& l = lib->GetAttackLibrary();
|
|
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
|
|
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
|
|
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
delete a1;
|
|
delete a2;
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Turn ordering: High priority goes before low priority") {
|
|
auto lib = TestLibrary::Get();
|
|
const auto& l = lib->GetAttackLibrary();
|
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
|
|
|
|
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
|
|
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
|
|
delete a1;
|
|
delete a2;
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Turn ordering: No priority goes before low priority") {
|
|
auto lib = TestLibrary::Get();
|
|
const auto& l = lib->GetAttackLibrary();
|
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto a2 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
|
|
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
|
|
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
|
TurnOrdering::OrderChoices(vec);
|
|
CHECK(vec[0] == choice2);
|
|
CHECK(vec[1] == choice1);
|
|
|
|
delete a1;
|
|
delete a2;
|
|
delete creature;
|
|
}
|
|
|
|
#endif |