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 @@ -131,7 +131,7 @@
}


BBQOption::BBQOption(OCR::LanguageOCROption* language_option)

Check failure on line 134 in SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::BBQOption::BBQOption( OCR :: LanguageOCROption * language_option): function_lines=87, limit=50, allowed 81
: GroupOption("Blueberry Quests", LockMode::UNLOCK_WHILE_RUNNING)
, m_language_owner(language_option == nullptr
? new OCR::LanguageOCROption(
Expand Down Expand Up @@ -185,6 +185,11 @@
"<b>Hatch Quest - Fix time for eggs:</b><br>Fix the time before doing a hatch egg quest.",
LockMode::UNLOCK_WHILE_RUNNING, false
)
, AUTO_BATTLE_HEAL_PERCENT(
"<b>Auto Battle Quest - Heal Below HP %:</b><br>Between passes, heal at the Pokemon Center only if your lead's HP is below this percentage. "
"If its HP could not be read, heal anyway.",
LockMode::UNLOCK_WHILE_RUNNING, 50, 0, 100
)
, CATCH_ON_WIN(true)
, NUM_RETRIES(
"<b>Number of Retries:</b><br>Reattempt a quest this many times if it fails.",
Expand All @@ -207,6 +212,7 @@
PA_ADD_OPTION(NUM_EGGS);
PA_ADD_OPTION(OUT_OF_EGGS);
PA_ADD_OPTION(FIX_TIME_FOR_HATCH);
PA_ADD_OPTION(AUTO_BATTLE_HEAL_PERCENT);
PA_ADD_OPTION(BATTLE_AI);
PA_ADD_OPTION(CATCH_ON_WIN);
PA_ADD_OPTION(NUM_RETRIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class BBQOption : public GroupOption{
EnumDropdownOption<OOEggs> OUT_OF_EGGS;
BooleanCheckBoxOption FIX_TIME_FOR_HATCH;

//Auto battle quest
SimpleIntegerOption<uint8_t> AUTO_BATTLE_HEAL_PERCENT;

//Tera raid
TeraAIOption BATTLE_AI;
TeraFarmerCatchOnWin CATCH_ON_WIN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
// Kills heard in each clear, in turn. Running past the end throws, which
// also stops a loop that would never end.
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;

std::vector<std::string> steps;
int seconds = 0;
Expand All @@ -180,11 +182,12 @@
}
steps.push_back("clear");
seconds += CLEAR_SECONDS;
const std::optional<double> hp = m_clears < hp_per_clear.size() ? hp_per_clear[m_clears] : std::nullopt;
m_kills += kills_per_clear[m_clears++];
if (m_kills >= stop_at_kills){
seconds -= CLEAR_TAIL_SECONDS;
}
return std::nullopt;
return hp;
}
virtual void return_to_plaza() override{
steps.push_back("return");
Expand All @@ -205,8 +208,8 @@
// 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);
std::string passes(int count, const std::string& pass = PASS){
std::vector<std::string> ret(count, pass);
return join(ret, " ");
}

Expand All @@ -224,6 +227,8 @@
uint64_t kill_target = 10;
int time_limit_minutes = 35;
std::vector<uint64_t> kills_per_clear;
std::vector<std::optional<double>> hp_per_clear = {}; // Unknown when not given.
int heal_below_hp_percent = 50;
BBQAutoBattleResult expected_result = BBQAutoBattleResult::TargetReached;
std::string expected_steps;
int expected_seconds = 0;
Expand All @@ -237,14 +242,16 @@
, m_scenario(std::move(scenario))
{}

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

Check warning on line 245 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=34 (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;

RecordingLogger logger;
BBQAutoBattlePolicy policy;
policy.kill_target = m_scenario.kill_target;
policy.time_limit = std::chrono::minutes(m_scenario.time_limit_minutes);
policy.heal_below_hp_percent = (uint8_t)m_scenario.heal_below_hp_percent;
BBQAutoBattleResult result;
try{
result = run_auto_battle(logger, actions, policy);
Expand Down Expand Up @@ -276,7 +283,7 @@

}

static void add_tests_BBQAutoBattle(UnitTestDatabase& database){

Check failure on line 286 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=172, limit=50, allowed 87
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 All @@ -288,10 +295,10 @@
.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 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: 2 kills, 6/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 4: 2 kills, 8/10 in total, HP ?, 352 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 5: 2 kills, 10/10 in total, HP ?, 448 s elapsed. Target reached: return without healing.",
},
},
Expand Down Expand Up @@ -322,8 +329,8 @@
.expected_steps = passes(2) + " " + LAST_PASS,
.expected_seconds = 3 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
.expected_log = {
"Auto Battle pass 1: 0 kills, 0/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 2: 0 kills, 0/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 1: 0 kills, 0/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 2: 0 kills, 0/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 3: 0 kills, 0/10 in total, HP ?, 250 s elapsed. No kill in 3 passes in a row: return and give up.",
},
},
Expand All @@ -344,9 +351,9 @@
.expected_steps = passes(3) + " " + LAST_PASS,
.expected_seconds = 4 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
.expected_log = {
"Auto Battle pass 1: 1 kills, 1/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 2: 1 kills, 2/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 3: 1 kills, 3/10 in total, HP ?, 250 s elapsed. Below the target: return, heal and go again.",
"Auto Battle pass 1: 1 kills, 1/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 2: 1 kills, 2/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 3: 1 kills, 3/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 4: 1 kills, 4/10 in total, HP ?, 352 s elapsed. Time limit of 5 min reached: return and give up.",
},
},
Expand All @@ -358,6 +365,91 @@
.expected_steps = passes(3) + " " + LAST_PASS,
.expected_seconds = 4 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
},
{
// Same kills as "auto battle 10 at 2 kills per pass", 4 heals (112 s) faster.
.name = "high HP skips the heal",
.kills_per_clear = {2, 2, 2, 2, 2},
.hp_per_clear = {0.8, 0.8, 0.8, 0.8, 0.8},
.expected_steps = passes(5, LAST_PASS),
.expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 4 * ScriptedAutoBattle::HEAL_SECONDS,
.expected_log = {
"Auto Battle pass 1: 2 kills, 2/10 in total, HP 80%, 46 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
"Auto Battle pass 2: 2 kills, 4/10 in total, HP 80%, 120 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
"Auto Battle pass 3: 2 kills, 6/10 in total, HP 80%, 194 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
"Auto Battle pass 4: 2 kills, 8/10 in total, HP 80%, 268 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
"Auto Battle pass 5: 2 kills, 10/10 in total, HP 80%, 336 s elapsed. Target reached: return without healing.",
},
},
{
// Same kills as "auto battle 30 at 3 kills per pass", 9 heals (252 s) faster.
.name = "high HP skips the heal in auto battle 30",
.kill_target = 30,
.kills_per_clear = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
.hp_per_clear = {0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9},
.expected_steps = passes(10, LAST_PASS),
.expected_seconds = 10 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 9 * ScriptedAutoBattle::HEAL_SECONDS,
},
{
.name = "low HP heals",
.kills_per_clear = {2, 2, 2, 2, 2},
.hp_per_clear = {0.3, 0.3, 0.3, 0.3, 0.3},
.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 30%, 46 s elapsed. Below the target and HP below 50%: return, heal and go again.",
"Auto Battle pass 2: 2 kills, 4/10 in total, HP 30%, 148 s elapsed. Below the target and HP below 50%: return, heal and go again.",
"Auto Battle pass 3: 2 kills, 6/10 in total, HP 30%, 250 s elapsed. Below the target and HP below 50%: return, heal and go again.",
"Auto Battle pass 4: 2 kills, 8/10 in total, HP 30%, 352 s elapsed. Below the target and HP below 50%: return, heal and go again.",
"Auto Battle pass 5: 2 kills, 10/10 in total, HP 30%, 448 s elapsed. Target reached: return without healing.",
},
},
{
// Unknown HP heals, as every pass did before the threshold.
.name = "unknown HP heals",
.kills_per_clear = {2, 2, 2, 2, 2},
.hp_per_clear = {0.8, std::nullopt, 0.8, std::nullopt, 0.8},
.expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS + " " + PASS + " " + LAST_PASS,
.expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 2 * ScriptedAutoBattle::HEAL_SECONDS,
},
{
// HP at the threshold skips the heal; just below heals.
.name = "heal threshold boundary",
.kills_per_clear = {3, 3, 3, 3},
.hp_per_clear = {0.5, 0.49, 0.5, 0.5},
.expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS + " " + LAST_PASS,
.expected_seconds = 4 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 2 * ScriptedAutoBattle::HEAL_SECONDS,
.expected_log = {
"Auto Battle pass 1: 3 kills, 3/10 in total, HP 50%, 46 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
"Auto Battle pass 2: 3 kills, 6/10 in total, HP 49%, 120 s elapsed. Below the target and HP below 50%: return, heal and go again.",
"Auto Battle pass 3: 3 kills, 9/10 in total, HP 50%, 222 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
"Auto Battle pass 4: 3 kills, 12/10 in total, HP 50%, 290 s elapsed. Target reached: return without healing.",
},
},
{
.name = "a threshold of 100% heals unless HP is full",
.kills_per_clear = {4, 4, 4},
.hp_per_clear = {1.0, 0.99, 1.0},
.heal_below_hp_percent = 100,
.expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS,
.expected_seconds = 3 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
},
{
.name = "a threshold of 0% heals only when HP is unknown",
.kills_per_clear = {4, 4, 4},
.hp_per_clear = {0.01, std::nullopt, 0.01},
.heal_below_hp_percent = 0,
.expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS,
.expected_seconds = 3 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
},
{
// The limits still end the attempt when no pass heals.
.name = "gives up after 3 passes with no kill and high HP",
.kills_per_clear = {0, 0, 0},
.hp_per_clear = {1.0, 1.0, 1.0},
.expected_result = BBQAutoBattleResult::NoKills,
.expected_steps = passes(3, LAST_PASS),
.expected_seconds = 3 * (PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS),
},
};
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=1448, limit=1000, allowed 1431
*
* 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=66, limit=50, allowed 50
Logger& logger,
BBQAutoBattleActions& actions,
const BBQAutoBattlePolicy& policy
Expand All @@ -1265,10 +1265,22 @@
const uint64_t kills = actions.kills();
empty_passes = kills == kills_before ? empty_passes + 1 : 0;
const auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(actions.now() - start);

