Use smart pointers for BattleSide.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -16,11 +16,11 @@ TEST_CASE("Move creature choice up next.", "[Battling]") {
|
||||
auto c3 = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
|
||||
auto c4 = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
|
||||
|
||||
std::vector<BaseTurnChoice*> choices = {
|
||||
new PassTurnChoice(c1),
|
||||
new PassTurnChoice(c2),
|
||||
new PassTurnChoice(c3),
|
||||
new PassTurnChoice(c4),
|
||||
std::vector<std::shared_ptr<BaseTurnChoice>> choices = {
|
||||
std::make_shared<PassTurnChoice>(c1),
|
||||
std::make_shared<PassTurnChoice>(c2),
|
||||
std::make_shared<PassTurnChoice>(c3),
|
||||
std::make_shared<PassTurnChoice>(c4),
|
||||
};
|
||||
|
||||
auto choiceQueue = ChoiceQueue(choices);
|
||||
|
||||
@@ -14,7 +14,6 @@ TEST_CASE("Set Choice one-sized side", "[Battling]") {
|
||||
side.SetCreature(c, 0);
|
||||
auto choice = new PassTurnChoice(c);
|
||||
side.SetChoice(choice);
|
||||
delete choice;
|
||||
delete c;
|
||||
}
|
||||
|
||||
@@ -26,7 +25,6 @@ TEST_CASE("Set Choice one-sized side, validate all choices set", "[Battling]") {
|
||||
REQUIRE_FALSE(side.AllChoicesSet());
|
||||
side.SetChoice(choice);
|
||||
REQUIRE(side.AllChoicesSet());
|
||||
delete choice;
|
||||
delete c;
|
||||
}
|
||||
|
||||
@@ -40,8 +38,6 @@ TEST_CASE("Set Choice two-sized side", "[Battling]") {
|
||||
auto choice2 = new PassTurnChoice(c2);
|
||||
side.SetChoice(choice1);
|
||||
side.SetChoice(choice2);
|
||||
delete choice1;
|
||||
delete choice2;
|
||||
delete c1;
|
||||
delete c2;
|
||||
}
|
||||
@@ -59,8 +55,6 @@ TEST_CASE("Set Choice two-sized side, validate all choices set", "[Battling]") {
|
||||
REQUIRE_FALSE(side.AllChoicesSet());
|
||||
side.SetChoice(choice2);
|
||||
REQUIRE(side.AllChoicesSet());
|
||||
delete choice1;
|
||||
delete choice2;
|
||||
delete c1;
|
||||
delete c2;
|
||||
}
|
||||
|
||||
@@ -13,40 +13,35 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
|
||||
auto lib = TestLibrary::Get();
|
||||
auto learnedAttack =
|
||||
LearnedAttack(lib->GetAttackLibrary()->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new PassTurnChoice(nullptr);
|
||||
auto choice2 = new AttackTurnChoice(nullptr, &learnedAttack, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto choice1 = std::make_shared<PassTurnChoice>(nullptr);
|
||||
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, &learnedAttack, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
||||
auto rand = ArbUt::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
||||
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
|
||||
delete choice1;
|
||||
delete choice2;
|
||||
}
|
||||
|
||||
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
|
||||
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
||||
auto rand = ArbUt::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
||||
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
|
||||
delete choice1;
|
||||
delete choice2;
|
||||
delete a1;
|
||||
delete a2;
|
||||
}
|
||||
@@ -55,20 +50,17 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
|
||||
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
||||
auto rand = ArbUt::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
||||
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
|
||||
delete choice1;
|
||||
delete choice2;
|
||||
delete a1;
|
||||
delete a2;
|
||||
}
|
||||
@@ -77,20 +69,18 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
|
||||
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
||||
auto rand = ArbUt::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
||||
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
|
||||
delete choice1;
|
||||
delete choice2;
|
||||
delete a1;
|
||||
delete a2;
|
||||
}
|
||||
@@ -99,20 +89,18 @@ TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
||||
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
|
||||
auto rand = ArbUt::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
|
||||
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
|
||||
delete choice1;
|
||||
delete choice2;
|
||||
delete a1;
|
||||
delete a2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user