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=596 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -149,13 +149,14 @@

// Auto Battle steps that report scripted kills, and charge each step the
// seconds measured on one live pass (bbq-m5 log, 2026-10-21).
class ScriptedAutoBattle : public BBQAutoBattleActions{

Check warning on line 152 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::ScriptedAutoBattle: public_methods=7 (advisory above 5, limit 7)
public:
static constexpr int FLY_SECONDS = 20; // Fly to Chargestone, wait 3 s, walk in (~19.5 s).
static constexpr int CLEAR_SECONDS = 26; // Battling, then 6 s with no kill.
static constexpr int CLEAR_TAIL_SECONDS = 6; // Skipped when the clear stops at `stop_at_kills`.
static constexpr int RETURN_SECONDS = 28; // Fly back to Central Plaza.
static constexpr int HEAL_SECONDS = 28; // Walk to the nurse and heal (14 s), then re-fly (14 s).
static constexpr int BOARD_SECONDS = 5; // Open the quest panel, read it, close it.

// Kills heard in each clear, in turn. Running past the end throws, which
// also stops a loop that would never end.
Expand All @@ -165,6 +166,8 @@
// 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;
// Whether each board read finds the quest, in turn. Past the end, it does.
std::vector<bool> quest_on_board_per_read;

std::vector<std::string> steps;
int seconds = 0;
Expand Down Expand Up @@ -200,6 +203,13 @@
}
m_returns++;
}
virtual bool quest_on_board() override{
steps.push_back("board");
seconds += BOARD_SECONDS;
const bool on_board = m_reads >= quest_on_board_per_read.size() || quest_on_board_per_read[m_reads];
m_reads++;
return on_board;
}
virtual void heal() override{
steps.push_back("heal");
seconds += HEAL_SECONDS;
Expand All @@ -209,6 +219,7 @@
uint64_t m_kills = 0;
size_t m_clears = 0;
size_t m_returns = 0;
size_t m_reads = 0;
};

// One pass as it shows in the expected steps.
Expand All @@ -226,6 +237,7 @@
case BBQAutoBattleResult::TargetReached: return "TargetReached";
case BBQAutoBattleResult::NoKills: return "NoKills";
case BBQAutoBattleResult::TimeLimit: return "TimeLimit";
case BBQAutoBattleResult::QuestDone: return "QuestDone";
}
return "?";
}
Expand All @@ -237,6 +249,8 @@
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.
uint64_t check_board_within_kills = 0; // Off unless a scenario tests it.
std::vector<bool> quest_on_board_per_read = {}; // On the board when not given.
int heal_below_hp_percent = 50;
BBQAutoBattleResult expected_result = BBQAutoBattleResult::TargetReached;
std::string expected_steps;
Expand All @@ -251,17 +265,19 @@
, m_scenario(std::move(scenario))
{}

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

