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
@@ -1,4 +1,4 @@
/* Pokemon SV BBQ Tests

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=526 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -162,6 +162,9 @@
std::vector<uint64_t> kills_per_clear;
// The lead's HP read in each clear, in turn. Past the end, it is unknown.
std::vector<std::optional<double>> hp_per_clear;
// Kills heard on each flight back, in turn: the lead finishing a kill
// after the clear ends. Past the end, none.
std::vector<uint64_t> kills_per_return;

std::vector<std::string> steps;
int seconds = 0;
Expand Down Expand Up @@ -192,6 +195,10 @@
virtual void return_to_plaza() override{
steps.push_back("return");
seconds += RETURN_SECONDS;
if (m_returns < kills_per_return.size()){
m_kills += kills_per_return[m_returns];
}
m_returns++;
}
virtual void heal() override{
steps.push_back("heal");
Expand All @@ -201,6 +208,7 @@
private:
uint64_t m_kills = 0;
size_t m_clears = 0;
size_t m_returns = 0;
};

// One pass as it shows in the expected steps.
Expand Down Expand Up @@ -228,6 +236,7 @@
int time_limit_minutes = 35;
std::vector<uint64_t> kills_per_clear;
std::vector<std::optional<double>> hp_per_clear = {}; // Unknown when not given.
std::vector<uint64_t> kills_per_return = {}; // None when not given.
int heal_below_hp_percent = 50;
BBQAutoBattleResult expected_result = BBQAutoBattleResult::TargetReached;
std::string expected_steps;
Expand All @@ -242,10 +251,11 @@
, m_scenario(std::move(scenario))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{

Check warning on line 254 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::Test_BBQAutoBattle::run( Logger & , CancellableScope &) const: function_lines=35 (advisory above 25, limit 50)
ScriptedAutoBattle actions;
actions.kills_per_clear = m_scenario.kills_per_clear;
actions.hp_per_clear = m_scenario.hp_per_clear;
actions.kills_per_return = m_scenario.kills_per_return;

RecordingLogger logger;
BBQAutoBattlePolicy policy;
Expand Down Expand Up @@ -283,7 +293,7 @@

}

static void add_tests_BBQAutoBattle(UnitTestDatabase& database){

Check failure on line 296 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=209, limit=50, allowed 172
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;
Expand Down Expand Up @@ -450,6 +460,43 @@
.expected_steps = passes(3, LAST_PASS),
.expected_seconds = 3 * (PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS),
},
{
// R3b: "pass 2: 1 kills, 4/10 in total" after "2/10". A kill heard after a pass's
// line counts in the next one, so the passes add up to the total.
.name = "a kill heard on the way back counts in the next pass",
.kills_per_clear = {2, 1, 3, 4},
.kills_per_return = {1},
.expected_steps = passes(3) + " " + LAST_PASS,
.expected_seconds = 4 * 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 and HP unknown: return, heal and go again.",
"Auto Battle pass 2: 2 kills, 4/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 3: 3 kills, 7/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 4: 4 kills, 11/10 in total, HP ?, 346 s elapsed. Target reached: return without healing.",
},
},
{
// A pass whose only kill was heard on the previous flight back is not empty.
.name = "a kill heard on the way back resets the empty passes",
.kills_per_clear = {0, 0, 0, 0, 0, 0},
.kills_per_return = {0, 1},
.expected_result = BBQAutoBattleResult::NoKills,
.expected_steps = passes(5) + " " + LAST_PASS,
.expected_seconds = 6 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
},
{
.name = "a kill heard on the way back that reaches the target skips the heal",
.kills_per_clear = {3, 3, 3},
.kills_per_return = {0, 0, 1},
.expected_steps = passes(2) + " " + LAST_PASS,
.expected_seconds = 3 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
.expected_log = {
"Auto Battle pass 1: 3 kills, 3/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 2: 3 kills, 6/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 3: 3 kills, 9/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle: kills heard on the way back reached the target, 10/10. Stop without healing.",
},
},
};
for (const BBQAutoBattleScenario& scenario : scenarios){
database.add<Test_BBQAutoBattle>(scenario);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Blueberry Quests

Check failure on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

<file>: file_lines=1460, limit=1000, allowed 1448
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -1247,7 +1247,7 @@
day_skip_from_overworld(console, context);
}

BBQAutoBattleResult run_auto_battle(

Check failure on line 1250 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::run_auto_battle( Logger & logger , BBQAutoBattleActions & actions , const BBQAutoBattlePolicy & policy): function_lines=78, limit=50, allowed 66
Logger& logger,
BBQAutoBattleActions& actions,
const BBQAutoBattlePolicy& policy
Expand All @@ -1255,9 +1255,12 @@
const WallClock start = actions.now();
uint64_t pass = 0;
uint64_t empty_passes = 0;
//The kill sound is heard in every step, not only while clearing: the lead can finish a kill
//after the clear ends, as the flight back starts. Each pass counts the kills since the last
//pass log, so a kill heard after it goes to the next pass and the passes add up to the total.
uint64_t kills_before = actions.kills();
while (actions.kills() < policy.kill_target){
pass++;
const uint64_t kills_before = actions.kills();

actions.fly_to_battle_area();
const std::optional<double> hp = actions.clear(policy.kill_target);
Expand Down Expand Up @@ -1299,12 +1302,21 @@
+ std::to_string(elapsed.count()) + " s elapsed. "
+ next
);
kills_before = kills;

//The next quest starts from Central Plaza, so return even when done.
actions.return_to_plaza();
if (end){
return *end;
}
if (actions.kills() >= policy.kill_target){
logger.log(
"Auto Battle: kills heard on the way back reached the target, "
+ std::to_string(actions.kills()) + "/" + std::to_string(policy.kill_target)
+ ". Stop without healing."
);
return BBQAutoBattleResult::TargetReached;
}
//Skipping the heal also skips its re-fly: return_to_plaza() already lands on the Central
//Plaza fly point, which is where the flight to Chargestone starts from.
if (heal){
Expand Down
Loading