Skip to content
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=92, limit=50, allowed 81
: GroupOption("Blueberry Quests", LockMode::UNLOCK_WHILE_RUNNING)
, m_language_owner(language_option == nullptr
? new OCR::LanguageOCROption(
Expand Down Expand Up @@ -190,6 +190,16 @@
"<b>Number of Retries:</b><br>Reattempt a quest this many times if it fails.",
LockMode::UNLOCK_WHILE_RUNNING, 1, 0, 5
)
, OUT_OF_RETRIES(
"<b>Out of Retries:</b><br>When a quest fails all its retries, do the selected option.",
{
{OutOfRetries::Skip, "skip", "Skip Quest - Not attempted again while it stays on the panel"},
{OutOfRetries::Reroll, "reroll", "Reroll Quest - Costs BP"},
{OutOfRetries::Stop, "stop", "Stop Program"},
},
LockMode::UNLOCK_WHILE_RUNNING,
OutOfRetries::Skip
)
, FIX_TIME_WHEN_DONE(
"<b>Fix Time when Done:</b><br>Fix the time after the program finishes.",
LockMode::UNLOCK_WHILE_RUNNING, false
Expand All @@ -210,6 +220,7 @@
PA_ADD_OPTION(BATTLE_AI);
PA_ADD_OPTION(CATCH_ON_WIN);
PA_ADD_OPTION(NUM_RETRIES);
PA_ADD_OPTION(OUT_OF_RETRIES);
PA_ADD_OPTION(FIX_TIME_WHEN_DONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class BBQOption : public GroupOption{
KeepGoing,
};

enum class OutOfRetries{
Skip,
Reroll,
Stop,
};

OCR::LanguageOCROption& LANGUAGE;

SimpleIntegerOption<uint64_t> NUM_QUESTS;
Expand All @@ -98,6 +104,7 @@ class BBQOption : public GroupOption{
TeraFarmerCatchOnWin CATCH_ON_WIN;

SimpleIntegerOption<uint8_t> NUM_RETRIES;
EnumDropdownOption<OutOfRetries> OUT_OF_RETRIES;

BooleanCheckBoxOption FIX_TIME_WHEN_DONE;

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

}

void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game){

Check failure on line 135 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::run_bbq_rounds( Logger & logger , const BBQOption & options , BBQGameActions & game): nesting=5, limit=4, allowed 4

Check failure on line 135 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::run_bbq_rounds( Logger & logger , const BBQOption & options , BBQGameActions & game): function_lines=96, limit=50, allowed 85
if (!exclusions_leave_a_blue_quest(options)){
throw UserSetupError(logger, "The quest exclusions table skips or rerolls every blue quest the program can do.");
}
Expand Down Expand Up @@ -199,7 +199,18 @@
num_completed_quests++;
}else{
logger.log("Quest did not complete successfully.");
failed_quests.insert(current_quest);
switch (options.OUT_OF_RETRIES){
case BBQOption::OutOfRetries::Skip:
failed_quests.insert(current_quest);
break;
case BBQOption::OutOfRetries::Reroll:
logger.log("Reroll selected. Rerolling the failed quest.");
game.reroll_quest(current_quest);
break;
case BBQOption::OutOfRetries::Stop:
logger.log("Stop selected. Stopping program.", COLOR_RED);
return;
}
}
}else{
//Note: This doesn't account for case such as "sneak up" being added and then completed alongside the next quest
Expand All @@ -221,7 +232,7 @@

namespace{

class BBQSoloFarmerGameActions : public BBQGameActions{

Check warning on line 235 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::BBQSoloFarmerGameActions: public_methods=6 (advisory above 5, limit 7)
public:
BBQSoloFarmerGameActions(
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
Expand All @@ -244,6 +255,15 @@
virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) override{
return process_and_do_quest(m_env, m_env.console, m_context, m_options, quest, eggs_hatched);
}
virtual void reroll_quest(BBQuests quest) override{
std::vector<BBQuests> quests = PokemonSV::read_quests(m_env.program_info(), m_env.console, m_context, m_options);
auto iter = std::find(quests.begin(), quests.end(), quest);
if (iter == quests.end()){
m_env.log("Failed quest is no longer on the panel. Not rerolling.");
return;
}
reroll_quest_slot(m_env.program_info(), m_env.console, m_context, m_options, quests, iter - quests.begin());
}
virtual void quest_completed() override{
m_stats.questsCompleted++;
m_env.update_stats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// that the round loop (which quests to attempt, which ones count, when to
// stop, when to save) runs in tests without a Switch: BBQSoloFarmer performs
// them on the console, and tests replace them with scripted results.
class BBQGameActions{

Check warning on line 27 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

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

Expand All @@ -43,6 +43,10 @@
// Increments `eggs_hatched` when the quest hatches eggs.
virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) = 0;

// Reroll a quest that failed all its attempts, if it is still on the
// panel. Spends BP.
virtual void reroll_quest(BBQuests quest) = 0;

// Progress reporting only: a quest was counted as completed. Lets stats
// update after every quest instead of once per round.
virtual void quest_completed() = 0;
Expand All @@ -55,7 +59,8 @@

// Run rounds of quests until NUM_QUESTS have been completed, or until
// eggs run out when OUT_OF_EGGS is Stop, or until every doable quest on the
// panel is one that already failed all its attempts.
// panel is one that already failed all its attempts, or until a quest fails
// all its attempts when OUT_OF_RETRIES is Stop.
// Throws UserSetupError if the exclusions leave no blue quest to do, or if
// the panel shows nothing doable for many reads in a row.
void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game);
Expand Down
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=905 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -142,7 +142,7 @@
// With out_of_bp, rerolls do nothing, as in the game when BP runs out.
// A run that reads the panel more than max_reads times is stuck: the read
// throws, and the test records "stuck".
class SimulatedBBQGameActions : public BBQGameActions{

Check warning on line 145 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::SimulatedBBQGameActions: public_methods=6 (advisory above 5, limit 7)
public:
std::vector<BBQuests> panel;
// Each attempt returns the next outcome; once exhausted, attempts succeed.
Expand Down Expand Up @@ -202,6 +202,13 @@
}
return success;
}
virtual void reroll_quest(BBQuests quest) override{
events.push_back("reroll");
auto iter = std::find(panel.begin(), panel.end(), quest);
if (iter != panel.end()){
*iter = next_new_quest();
}
}
virtual void quest_completed() override{
events.push_back("completed");
}
Expand Down Expand Up @@ -255,6 +262,7 @@
size_t max_reads = 1000;
std::vector<BBQuests> new_quests = {};
std::vector<std::pair<BBQuests, BBQAction>> exclusions = {};
BBQOption::OutOfRetries out_of_retries = BBQOption::OutOfRetries::Skip;
uint64_t expected_completed = 0;
std::string expected;
};
Expand All @@ -266,7 +274,7 @@
, m_scenario(std::move(scenario))
{}

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

Check warning on line 277 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_BBQFarmerRounds::run( Logger & , CancellableScope &) const: function_lines=46 (advisory above 25, limit 50)
BBQOption options;
options.NUM_QUESTS.set(m_scenario.num_quests);
options.SAVE_NUM_QUESTS.set(m_scenario.save_num_quests);
Expand All @@ -280,6 +288,7 @@
row->action.set(action);
options.QUEST_EXCLUSIONS.append_row(std::move(row));
}
options.OUT_OF_RETRIES.set(m_scenario.out_of_retries);

SimulatedBBQGameActions game;
game.panel = m_scenario.panel;
Expand Down Expand Up @@ -327,7 +336,7 @@
return ret;
}