//Unknown HP heals, as every pass did before the threshold existed. The log rounds HP
//down, so it shows below the threshold exactly when it is.
const bool heal = !hp || *hp * 100 < policy.heal_below_hp_percent;
const std::string hp_text = hp ? std::to_string((int)std::floor(*hp * 100)) + "%" : "?";
const std::string threshold_text = std::to_string(policy.heal_below_hp_percent) + "%";

std::optional<BBQAutoBattleResult> end;
std::string next = "Below the target: return, heal and go again.";
std::string next;
if (!hp){
next = "Below the target and HP unknown: return, heal and go again.";
}else if (heal){
next = "Below the target and HP below " + threshold_text + ": return, heal and go again.";
}else{
next = "Below the target and HP at or above " + threshold_text + ": return and go again without healing.";
}
if (kills >= policy.kill_target){
end = BBQAutoBattleResult::TargetReached;
next = "Target reached: return without healing.";
Expand All @@ -1293,7 +1305,11 @@
if (end){
return *end;
}
actions.heal();
//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){
actions.heal();
}
}
return BBQAutoBattleResult::TargetReached;
}
Expand Down Expand Up @@ -1390,7 +1406,7 @@

}

void quest_auto_battle(

Check warning on line 1409 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::quest_auto_battle( ProgramEnvironment & env , VideoStream & stream , ProControllerContext & context , const BBQOption & BBQ_OPTIONS , BBQuests current_quest): function_lines=34 (advisory above 25, limit 50)
ProgramEnvironment& env,
VideoStream& stream, ProControllerContext& context,
const BBQOption& BBQ_OPTIONS,
Expand Down Expand Up @@ -1419,6 +1435,7 @@
policy.kill_target = 30;
policy.time_limit = std::chrono::minutes(60);
}
policy.heal_below_hp_percent = BBQ_OPTIONS.AUTO_BATTLE_HEAL_PERCENT;

ConsoleBBQAutoBattleActions actions(env, stream, context, stats, tracker, sensors.lets_go_hp);
run_auto_battle(stream.logger(), actions, policy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ struct BBQAutoBattlePolicy{
uint64_t max_empty_passes = 3;
//Give up after the pass that ends past this time.
std::chrono::minutes time_limit = std::chrono::minutes(35);
//Between passes, heal only if the lead's HP is below this percentage or unknown.
uint8_t heal_below_hp_percent = 50;
};

//Why run_auto_battle() returned.
Expand Down
Loading