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 @@ -15,7 +15,7 @@ const EnumDropdownDatabase<BBQuests>& BBQuests_database(){
static EnumDropdownDatabase<BBQuests> database{
{BBQuests::auto_10, "auto-10", "Defeat 10 wild Pokemon using Auto Battle!"},
{BBQuests::make_tm, "make-tm", "Make yourself a TM!"},
//{BBQuests::pickup_10, "pickup-10", "Pick up items on the ground 10 times!"},
{BBQuests::pickup_10, "pickup-10", "Pick up items on the ground 10 times!"},
{BBQuests::sneak_up, "sneak-up", "Successfully sneak up on 1 Pokemon and surprise them with a battle!"},
{BBQuests::photo_fly, "photo-fly", "Take a photo of a wild Pokemon in flight!"},
{BBQuests::photo_swim, "photo-swim", "Take a photo of a wild Pokemon that is swimming!"},
Expand Down Expand Up @@ -108,8 +108,9 @@ BBQuestTable::BBQuestTable()
"Exclude the quests in the table. If you want to skip a quest, select it below. "
"(Quests can be explicitly included, but this is not necessary.) "
"Do not exclude too many quests, as rerolling costs BP. "
"The program will automatically reroll all quests if none are possible, but will not handle being out of BP. "
"Does not include egg hatching or pickup quests, as eggs are handled in other options and pickup is not possible. ",
"If no quest is possible, the program rerolls one quest it cannot do, or all quests if there is none. "
"Quests the program cannot do, such as pickup, are never run, but can be rerolled or skipped here. "
"Does not include egg hatching, as eggs are handled in other options. ",
//"Duplicates of the same quest",
//duplicates will work in table order. might lead to weird behavior like rerolling and then marking a quest as complete.
//won't break the program though.
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=1032, limit=1000, allowed 1000
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -530,6 +530,7 @@
std::string name;
std::vector<BBQuests> quests;
std::vector<std::pair<BBQuests, BBQAction>> extra_exclusions = {};
std::optional<int> bp = 1000;
uint8_t num_eggs = 1;
uint8_t eggs_hatched = 0;
BBQOption::OOEggs out_of_eggs = BBQOption::OOEggs::Reroll;
Expand Down Expand Up @@ -572,7 +573,7 @@
}

NullLogger logger;
const BBQuestPlan plan = plan_quests(logger, options, m_scenario.quests, m_scenario.eggs_hatched);
const BBQuestPlan plan = plan_quests(logger, options, m_scenario.quests, m_scenario.eggs_hatched, m_scenario.bp);
if (plan.to_do != m_scenario.expected_to_do){
return "Expected quests to do: " + quests_to_string(m_scenario.expected_to_do)
+ "got: " + quests_to_string(plan.to_do);
Expand Down Expand Up @@ -715,7 +716,7 @@

}

static void add_tests_BBQuestPlan(UnitTestDatabase& database){

Check failure on line 719 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_BBQuestPlan( UnitTestDatabase & database): function_lines=196, limit=50, allowed 70
using enum BBQuests;
const BBQuestPlanScenario scenarios[] = {
{
Expand All @@ -724,15 +725,141 @@
.expected_to_do = {make_tm, sneak_up},
},
{
.name = "quests not possible are left out",
// Left alone, it would hold its slot until something else is
// rerolled. A blue reroll costs 10 BP.
.name = "a blue quest not possible is rerolled while others are doable",
.quests = {make_tm, catch_flying, sneak_up},
.expected_to_do = {make_tm, sneak_up},
.expected_reroll_slots = {1},
},
{
// An undetected quest is neither run nor rerolled.
.name = "a quest not possible is rerolled, an undetected one is not",
.quests = {pickup_10, make_tm, UnableToDetect},
.expected_to_do = {make_tm},
.expected_reroll_slots = {0},
},
{
// A red quest costs 50 BP to reroll, but pays 100-150 BP, and
// the next red quest cannot appear while it stays.
.name = "a red quest not possible is rerolled while the blues are doable",
.quests = {photo_flying, make_tm, sneak_up, travel_500},
.expected_to_do = {make_tm, sneak_up, travel_500},
.expected_reroll_slots = {0},
},
{
// The board that held 2 of 4 slots for 20 minutes.
.name = "a red and a blue quest not possible are both rerolled",
.quests = {photo_flying, make_tm, catch_flying, sneak_up},
.expected_to_do = {make_tm, sneak_up},
.expected_reroll_slots = {0, 2},
},
{
// There is no longer a single slot to fall back on: every quest
// not possible was rerolled already, so not every quest is.
.name = "nothing doable rerolls each quest not possible, not all",
.quests = {photo_flying, auto_10, pickup_10, catch_flying},
.expected_reroll_slots = {0, 2, 3},
},
{
.name = "a skip row keeps a red quest not possible",
.quests = {photo_flying, make_tm, catch_flying, sneak_up},
.extra_exclusions = {{photo_flying, BBQAction::skip}},
.expected_to_do = {make_tm, sneak_up},
.expected_reroll_slots = {2},
},
{
.name = "a run row keeps a blue quest not possible",
.quests = {photo_flying, make_tm, catch_flying, sneak_up},
.extra_exclusions = {{catch_flying, BBQAction::run}},
.expected_to_do = {make_tm, sneak_up},
.expected_reroll_slots = {0},
},
{
// A red reroll costs 50 BP, a blue one 10.
.name = "BP for a blue reroll but not a red one skips the red quest not possible",
.quests = {photo_flying, make_tm, catch_flying, sneak_up},
.bp = 49,
.expected_to_do = {make_tm, sneak_up},
.expected_reroll_slots = {2},
},
{
.name = "BP for exactly a red reroll rerolls it and skips the blue one",
.quests = {photo_flying, make_tm, catch_flying, sneak_up},
.bp = 55,
.expected_to_do = {make_tm, sneak_up},
.expected_reroll_slots = {0},
},
{
// Before, the reroll did not happen and the program stopped.
.name = "BP under a blue reroll skips quests not possible and runs the doable ones",
.quests = {photo_flying, make_tm, catch_flying, sneak_up},
.bp = 9,
.expected_to_do = {make_tm, sneak_up},
},
{
.name = "unknown BP skips quests not possible and runs the doable ones",
.quests = {photo_flying, make_tm, catch_flying, sneak_up},
.bp = std::nullopt,
.expected_to_do = {make_tm, sneak_up},
},
{
// A reroll row is paid for first.
.name = "BP left after a reroll row decides the quests not possible",
.quests = {make_tm, catch_flying, sneak_up, pickup_10},
.extra_exclusions = {{sneak_up, BBQAction::reroll}},
.bp = 25,
.expected_to_do = {make_tm},
.expected_reroll_slots = {1, 2},
},
{
// Nothing else changes the panel, so BP does not hold it back.
.name = "nothing doable rerolls each quest not possible whatever the BP",
.quests = {photo_flying, auto_10, catch_flying},
.bp = 0,
.expected_reroll_slots = {0, 2},
},
{
.name = "nothing doable and nothing not possible rerolls all",
.quests = {auto_10, sneak_up},
.extra_exclusions = {{sneak_up, BBQAction::skip}},
.expected_reroll_all = true,
},
{
// An undetected quest is not known to be impossible.
.name = "an undetected quest is not rerolled alone",
.quests = {UnableToDetect, auto_10},
.expected_reroll_all = true,
},
{
.name = "nothing doable rerolls all",
.name = "a skipped quest not possible is not rerolled",
.quests = {pickup_10, auto_10, catch_flying},
.extra_exclusions = {{pickup_10, BBQAction::skip}},
.expected_reroll_slots = {2},
},
{
// Only skipped quests left: nothing changes the panel otherwise.
.name = "skip rows on every quest not possible reroll all when nothing is doable",
.quests = {photo_flying, auto_10, catch_flying},
.extra_exclusions = {
{photo_flying, BBQAction::skip},
{catch_flying, BBQAction::skip},
},
.expected_reroll_all = true,
},
{
.name = "a reroll row rerolls a quest not possible",
.quests = {make_tm, sneak_up, pickup_10},
.extra_exclusions = {{pickup_10, BBQAction::reroll}},
.expected_to_do = {make_tm, sneak_up},
.expected_reroll_slots = {2},
},
{
.name = "a run row does not run a quest not possible",
.quests = {make_tm, pickup_10},
.extra_exclusions = {{pickup_10, BBQAction::run}},
.expected_to_do = {make_tm},
},
{
// The reroll replaces a quest, so the next read has something new.
.name = "a reroll row rerolls that slot",
Expand All @@ -746,7 +873,7 @@
.name = "a rerolled slot with nothing doable does not reroll all",
.quests = {pickup_10, sneak_up, auto_10},
.extra_exclusions = {{sneak_up, BBQAction::reroll}},
.expected_reroll_slots = {1},
.expected_reroll_slots = {0, 1},
},
{
// Each row for a quest applies, in table order.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* 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=1519, limit=1000, allowed 1452
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <algorithm>
#include<vector>
#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h"
#include "CommonFramework/Tools/ErrorDumper.h"
Expand Down Expand Up @@ -171,10 +172,11 @@
}

//Apply each exclusions table row for the quest, in table order. Returns false if no row is for it.
//A quest the program cannot do is never run, but can still be rerolled or skipped.
bool plan_from_exclusions(

Check warning on line 176 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::plan_from_exclusions( Logger & logger , const std :: vector<std::unique_ptr<BBQuestTableRow>> & exclusions_table , BBQuests quest , size_t slot , bool possible , BBQuestPlan & plan): function_lines=33 (advisory above 25, limit 50)
Logger& logger,
const std::vector<std::unique_ptr<BBQuestTableRow>>& exclusions_table,
BBQuests quest, size_t slot,
BBQuests quest, size_t slot, bool possible,
BBQuestPlan& plan
){
bool quest_in_table = false;
Expand All @@ -186,6 +188,10 @@
quest_in_table = true;
switch (row->action){
case BBQAction::run:
if (!possible){
logger.log("Run selected, but this quest is not possible. Skipping quest.");
break;
}
logger.log("Run selected. Adding quest to list.");
plan.to_do.push_back(quest);
break;
Expand Down Expand Up @@ -367,20 +373,28 @@
}
}

int reroll_cost(BBQuests quest){
return red_quests.contains(quest) ? 50 : 10;
}

BBQuestPlan plan_quests(

Check failure on line 380 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::plan_quests( Logger & logger , const BBQOption & BBQ_OPTIONS , const std :: vector<BBQuests> & quest_list , uint8_t eggs_hatched , std :: optional<int> bp): function_lines=79, limit=50, allowed 50
Logger& logger,
const BBQOption& BBQ_OPTIONS,
const std::vector<BBQuests>& quest_list,
uint8_t eggs_hatched
uint8_t eggs_hatched,
std::optional<int> bp
){
BBQuestPlan plan;
std::vector<std::unique_ptr<BBQuestTableRow>> exclusions_table = BBQ_OPTIONS.QUEST_EXCLUSIONS.copy_snapshot();

//Quests not possible and not in the table, in panel order. Rerolled below if BP allows.
std::vector<size_t> not_possible_slots;

logger.log("Processing quests.");
for (size_t slot = 0; slot < quest_list.size(); slot++){
const BBQuests n = quest_list[slot];
if (not_possible_quests.contains(n)){
logger.log("Quest not possible");
if (n == BBQuests::UnableToDetect){
logger.log("Quest not detected.");
continue;
}
//Check eggs remaining.
Expand All @@ -389,26 +403,79 @@
plan_out_of_eggs(logger, BBQ_OPTIONS, slot, plan);
continue;
}
if (!plan_from_exclusions(logger, exclusions_table, n, slot, plan)){
logger.log("Quest not in inclusion/exclusions table. Adding to list.");
plan.to_do.push_back(n);
const bool possible = !not_possible_quests.contains(n);
if (plan_from_exclusions(logger, exclusions_table, n, slot, possible, plan)){
continue;
}
if (!possible){
logger.log("Quest not possible.");
not_possible_slots.push_back(slot);
continue;
}
logger.log("Quest not in inclusion/exclusions table. Adding to list.");
plan.to_do.push_back(n);
}

if (plan.to_do.empty()){
//Nothing else to do: a quest not possible only changes by rerolling it.
for (size_t slot : not_possible_slots){
logger.log("No possible quests! Rerolling quest " + std::to_string(slot + 1) + ", which is not possible.");
plan.reroll_slots.push_back(slot);
}
}else{
//Left on the panel, a quest not possible holds a slot until something else is rerolled.
//A red quest costs 50 BP to reroll instead of 10, but pays 100-150 BP and keeps the
//next red quest from appearing, so it is rerolled too. Without the BP for it, it is
//skipped and the doable quests run, rather than stopping the program on a reroll
//that does not happen.
int budget = bp.value_or(0);
for (size_t slot : plan.reroll_slots){
budget -= reroll_cost(quest_list[slot]);
}
for (size_t slot : not_possible_slots){
const int cost = reroll_cost(quest_list[slot]);
if (!bp || budget < cost){
logger.log(
"Quest " + std::to_string(slot + 1) + " not possible, but BP (" +
(bp ? std::to_string(*bp) : "unknown") + ") does not cover its " +
std::to_string(cost) + " BP reroll. Skipping it."
);
continue;
}
logger.log("Quest " + std::to_string(slot + 1) + " not possible. Rerolling quest. New quest will be run in the next batch of quests.");
budget -= cost;
plan.reroll_slots.push_back(slot);
}
}
std::sort(plan.reroll_slots.begin(), plan.reroll_slots.end());

//Check that quests_to_do is not empty (after completing all quests on the list, be sure to erase it.
//Lag might be a problem in multi - look into making slots like menu-left navigation
plan.reroll_all = plan.reroll_slots.empty() && plan.to_do.empty();
if (plan.reroll_slots.empty() && plan.to_do.empty()){
plan.reroll_all = true;
}
return plan;
}

std::vector<BBQuests> process_quest_list(

Check warning on line 460 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::process_quest_list( const ProgramInfo & info , VideoStream & stream , ProControllerContext & context , const BBQOption & BBQ_OPTIONS , const std :: vector<BBQuests> & quest_list , uint8_t eggs_hatched): function_lines=45 (advisory above 25, limit 50)
const ProgramInfo& info,
VideoStream& stream, ProControllerContext& context,
const BBQOption& BBQ_OPTIONS,
const std::vector<BBQuests>& quest_list,
uint8_t eggs_hatched
){
BBQuestPlan plan = plan_quests(stream.logger(), BBQ_OPTIONS, quest_list, eggs_hatched);
//Read BP only when a quest not possible may be rerolled while others are doable.
std::optional<int> bp;
if (std::any_of(quest_list.begin(), quest_list.end(), [](BBQuests quest){
return quest != BBQuests::UnableToDetect && not_possible_quests.contains(quest);
})){
const int read = read_BP(info, stream, context);
if (read >= 0){
bp = read;
}
stream.log("BP: " + (bp ? std::to_string(*bp) : "unable to read"));
}
BBQuestPlan plan = plan_quests(stream.logger(), BBQ_OPTIONS, quest_list, eggs_hatched, bp);

//Each reroll updates the panel the next one checks against.
std::vector<BBQuests> panel = quest_list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,23 @@ struct BBQuestPlan{
std::vector<size_t> reroll_slots; //Slots to reroll, in panel order.
bool reroll_all = false; //Nothing to do and nothing rerolled: reroll every slot.
};
//BP it costs to reroll one quest: 50 for a red quest, 10 for a blue one.
int reroll_cost(BBQuests quest);
//Decide what to do with each quest from the options alone, without touching the game, so
//the decision can be tested. Quests not possible are left out. Out-of-egg hatch quests and
//quests set to reroll in the exclusions table are rerolled. A quest with several table rows
//gets the action of each row, in table order.
//the decision can be tested. Quests not possible are never run. Those not in the exclusions
//table are rerolled, red or blue, so they do not hold a slot, as long as BP (the balance
//read from the panel, if any) still covers their cost after the other planned rerolls; the
//rest are skipped, and the doable quests run. A table row for one decides instead.
//Out-of-egg hatch quests and quests set to reroll in the exclusions table are rerolled. A
//quest with several table rows gets the action of each row, in table order. With nothing to
//do, every quest not possible and not in the table is rerolled whatever the BP, or else
//every quest.
BBQuestPlan plan_quests(
Logger& logger,
const BBQOption& BBQ_OPTIONS,
const std::vector<BBQuests>& quest_list,
uint8_t eggs_hatched
uint8_t eggs_hatched,
std::optional<int> bp
);

//The steps of rerolling one quest on the quest panel. They are injected so that the reroll
Expand Down
Loading