2019-10-31 11:02:23 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
|
2019-12-07 12:45:44 +00:00
|
|
|
#include "../../extern/catch.hpp"
|
2019-10-31 11:02:23 +00:00
|
|
|
#include "../../src/Battling/Flow/TurnOrdering.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;
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
|
2020-03-22 12:42:26 +00:00
|
|
|
auto lib = TestLibrary::Get();
|
|
|
|
auto learnedAttack = LearnedAttack(lib->GetAttackLibrary()->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
2019-10-31 11:02:23 +00:00
|
|
|
auto choice1 = new PassTurnChoice(nullptr);
|
2020-03-22 12:42:26 +00:00
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, &learnedAttack, CreatureIndex(0, 0));
|
2019-11-10 16:08:42 +00:00
|
|
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
2020-02-26 12:51:16 +00:00
|
|
|
auto rand = Arbutils::Random();
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 11:02:23 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2019-11-10 16:08:42 +00:00
|
|
|
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 11:02:23 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
|
|
|
delete choice1;
|
|
|
|
delete choice2;
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
|
2020-03-26 21:46:14 +00:00
|
|
|
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
2020-02-27 17:23:23 +00:00
|
|
|
auto a1 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown);
|
2019-12-05 08:53:48 +00:00
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
2019-11-10 16:08:42 +00:00
|
|
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
2020-02-26 12:51:16 +00:00
|
|
|
auto rand = Arbutils::Random();
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2019-11-10 16:08:42 +00:00
|
|
|
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
|
|
|
delete choice1;
|
|
|
|
delete choice2;
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
|
2020-03-26 21:46:14 +00:00
|
|
|
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
2020-02-27 17:23:23 +00:00
|
|
|
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown);
|
2019-12-05 08:53:48 +00:00
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
2019-11-10 16:08:42 +00:00
|
|
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
2020-02-26 12:51:16 +00:00
|
|
|
auto rand = Arbutils::Random();
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2019-11-10 16:08:42 +00:00
|
|
|
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
|
|
|
delete choice1;
|
|
|
|
delete choice2;
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
|
2020-03-26 21:46:14 +00:00
|
|
|
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
2020-02-27 17:23:23 +00:00
|
|
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown);
|
2019-12-05 08:53:48 +00:00
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
2019-11-10 16:08:42 +00:00
|
|
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
2020-02-26 12:51:16 +00:00
|
|
|
auto rand = Arbutils::Random();
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2019-11-10 16:08:42 +00:00
|
|
|
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
|
|
|
delete choice1;
|
|
|
|
delete choice2;
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
2020-03-26 21:46:14 +00:00
|
|
|
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
2020-02-27 17:23:23 +00:00
|
|
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
2019-12-05 08:53:48 +00:00
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
2019-11-10 16:08:42 +00:00
|
|
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
2020-02-26 12:51:16 +00:00
|
|
|
auto rand = Arbutils::Random();
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
2019-11-10 16:08:42 +00:00
|
|
|
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
2019-11-28 11:55:22 +00:00
|
|
|
TurnOrdering::OrderChoices(vec, rand);
|
2019-10-31 12:03:41 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
|
|
|
|
delete choice1;
|
|
|
|
delete choice2;
|
2019-10-31 12:33:32 +00:00
|
|
|
delete a1;
|
|
|
|
delete a2;
|
2019-10-31 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 11:02:23 +00:00
|
|
|
#endif
|