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 @@ -123,6 +123,17 @@
// language is wrong so no quest is read, or there is no BP left to reroll.
const size_t MAX_READS_WITHOUT_DOABLE_QUEST = 30;

}

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

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace

// Quests done at Central Plaza with no flight out: they start at its fly
// point and fly back to it, so the player is where the round actions and the
// next quest expect. Every other route flies to another plaza or area.
bool bbq_quest_is_no_trip(BBQuests quest){
return quest == BBQuests::make_tm || quest == BBQuests::travel_500;
}

namespace{

// Whether a round that took the completed count from previous_completed
// to completed crossed a nonzero multiple of the save interval.
bool bbq_save_due(uint64_t previous_completed, uint64_t completed, uint64_t interval){
Expand All @@ -132,7 +143,7 @@

}

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

Check failure on line 146 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=162, limit=50, allowed 139
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 @@ -208,23 +219,37 @@
const uint64_t completed_before_round = num_completed_quests;
bool replan_after_reroll = false;
std::optional<std::vector<BBQuests>> rerolled_panel;
//The panel read that checked a completed no-trip quest. Nothing runs
//between it and the next dispatch or plan, so a no-trip quest next or
//the next plan starts from it instead of reading again.
std::optional<std::vector<BBQuests>> no_trip_panel;
for (auto current_quest : quests_to_do){
//Check if quest was already completed (ex. 500 meters completed while navigating to take a photo)
if (dispatch_panel){
logger.log("Reusing verified quest panel for first dispatch.");
quest_list = std::move(*dispatch_panel);
dispatch_panel.reset();
}else if (no_trip_panel && bbq_quest_is_no_trip(current_quest)){
logger.log("Reusing quest panel read after a no-trip quest for dispatch.");
quest_list = std::move(*no_trip_panel);
no_trip_panel.reset();
forget_quests_gone_from_panel(failed_quests, quest_list);
}else{
no_trip_panel.reset();
logger.log("Reading quest panel before dispatch.");
quest_list = read_panel();
}
if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){
logger.log("Current quest exists on list. Doing quest.");
bool questSuccess = game.do_quest(current_quest, eggs_hatched);
std::vector<BBQuests> panel_after;
bool questSuccess = game.do_quest(current_quest, eggs_hatched, panel_after);
if (questSuccess){
logger.log("Quest completed successfully.");
game.quest_completed();
num_completed_quests++;
if (bbq_quest_is_no_trip(current_quest)){
no_trip_panel = std::move(panel_after);
}
}else{
logger.log("Quest did not complete successfully.");
switch (options.OUT_OF_RETRIES){
Expand Down Expand Up @@ -261,6 +286,15 @@
uint64_t temp_save_num_option = options.SAVE_NUM_QUESTS;
// A round can cross a milestone without ending at an exact multiple.
const bool save = bbq_save_due(completed_before_round, num_completed_quests, temp_save_num_option);

//A no-trip quest ended the round at Central Plaza, and fixing the date
//does not change the quests, so plan the next quests from its read
//at once. Round actions still run before a save or the last stop.
if (no_trip_panel && !save && num_completed_quests < options.NUM_QUESTS){
logger.log("Chaining after a no-trip quest. Skipping round actions.");
observed_panel = std::move(no_trip_panel);
continue;
}
game.end_round(save);

//The reroll was the last game action of the round. Fixing the date
Expand Down Expand Up @@ -295,8 +329,8 @@
) override{
return PokemonSV::process_quest_list(m_env.program_info(), m_env.console, m_context, m_options, quests, eggs_hatched);
}
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 bool do_quest(BBQuests quest, uint8_t& eggs_hatched, std::vector<BBQuests>& panel_after) override{
return process_and_do_quest(m_env, m_env.console, m_context, m_options, quest, eggs_hatched, &panel_after);
}
virtual std::optional<std::vector<BBQuests>> reroll_quest(BBQuests quest) override{
std::vector<BBQuests> quests = PokemonSV::read_quests(m_env.program_info(), m_env.console, m_context, m_options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class BBQGameActions{

// Attempt one quest that is on the panel, after process_quest_list()
// chose it. Returns true if it is no longer on the panel afterwards.
// Increments `eggs_hatched` when the quest hatches eggs.
virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) = 0;
// Increments `eggs_hatched` when the quest hatches eggs. Sets
// `panel_after` to the quest panel read that checked the last attempt.
virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched, std::vector<BBQuests>& panel_after) = 0;

// Reroll a quest that failed all its attempts, if it is still on the
// panel. Spends BP. Returns the panel read to verify the reroll when
Expand All @@ -61,10 +62,16 @@ class BBQGameActions{
virtual void end_round(bool save) = 0;
};

// Whether a quest is done at Central Plaza with no flight out.
bool bbq_quest_is_no_trip(BBQuests quest);

// 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, or until a quest fails
// all its attempts when OUT_OF_RETRIES is Stop.
// all its attempts when OUT_OF_RETRIES is Stop. No-trip quests (see
// bbq_quest_is_no_trip()) are chained: the panel read that checked one is
// reused for a no-trip quest next or for the next plan, without the round
// actions between.
// 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 failure 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

<file>: file_lines=1206, limit=1000, allowed 1146
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -206,7 +206,7 @@
}
return {std::move(doable), std::nullopt};
}
virtual bool do_quest(BBQuests quest, uint8_t&) override{
virtual bool do_quest(BBQuests quest, uint8_t&, std::vector<BBQuests>& panel_after) override{
events.push_back("do");
attempted_quests.push_back(quest);
const bool success = !never_completes.contains(quest)
Expand All @@ -219,6 +219,7 @@
}
}
}
panel_after = panel;
return success;
}
virtual std::optional<std::vector<BBQuests>> reroll_quest(BBQuests quest) override{
Expand Down Expand Up @@ -380,7 +381,7 @@
return ret;
}

