2019-10-31 11:02:23 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
|
2022-02-05 12:59:15 +00:00
|
|
|
#include <doctest.h>
|
2019-10-31 11:02:23 +00:00
|
|
|
#include "../../src/Battling/Flow/TurnOrdering.hpp"
|
2020-12-12 11:22:48 +00:00
|
|
|
#include "../../src/Battling/Models/CreateCreature.hpp"
|
2019-11-28 11:55:22 +00:00
|
|
|
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
|
|
|
|
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
|
2019-12-07 12:45:44 +00:00
|
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2019-10-31 11:31:31 +00:00
|
|
|
using namespace CreatureLib;
|
2019-10-31 11:02:23 +00:00
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Turn ordering: Attack before pass") {
|
2020-03-22 12:42:26 +00:00
|
|
|
auto lib = TestLibrary::Get();
|
2022-05-16 15:21:39 +00:00
|
|
|
auto learnedAttack = LearnedAttack(lib->GetAttackLibrary()->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
2020-12-12 11:22:48 +00:00
|
|
|
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));
|
2020-06-02 11:06:24 +00:00
|
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 11:02:23 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2020-06-02 11:06:24 +00:00
|
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 11:02:23 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2020-12-12 11:22:48 +00:00
|
|
|
delete creature;
|
2019-10-31 11:02:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Turn ordering: High priority goes before no priority") {
|
2020-12-12 11:22:48 +00:00
|
|
|
auto lib = TestLibrary::Get();
|
|
|
|
const auto& l = lib->GetAttackLibrary();
|
2022-05-16 15:21:39 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetByHash("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetByHash("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
2020-12-12 11:22:48 +00:00
|
|
|
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));
|
2020-06-02 11:06:24 +00:00
|
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2020-06-02 11:06:24 +00:00
|
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2020-12-12 11:22:48 +00:00
|
|
|
delete creature;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Turn ordering: Higher priority goes before high priority") {
|
2020-12-12 11:22:48 +00:00
|
|
|
auto lib = TestLibrary::Get();
|
|
|
|
const auto& l = lib->GetAttackLibrary();
|
2022-05-16 15:21:39 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetByHash("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetByHash("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
2020-12-12 11:22:48 +00:00
|
|
|
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));
|
2020-06-02 11:06:24 +00:00
|
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2020-06-02 11:06:24 +00:00
|
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2020-12-12 11:22:48 +00:00
|
|
|
delete creature;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Turn ordering: High priority goes before low priority") {
|
2020-12-12 11:22:48 +00:00
|
|
|
auto lib = TestLibrary::Get();
|
|
|
|
const auto& l = lib->GetAttackLibrary();
|
2022-05-16 15:21:39 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetByHash("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetByHash("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
2020-12-12 11:22:48 +00:00
|
|
|
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));
|
2020-06-02 11:06:24 +00:00
|
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2020-06-02 11:06:24 +00:00
|
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2020-12-12 11:22:48 +00:00
|
|
|
delete creature;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Turn ordering: No priority goes before low priority") {
|
2020-12-12 11:22:48 +00:00
|
|
|
auto lib = TestLibrary::Get();
|
|
|
|
const auto& l = lib->GetAttackLibrary();
|
2022-05-16 15:21:39 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetByHash("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetByHash("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
2020-12-12 11:22:48 +00:00
|
|
|
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));
|
2020-06-02 11:06:24 +00:00
|
|
|
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2020-06-02 11:06:24 +00:00
|
|
|
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
2020-08-30 11:14:33 +00:00
|
|
|
TurnOrdering::OrderChoices(vec);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2020-12-12 11:22:48 +00:00
|
|
|
delete creature;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 11:02:23 +00:00
|
|
|
#endif
|