Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2779423
PokemonSV: move the BBQ farmer's tests into their own file
dayfine Oct 27, 2026
0181f81
BBQ: run the Auto Battle loop against injectable game steps
dayfine Oct 22, 2026
fda42de
BBQ: stop an Auto Battle quest once its kills reach the target
dayfine Oct 28, 2026
a536fda
BBQ: give up an Auto Battle quest after 3 empty passes or a time limit
dayfine Oct 28, 2026
3a0b28e
BBQ: heal between Auto Battle passes only when HP is low (behavior ch…
dayfine Oct 28, 2026
0667c79
BBQ: count kills heard on the way back in the Auto Battle pass log
dayfine Oct 28, 2026
a48d541
BBQ: near the Auto Battle target, stop when the quest leaves the boar…
dayfine Oct 28, 2026
daa1de3
PokemonSV: move the BBQ farmer's tests into their own file
dayfine Oct 27, 2026
ad2fe1a
Merge origin/bbq/tests-file into bbq/auto-battle-seam
dayfine Oct 30, 2026
7a1b8fb
Merge origin/bbq/auto-battle-seam into bbq/auto-battle-stop-at-target
dayfine Oct 30, 2026
66f1111
Merge origin/bbq/auto-battle-stop-at-target into bbq/auto-battle-bounds
dayfine Oct 30, 2026
70e7a58
Merge origin/bbq/auto-battle-bounds into bbq/auto-battle-heal-threshold
dayfine Oct 30, 2026
d130543
Merge origin/bbq/auto-battle-heal-threshold into bbq/auto-battle-kill…
dayfine Oct 30, 2026
84b8630
Merge origin/bbq/auto-battle-kill-count into bbq/auto-battle-quest-do…
dayfine Oct 30, 2026
9e681ce
Merge upstream/main into bbq/tests-file
dayfine Nov 2, 2026
53236ce
Merge bbq/tests-file into bbq/auto-battle-seam
dayfine Nov 2, 2026
a108b4d
Merge bbq/auto-battle-seam into bbq/auto-battle-stop-at-target
dayfine Nov 2, 2026
e324a29
Merge bbq/auto-battle-stop-at-target into bbq/auto-battle-bounds
dayfine Nov 2, 2026
5216242
Merge bbq/auto-battle-bounds into bbq/auto-battle-heal-threshold
dayfine Nov 2, 2026
0078342
Merge bbq/auto-battle-heal-threshold into bbq/auto-battle-kill-count
dayfine Nov 2, 2026
0ae8f9c
Merge bbq/auto-battle-kill-count into bbq/auto-battle-quest-done-check
dayfine Nov 2, 2026
01ed372
Merge origin/main into bbq/tests-file
dayfine Nov 3, 2026
af1bd4a
Merge origin/bbq/tests-file into bbq/auto-battle-seam
dayfine Nov 3, 2026
2484600
Merge origin/bbq/auto-battle-seam into bbq/auto-battle-stop-at-target
dayfine Nov 3, 2026
d2cc9c6
Merge origin/bbq/auto-battle-stop-at-target into bbq/auto-battle-bounds
dayfine Nov 3, 2026
a6f0db6
Merge origin/bbq/auto-battle-bounds into bbq/auto-battle-heal-threshold
dayfine Nov 3, 2026
306a0c3
Merge origin/bbq/auto-battle-heal-threshold into bbq/auto-battle-kill…
dayfine Nov 3, 2026
7599b66
Merge origin/bbq/auto-battle-kill-count into bbq/auto-battle-quest-do…
dayfine Nov 3, 2026
bc8cbfb
Merge origin/main into bbq/tests-file
dayfine Nov 4, 2026
f8b11a7
Merge origin/bbq/tests-file into bbq/auto-battle-seam
dayfine Nov 4, 2026
a866b47
Merge origin/bbq/auto-battle-seam into bbq/auto-battle-stop-at-target
dayfine Nov 4, 2026
fb55460
Merge origin/bbq/auto-battle-stop-at-target into bbq/auto-battle-bounds
dayfine Nov 4, 2026
4325514
Merge origin/bbq/auto-battle-bounds into bbq/auto-battle-heal-threshold
dayfine Nov 4, 2026
9f98902
Merge origin/bbq/auto-battle-heal-threshold into bbq/auto-battle-kill…
dayfine Nov 4, 2026
fb73ff5
Merge origin/bbq/auto-battle-kill-count into bbq/auto-battle-quest-do…
dayfine Nov 4, 2026
6259f0d
Merge origin/main into bbq/tests-file
dayfine Nov 6, 2026
d775751
Merge origin/bbq/tests-file into bbq/auto-battle-seam
dayfine Nov 6, 2026
a737cd8
Merge origin/bbq/auto-battle-seam into bbq/auto-battle-stop-at-target
dayfine Nov 6, 2026
347e525
Merge origin/bbq/auto-battle-stop-at-target into bbq/auto-battle-bounds
dayfine Nov 6, 2026
219d090
Merge origin/bbq/auto-battle-bounds into bbq/auto-battle-heal-threshold
dayfine Nov 6, 2026
e8c5f98
Merge origin/bbq/auto-battle-heal-threshold into bbq/auto-battle-kill…
dayfine Nov 6, 2026
ffabc2b
Merge origin/bbq/auto-battle-kill-count into bbq/auto-battle-quest-do…
dayfine Nov 6, 2026
3848169
Merge remote-tracking branch 'origin/main' into bbq/tree2-auto-battle
dayfine Nov 9, 2026
0964aaf
Merge origin/main into bbq/tree2-auto-battle
dayfine Nov 9, 2026
5cbce6c
Merge origin/main into bbq/tree2-auto-battle
dayfine Nov 10, 2026
6fff92d
Merge origin/main into bbq/tree2-auto-battle
dayfine Nov 11, 2026
4bdb9f4
Merge origin/main into bbq/tree2-auto-battle
dayfine Nov 12, 2026
0f61f7d
Merge origin/main into bbq/tree2-auto-battle
dayfine Nov 13, 2026
2c5227b
Merge origin/main into bbq/tree2-auto-battle
dayfine Nov 14, 2026
d9a495d
Merge origin/main into bbq/tree2-auto-battle
dayfine Nov 16, 2026
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* 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=1480, limit=1000, allowed 1322
*
* From: https://github.com/PokemonAutomation/
*
*/

#include<cmath>
#include<optional>
#include<vector>
#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h"
#include "CommonFramework/Tools/ErrorDumper.h"
Expand All @@ -27,6 +29,7 @@
#include "VideoGames/PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h"
#include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h"
#include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_OverworldSensors.h"
#include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoHpReader.h"
#include "VideoGames/PokemonSV/Inference/Boxes/PokemonSV_BoxDetection.h"
#include "VideoGames/PokemonSV/Programs/Boxes/PokemonSV_BoxRoutines.h"
#include "VideoGames/PokemonSV/Programs/PokemonSV_MenuNavigation.h"
Expand Down Expand Up @@ -1244,75 +1247,230 @@
day_skip_from_overworld(console, context);
}