static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){

Check failure on line 384 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=340, limit=50, allowed 281
const std::string round_of_3 = "read process do completed read do completed read do completed";
std::string read_30_times;
for (int c = 0; c < 30; c++){
Expand Down Expand Up @@ -457,13 +458,13 @@
.reuse_rerolled_panel = true,
.expected_completed = 3,
.expected_attempted = {BBQuests::catch_fighting, BBQuests::travel_500, BBQuests::make_tm, BBQuests::photo_savanna},
.expected_reads = 3,
.expected = "read process do reroll end process process do completed read do completed read do completed end",
.expected_reads = 2,
.expected = "read process do reroll end process process do completed do completed read do completed end",
},
{
// As above, but neither reroll's read is reusable. Only the
// first dispatch skips a read: 2 reads before the next attempt
// instead of 3.
// instead of 3. make-tm starts from travel-500's read.
.name = "failed reroll then table reroll without reusable reads",
.num_quests = 1,
.panel = {BBQuests::catch_fighting, BBQuests::make_tm, BBQuests::photo_savanna},
Expand All @@ -473,8 +474,8 @@
.table_rerolls = {BBQuests::pickup_10},
.expected_completed = 3,
.expected_attempted = {BBQuests::catch_fighting, BBQuests::travel_500, BBQuests::make_tm, BBQuests::photo_savanna},
.expected_reads = 5,
.expected = "read process do reroll end read process read process do completed read do completed read do completed end",
.expected_reads = 4,
.expected = "read process do reroll end read process read process do completed do completed read do completed end",
},
{
// The save resets the game, so the reroll's read is not reused.
Expand Down Expand Up @@ -592,8 +593,9 @@
},
{
// sneak-up fails, then leaves the panel along with make-tm. Round 2
// reads a full panel without it, and its replacement for
// photo-canyon brings it back. Round 3 attempts it again.
// plans round 2 from a full panel without it (make-tm's read, no
// round actions), and its replacement for photo-canyon brings it
// back. Round 3 attempts it again.
.name = "failed quest that leaves a full panel is attempted again",
.num_quests = 5,
.panel = {BBQuests::sneak_up, BBQuests::make_tm, BBQuests::pickup_10, BBQuests::catch_flying},
Expand All @@ -602,8 +604,8 @@
.new_quests = {BBQuests::auto_10, BBQuests::photo_canyon, BBQuests::sneak_up},
.expected_completed = 5,
.expected =
"read process do read do completed end "
"read process do completed read do completed end "
"read process do read do completed "
"process do completed read do completed end "
"read process do completed read do completed end",
},
{
Expand All @@ -617,8 +619,8 @@
.new_quests = {BBQuests::auto_10, BBQuests::photo_canyon, BBQuests::sneak_up},
.expected_completed = 4,
.expected =
"read process do read do completed end "
"read process do completed read do completed end "
"read process do read do completed "
"process do completed read do completed end "
"read process do completed end",
},
{
Expand Down Expand Up @@ -656,6 +658,64 @@
.expected_completed = 0,
.expected = "read process do",
},
{
// make-tm ends round 1 back at Central Plaza: its read plans
// round 2 with no round actions between it and travel-500.
.name = "no-trip quests chain with no round actions between",
.num_quests = 5,
.panel = {BBQuests::auto_10, BBQuests::sneak_up, BBQuests::make_tm},
.new_quests = {BBQuests::travel_500, BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar},
.expected_completed = 6,
.expected_attempted = {
BBQuests::auto_10, BBQuests::sneak_up, BBQuests::make_tm,
BBQuests::travel_500, BBQuests::photo_canyon, BBQuests::photo_coastal,
},
.expected_reads = 5,
.expected =
"read process do completed read do completed read do completed "
"process do completed read do completed read do completed end",
},
{
// make-tm, travel-500 and photo-canyon on one board: only
// travel-500 starts from make-tm's read. The trip quest reads
// the panel and ends the round as usual.
.name = "no-trip then trip quest keeps the trip's usual steps",
.num_quests = 3,
.panel = {BBQuests::make_tm, BBQuests::travel_500, BBQuests::photo_canyon},
.new_quests = {BBQuests::photo_coastal, BBQuests::photo_polar, BBQuests::photo_savanna},
.expected_completed = 3,
.expected_reads = 2,
.expected = "read process do completed do completed read do completed end",
},
{
.name = "failed no-trip quest ends the round as usual",
.num_quests = 3,
.panel = {BBQuests::auto_10, BBQuests::sneak_up, BBQuests::make_tm},
.outcomes = {true, true, false},
.new_quests = {BBQuests::travel_500, BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar},
.expected_completed = 4,
.expected =
"read process do completed read do completed read do end "
"read process do completed read do completed end",
},
{
.name = "no-trip quest does not chain past a save",
.num_quests = 6,
.save_num_quests = 3,
.panel = {BBQuests::auto_10, BBQuests::sneak_up, BBQuests::make_tm},
.new_quests = {BBQuests::travel_500, BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar},
.expected_completed = 6,
.expected =
"read process do completed read do completed read do completed end(save) "
"read process do completed read do completed read do completed end(save)",
},
{
.name = "no-trip quest that reaches the goal ends the round",
.num_quests = 3,
.panel = {BBQuests::auto_10, BBQuests::sneak_up, BBQuests::make_tm},
.expected_completed = 3,
.expected = "read process do completed read do completed read do completed end",
},
};
for (const BBQRoundsScenario& scenario : scenarios){
database.add<Test_BBQFarmerRounds>(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=1479, limit=1000, allowed 1475
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -458,12 +458,13 @@
return {std::move(plan.to_do), std::nullopt};
}

bool process_and_do_quest(

Check failure on line 461 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::process_and_do_quest( ProgramEnvironment & env , ConsoleHandle & console , ProControllerContext & context , BBQOption & BBQ_OPTIONS , BBQuests current_quest , uint8_t & eggs_hatched , std :: vector<BBQuests> * panel_after): function_lines=136, limit=50, allowed 132
ProgramEnvironment& env,
ConsoleHandle& console, ProControllerContext& context,
BBQOption& BBQ_OPTIONS,
BBQuests current_quest,
uint8_t& eggs_hatched
uint8_t& eggs_hatched,
std::vector<BBQuests>* panel_after
){
bool quest_completed = false;
int quest_attempts = 0;
Expand Down Expand Up @@ -570,6 +571,9 @@
//Validate quest was completed by checking list
console.log("Reading quest panel after attempt.");
std::vector<BBQuests> quest_list = read_quests(env.program_info(), console, context, BBQ_OPTIONS);
if (panel_after){
*panel_after = quest_list;
}
if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){
console.log("Current quest exists on list. Quest did not complete.");
quest_attempts++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ BBQuestBatch process_quest_list(
);

//Take the current quest and calls the function to do it, then checks the quest was successful. Returns true if so.
//If panel_after is given, it receives the quest panel read that checked the last attempt.
bool process_and_do_quest(
ProgramEnvironment& env,
ConsoleHandle& console, ProControllerContext& context,
BBQOption& BBQ_OPTIONS,
BBQuests current_quest,
uint8_t& eggs_hatched
uint8_t& eggs_hatched,
std::vector<BBQuests>* panel_after = nullptr
);

//Iterate through TMs until a craftable one is found. Make the TM and return to position.
Expand Down
Loading