2019-10-31 11:02:23 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
|
|
|
|
#include "../TestLibrary/TestLibrary.cpp"
|
|
|
|
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
|
|
|
|
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
|
|
|
|
#include "../../src/Battling/Flow/TurnOrdering.hpp"
|
|
|
|
|
2019-10-31 11:31:31 +00:00
|
|
|
using namespace CreatureLib;
|
2019-10-31 11:02:23 +00:00
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
|
|
|
|
TEST_CASE( "Turn ordering: Attack before pass", "[Battling]" ) {
|
|
|
|
auto choice1 = new PassTurnChoice(nullptr);
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, nullptr);
|
|
|
|
auto vec = std::vector<const BaseTurnChoice*>{choice1, choice2};
|
2019-10-31 11:31:31 +00:00
|
|
|
auto rand = Core::Random();
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
2019-10-31 11:02:23 +00:00
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
vec = std::vector<const BaseTurnChoice*>{choice2, choice1};
|
2019-10-31 11:31:31 +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-10-31 12:03:41 +00:00
|
|
|
TEST_CASE( "Turn ordering: High priority goes before no priority", "[Battling]" ) {
|
|
|
|
auto l = GetLibrary()->GetAttackLibrary();
|
2019-10-31 12:33:32 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown);
|
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1);
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2);
|
2019-10-31 12:03:41 +00:00
|
|
|
auto vec = std::vector<const BaseTurnChoice*>{choice1, choice2};
|
|
|
|
auto rand = Core::Random();
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
vec = std::vector<const BaseTurnChoice*>{choice2, choice1};
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "Turn ordering: Higher priority goes before high priority", "[Battling]" ) {
|
|
|
|
auto l = GetLibrary()->GetAttackLibrary();
|
2019-10-31 12:33:32 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown);
|
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1);
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2);
|
2019-10-31 12:03:41 +00:00
|
|
|
auto vec = std::vector<const BaseTurnChoice*>{choice1, choice2};
|
|
|
|
auto rand = Core::Random();
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
vec = std::vector<const BaseTurnChoice*>{choice2, choice1};
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "Turn ordering: High priority goes before low priority", "[Battling]" ) {
|
|
|
|
auto l = GetLibrary()->GetAttackLibrary();
|
2019-10-31 12:33:32 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown);
|
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1);
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2);
|
2019-10-31 12:03:41 +00:00
|
|
|
auto vec = std::vector<const BaseTurnChoice*>{choice1, choice2};
|
|
|
|
auto rand = Core::Random();
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
vec = std::vector<const BaseTurnChoice*>{choice2, choice1};
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "Turn ordering: No priority goes before low priority", "[Battling]" ) {
|
|
|
|
auto l = GetLibrary()->GetAttackLibrary();
|
2019-10-31 12:33:32 +00:00
|
|
|
auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown);
|
|
|
|
auto a2 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown);
|
|
|
|
auto choice1 = new AttackTurnChoice(nullptr, a1);
|
|
|
|
auto choice2 = new AttackTurnChoice(nullptr, a2);
|
2019-10-31 12:03:41 +00:00
|
|
|
auto vec = std::vector<const BaseTurnChoice*>{choice1, choice2};
|
|
|
|
auto rand = Core::Random();
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
CHECK(vec[0] == choice2);
|
|
|
|
CHECK(vec[1] == choice1);
|
|
|
|
vec = std::vector<const BaseTurnChoice*>{choice2, choice1};
|
|
|
|
TurnOrdering::OrderChoices(vec,rand);
|
|
|
|
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
|