void quest_auto_battle(
ProgramEnvironment& env,
VideoStream& stream, ProControllerContext& context,
const BBQOption& BBQ_OPTIONS,
BBQuests current_quest
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=89, limit=50, allowed 50
Logger& logger,
BBQAutoBattleActions& actions,
const BBQAutoBattlePolicy& policy
){
stream.log("Quest: Auto Battle 10/30");


OverworldSensors sensors(
env.logger(), stream, context
);

LetsGoEncounterBotStats stats;
LetsGoEncounterBotTracker tracker(
env, stream,
stats,
sensors.lets_go_kill
);

uint64_t target_number = 10;
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++;

actions.fly_to_battle_area();
const std::optional<double> hp = actions.clear(policy.kill_target);

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;
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.";
}else if (empty_passes >= policy.max_empty_passes){
end = BBQAutoBattleResult::NoKills;
next = "No kill in " + std::to_string(empty_passes) + " passes in a row: return and give up.";
}else if (elapsed >= policy.time_limit){
end = BBQAutoBattleResult::TimeLimit;
next = "Time limit of " + std::to_string(policy.time_limit.count()) + " min reached: return and give up.";
}
logger.log(
"Auto Battle pass " + std::to_string(pass) + ": "
+ std::to_string(kills - kills_before) + " kills, "
+ std::to_string(kills) + "/" + std::to_string(policy.kill_target) + " in total, "
+ "HP " + hp_text + ", "
+ std::to_string(elapsed.count()) + " s elapsed. "
+ next
);
kills_before = kills;