Check warning on line 268 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=37 (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;
actions.quest_on_board_per_read = m_scenario.quest_on_board_per_read;

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;
policy.check_board_within_kills = m_scenario.check_board_within_kills;
BBQAutoBattleResult result;
try{
result = run_auto_battle(logger, actions, policy);
Expand Down Expand Up @@ -293,7 +309,7 @@

}

static void add_tests_BBQAutoBattle(UnitTestDatabase& database){

Check failure on line 312 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=263, limit=50, allowed 209
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 @@ -497,6 +513,60 @@
"Auto Battle: kills heard on the way back reached the target, 10/10. Stop without healing.",
},
},
{
// R3b: 9 kills heard, but the game had completed the quest. The board read
// replaces the 5th pass and its heal.
.name = "near the target, a board without the quest ends it",
.kills_per_clear = {3, 3, 3},
.check_board_within_kills = 2,
.quest_on_board_per_read = {false},
.expected_result = BBQAutoBattleResult::QuestDone,
.expected_steps = passes(2) + " " + LAST_PASS + " board",
.expected_seconds = 3 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS + ScriptedAutoBattle::BOARD_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: the quest is no longer on the board at 9/10 kills heard. Stop: the game completed it.",
},
},
{
// Each pass near the target reads the board until the quest is gone.
.name = "near the target, a board with the quest goes again",
.kills_per_clear = {4, 4, 1, 1},
.check_board_within_kills = 2,
.quest_on_board_per_read = {true, false},
.expected_result = BBQAutoBattleResult::QuestDone,
.expected_steps = PASS + " " + LAST_PASS + " board heal " + LAST_PASS + " board",
.expected_seconds = 3 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS + 2 * ScriptedAutoBattle::BOARD_SECONDS,
.expected_log = {
"Auto Battle pass 1: 4 kills, 4/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 2: 4 kills, 8/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle: the quest is still on the board at 8/10 kills heard. Go again.",
"Auto Battle pass 3: 1 kills, 9/10 in total, HP ?, 255 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle: the quest is no longer on the board at 9/10 kills heard. Stop: the game completed it.",
},
},
{
// Far from the target the board is never read, and reaching the target
// needs no read.
.name = "far from the target, no board read",
.kills_per_clear = {5, 5},
.check_board_within_kills = 2,
.quest_on_board_per_read = {false},
.expected_steps = PASS + " " + LAST_PASS,
.expected_seconds = 2 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
},
{
// High HP skips the heal but not the read.
.name = "near the target with high HP, read the board without healing",
.kill_target = 30,
.kills_per_clear = {10, 10, 9, 1},
.hp_per_clear = {0.9, 0.9, 0.9, 0.9},
.check_board_within_kills = 2,
.expected_steps = passes(2, LAST_PASS) + " " + LAST_PASS + " board " + LAST_PASS,
.expected_seconds = 4 * (PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS) - ScriptedAutoBattle::CLEAR_TAIL_SECONDS + ScriptedAutoBattle::BOARD_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=1480, limit=1000, allowed 1460
*
* 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=89, limit=50, allowed 78
Logger& logger,
BBQAutoBattleActions& actions,
const BBQAutoBattlePolicy& policy
Expand Down Expand Up @@ -1317,6 +1317,17 @@
);
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){
Expand All @@ -1328,17 +1339,20 @@

namespace{

class ConsoleBBQAutoBattleActions : public BBQAutoBattleActions{

Check warning on line 1342 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::ConsoleBBQAutoBattleActions: public_methods=7 (advisory above 5, limit 7)
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
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{
Expand Down Expand Up @@ -1385,6 +1399,10 @@
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);
Expand Down Expand Up @@ -1414,6 +1432,8 @@
LetsGoEncounterBotStats& m_stats;
LetsGoEncounterBotTracker& m_tracker;
LetsGoHpWatcher& m_hp_watcher;
const BBQOption& m_options;
BBQuests m_quest;
};

}
Expand Down Expand Up @@ -1449,7 +1469,7 @@
}
policy.heal_below_hp_percent = BBQ_OPTIONS.AUTO_BATTLE_HEAL_PERCENT;

ConsoleBBQAutoBattleActions actions(env, stream, context, stats, tracker, sensors.lets_go_hp);
ConsoleBBQAutoBattleActions actions(env, stream, context, stats, tracker, sensors.lets_go_hp, BBQ_OPTIONS, current_quest);
run_auto_battle(stream.logger(), actions, policy);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@

//The game steps of one Auto Battle pass. They are injected so that the loop's decisions (when
//to go again, when to stop) run in tests without a Switch.
class BBQAutoBattleActions{

Check warning on line 167 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::BBQAutoBattleActions: public_methods=7 (advisory above 5, limit 7)
public:
virtual ~BBQAutoBattleActions() = default;

Expand All @@ -185,6 +185,10 @@
//Fly back to Central Plaza. Leaving the cave respawns its Pokemon.
virtual void return_to_plaza() = 0;

//At Central Plaza, read the quest panel. Returns whether this quest is still on it: the game
//removes a quest once it is completed.
virtual bool quest_on_board() = 0;

//Walk to the nurse and heal, then fly to the Central Plaza fly point again: the flight to
//Chargestone moves the map cursor from there.
virtual void heal() = 0;
Expand All @@ -198,13 +202,17 @@
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;
//After a pass that ends this close to the target, read the board before going again, and
//stop if the quest is gone. 0 never reads it.
uint64_t check_board_within_kills = 2;
};

//Why run_auto_battle() returned.
enum class BBQAutoBattleResult{
TargetReached,
NoKills, //max_empty_passes passes in a row had no kill.
TimeLimit,
QuestDone, //The quest left the board before the heard kills reached the target.
};

//Clear Chargestone Cavern, one pass at a time, until the kills reach the target, and return why
Expand Down
Loading