static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){

Check failure on line 339 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_BBQFarmerRounds( UnitTestDatabase & database): function_lines=181, limit=50, allowed 162
const std::string round_of_3 = "read process read do completed read do completed read do completed";
std::string read_30_times;
for (int c = 0; c < 30; c++){
Expand Down Expand Up @@ -427,14 +436,15 @@
{
// Round 1 completes nothing. It must not save, even though the
// count (0) is a multiple of the interval.
// Every quest fails, so nothing doable is left and the farmer
// stops, but the round with no completions doesn't save.
// Every quest fails and is rerolled, so round 1 completes
// nothing and doesn't save; round 2 reaches the milestone.
.name = "round without completions does not save",
.num_quests = 3,
.save_num_quests = 2,
.outcomes = {false, false, false},
.expected_completed = 0,
.expected = "read process read do read do read do end read process",
.out_of_retries = BBQOption::OutOfRetries::Reroll,
.expected_completed = 3,
.expected = "read process read do reroll read do reroll read do reroll end " + round_of_3 + " end(save)",
},
{
// sneak-up fails, then leaves the panel along with make-tm. Round 2
Expand Down Expand Up @@ -484,6 +494,24 @@
.expected_completed = 3,
.expected = round_of_3 + " end",
},
{
// sneak-up is rerolled to photo-polar, which round 2 attempts.
.name = "out of retries with reroll replaces the failed quest",
.num_quests = 3,
.never_completes = {BBQuests::sneak_up},
.out_of_retries = BBQOption::OutOfRetries::Reroll,
.expected_completed = 5,
.expected = "read process read do completed read do completed read do reroll end " + round_of_3 + " end",
},
{
.name = "out of retries with stop stops at once",
.num_quests = 3,
.panel = {BBQuests::sneak_up, BBQuests::make_tm, BBQuests::auto_10},
.never_completes = {BBQuests::sneak_up},
.out_of_retries = BBQOption::OutOfRetries::Stop,
.expected_completed = 0,
.expected = "read process read do",
},
};
for (const BBQRoundsScenario& scenario : scenarios){
database.add<Test_BBQFarmerRounds>(scenario);
Expand Down
Loading