if (current_quest == BBQuests::auto_30){
target_number = 30;
//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;
}
//The heard count can fall short of the game's: a kill whose sound was missed still counts
//in game. Near the target, read the board before going again. The read (~5 s) costs much
//less than a pass and its heal.
if (actions.kills() + policy.check_board_within_kills >= policy.kill_target){
const std::string count_text = std::to_string(actions.kills()) + "/" + std::to_string(policy.kill_target);
if (!actions.quest_on_board()){
logger.log("Auto Battle: the quest is no longer on the board at " + count_text + " kills heard. Stop: the game completed it.");
return BBQAutoBattleResult::QuestDone;
}
logger.log("Auto Battle: the quest is still on the board at " + count_text + " kills heard. Go again.");
}
//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;
}

while (stats.m_kills < target_number){

central_to_chargestone(env.program_info(), stream, context);
namespace{

class ConsoleBBQAutoBattleActions : public BBQAutoBattleActions{
public:
ConsoleBBQAutoBattleActions(

Check failure on line 1344 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::ConsoleBBQAutoBattleActions::ConsoleBBQAutoBattleActions( ProgramEnvironment & env , VideoStream & stream , ProControllerContext & context , LetsGoEncounterBotStats & stats , LetsGoEncounterBotTracker & tracker , LetsGoHpWatcher & hp_watcher , const BBQOption & options , BBQuests quest): parameters=8, limit=7, allowed 7
ProgramEnvironment& env,
VideoStream& stream, ProControllerContext& context,
LetsGoEncounterBotStats& stats,
LetsGoEncounterBotTracker& tracker,
LetsGoHpWatcher& hp_watcher,
const BBQOption& options,
BBQuests quest
)
: m_env(env), m_stream(stream), m_context(context)
, m_stats(stats), m_tracker(tracker), m_hp_watcher(hp_watcher)
, m_options(options), m_quest(quest)
{}

virtual uint64_t kills() const override{
return m_stats.m_kills;
}
virtual WallClock now() const override{
return current_time();
}
virtual void fly_to_battle_area() override{
central_to_chargestone(m_env.program_info(), m_stream, m_context);

//Wait for spawns
pbf_wait(context, 3000ms);
context.wait_for_all_requests();
pbf_wait(m_context, 3000ms);
m_context.wait_for_all_requests();

//Forward and right, stay in the battle court - safe zone
pbf_press_button(context, BUTTON_L, 160ms, 400ms);
pbf_move_left_joystick(context, {0, +1}, 2000ms, 400ms);
pbf_move_left_joystick(context, {+1, 0}, 1440ms, 400ms);
pbf_press_button(context, BUTTON_L, 160ms, 400ms);
pbf_press_button(m_context, BUTTON_L, 160ms, 400ms);
pbf_move_left_joystick(m_context, {0, +1}, 2000ms, 400ms);
pbf_move_left_joystick(m_context, {+1, 0}, 1440ms, 400ms);
pbf_press_button(m_context, BUTTON_L, 160ms, 400ms);
}
virtual std::optional<double> clear(uint64_t stop_at_kills) override{
//The watcher runs for the whole quest. Forget what it read before this clear, so a reading
//from an earlier pass is never reported as this one's.
m_hp_watcher.clear();

use_lets_go_to_clear_in_front(stream, context, tracker, false, [&](ProControllerContext& context){
use_lets_go_to_clear_in_front(m_stream, m_context, m_tracker, false, [&](ProControllerContext& context){
pbf_move_left_joystick(context, {0, -1}, 1440ms, 400ms);
pbf_wait(context, 12000ms);
context.wait_for_all_requests();
});
},
[&]{ return m_stats.m_kills >= stop_at_kills; }
);

context.wait_for_all_requests();
return_to_plaza(env.program_info(), stream, context);
m_context.wait_for_all_requests();

OverworldWatcher done_healing(stream.logger(), COLOR_BLUE);
pbf_move_left_joystick(context, {0, +1}, 800ms, 160ms);
//Read before leaving: the HP bar is only on screen in the overworld with the lead out.
const double hp = m_hp_watcher.last_known_value();
if (hp <= 0){
return std::nullopt;
}
return hp;
}
virtual void return_to_plaza() override{
PokemonSV::return_to_plaza(m_env.program_info(), m_stream, m_context);
}
virtual bool quest_on_board() override{
const std::vector<BBQuests> quests = read_quests(m_env.program_info(), m_stream, m_context, m_options);
return std::find(quests.begin(), quests.end(), m_quest) != quests.end();
}
virtual void heal() override{
OverworldWatcher done_healing(m_stream.logger(), COLOR_BLUE);
pbf_move_left_joystick(m_context, {0, +1}, 800ms, 160ms);

pbf_mash_button(context, BUTTON_A, 2400ms);
context.wait_for_all_requests();
pbf_mash_button(m_context, BUTTON_A, 2400ms);
m_context.wait_for_all_requests();

int exit = run_until<ProControllerContext>(
stream, context,
m_stream, m_context,
[&](ProControllerContext& context){
pbf_mash_button(context, BUTTON_B, 16000ms);
},
{ { done_healing } }
);
if (exit == 0){
stream.log("Overworld detected.");
m_stream.log("Overworld detected.");
}
open_map_from_overworld(env.program_info(), stream, context);
pbf_press_button(context, BUTTON_ZL, 320ms, 800ms);
fly_to_overworld_from_map(env.program_info(), stream, context);
open_map_from_overworld(m_env.program_info(), m_stream, m_context);
pbf_press_button(m_context, BUTTON_ZL, 320ms, 800ms);
fly_to_overworld_from_map(m_env.program_info(), m_stream, m_context);
}

private:
ProgramEnvironment& m_env;
VideoStream& m_stream;
ProControllerContext& m_context;
LetsGoEncounterBotStats& m_stats;
LetsGoEncounterBotTracker& m_tracker;
LetsGoHpWatcher& m_hp_watcher;
const BBQOption& m_options;
BBQuests m_quest;
};

}

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

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace

void quest_auto_battle(
ProgramEnvironment& env,
VideoStream& stream, ProControllerContext& context,
const BBQOption& BBQ_OPTIONS,
BBQuests current_quest
){
stream.log("Quest: Auto Battle 10/30");


OverworldSensors sensors(
env.logger(), stream, context
);

LetsGoEncounterBotStats stats;
LetsGoEncounterBotTracker tracker(
env, stream,
stats,
sensors.lets_go_kill
);

//The time limits are about 3x the slowest attempts seen with a correct lead.
BBQAutoBattlePolicy policy;
policy.kill_target = 10;
policy.time_limit = std::chrono::minutes(35);

if (current_quest == BBQuests::auto_30){
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, BBQ_OPTIONS, current_quest);
run_auto_battle(stream.logger(), actions, policy);
}


Expand Down
Loading
Loading