Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@

// One pass as it shows in the expected steps.
const std::string PASS = "fly clear return heal";
// A pass that returns without healing.
const std::string LAST_PASS = "fly clear return";

std::string passes(int count){
std::vector<std::string> ret(count, PASS);
Expand Down Expand Up @@ -264,43 +266,44 @@

}

static void add_tests_BBQAutoBattle(UnitTestDatabase& database){

Check failure on line 269 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::add_tests_BBQAutoBattle( UnitTestDatabase & database): function_lines=52, limit=50, allowed 51
constexpr int PASS_SECONDS = ScriptedAutoBattle::FLY_SECONDS + ScriptedAutoBattle::CLEAR_SECONDS
+ ScriptedAutoBattle::RETURN_SECONDS + ScriptedAutoBattle::HEAL_SECONDS;
constexpr int LAST_PASS_SAVED_SECONDS = ScriptedAutoBattle::CLEAR_TAIL_SECONDS + ScriptedAutoBattle::HEAL_SECONDS;
const BBQAutoBattleScenario scenarios[] = {
{
// The final pass still heals and re-flies, though the quest is done.
// The final pass stops clearing at the target, and skips the heal and re-fly.
.name = "auto battle 10 at 2 kills per pass",
.kills_per_clear = {2, 2, 2, 2, 2},
.expected_steps = passes(5),
.expected_seconds = 5 * PASS_SECONDS,
.expected_steps = passes(4) + " " + LAST_PASS,
.expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
.expected_log = {
"Auto Battle pass 1: 2 kills, 2/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 2: 2 kills, 4/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 3: 2 kills, 6/10 in total, HP ?, 250 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 4: 2 kills, 8/10 in total, HP ?, 352 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 5: 2 kills, 10/10 in total, HP ?, 454 s elapsed. Target reached: return and heal.",
"Auto Battle pass 5: 2 kills, 10/10 in total, HP ?, 448 s elapsed. Target reached: return without healing.",
},
},
{
.name = "auto battle 30 at 3 kills per pass",
.kill_target = 30,
.kills_per_clear = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
.expected_steps = passes(10),
.expected_seconds = 10 * PASS_SECONDS,
.expected_steps = passes(9) + " " + LAST_PASS,
.expected_seconds = 10 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
},
{
// A clear keeps going while kills are heard, past the target.
// Kills heard before the clear can stop still count.
.name = "kills past the target",
.kills_per_clear = {4, 4, 4},
.expected_steps = passes(3),
.expected_seconds = 3 * PASS_SECONDS,
.expected_steps = passes(2) + " " + LAST_PASS,
.expected_seconds = 3 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
},
{
.name = "passes with no kill go again",
.kills_per_clear = {0, 0, 5, 0, 5},
.expected_steps = passes(5),
.expected_seconds = 5 * PASS_SECONDS,
.expected_steps = passes(4) + " " + LAST_PASS,
.expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
},
{
// Nothing bounds the loop: with no kills it never ends.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include<cmath>
#include<limits>
#include<optional>
#include<vector>
#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h"
Expand Down Expand Up @@ -1260,8 +1259,7 @@ BBQAutoBattleResult run_auto_battle(
const uint64_t kills_before = actions.kills();

actions.fly_to_battle_area();
//Clear until no kill has been heard for 6 seconds, even past the target.
const std::optional<double> hp = actions.clear(std::numeric_limits<uint64_t>::max());
const std::optional<double> hp = actions.clear(policy.kill_target);

const uint64_t kills = actions.kills();
const auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(actions.now() - start);
Expand All @@ -1271,7 +1269,7 @@ BBQAutoBattleResult run_auto_battle(
std::string next = "Below the target: return, heal and go again.";
if (kills >= policy.kill_target){
end = BBQAutoBattleResult::TargetReached;
next = "Target reached: return and heal.";
next = "Target reached: return without healing.";
}
logger.log(
"Auto Battle pass " + std::to_string(pass) + ": "
Expand All @@ -1282,11 +1280,12 @@ BBQAutoBattleResult run_auto_battle(
+ next
);

//The next quest starts from Central Plaza, so return even when done.
actions.return_to_plaza();
actions.heal();
if (end){
return *end;
}
actions.heal();
}
return BBQAutoBattleResult::TargetReached;
}
Expand Down
Loading