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
42 changes: 41 additions & 1 deletion SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ class SimulatedBBQGameActions : public BBQGameActions{
};

std::vector<std::string> events;
// The quests do_quest() was called with, in order.
std::vector<BBQuests> attempted;

virtual std::vector<BBQuests> read_quests() override{
events.push_back("read");
Expand Down Expand Up @@ -453,6 +455,7 @@ class SimulatedBBQGameActions : public BBQGameActions{
}
virtual bool do_quest(BBQuests quest, uint8_t&) override{
events.push_back("do");
attempted.push_back(quest);
const bool success = !never_completes.contains(quest)
&& (m_next_outcome < outcomes.size() ? outcomes[m_next_outcome++] : true);
if (success){
Expand Down Expand Up @@ -525,6 +528,8 @@ struct BBQRoundsScenario{
BBQOption::OutOfRetries out_of_retries = BBQOption::OutOfRetries::Skip;
uint64_t expected_completed = 0;
std::string expected;
// Checked when not empty.
std::vector<BBQuests> expected_attempted = {};
};

class Test_BBQFarmerRounds : public UnitTest{
Expand Down Expand Up @@ -564,6 +569,10 @@ class Test_BBQFarmerRounds : public UnitTest{
if (actual != m_scenario.expected){
return "Expected: " + m_scenario.expected + "\nActual: " + actual;
}
if (!m_scenario.expected_attempted.empty() && game.attempted != m_scenario.expected_attempted){
return "Expected attempts: " + quests_to_string(m_scenario.expected_attempted)
+ "got: " + quests_to_string(game.attempted);
}
return true;
}

Expand All @@ -586,12 +595,43 @@ void add_tests_BBQFarmerRounds(UnitTestDatabase& database){
{
// Doing photo_swim also completes travel_500, so travel_500 is
// gone when the loop reads the panel before attempting it.
// make_tm runs first, as the cheapest.
.name = "quest already gone counts as completed",
.num_quests = 3,
.panel = {BBQuests::photo_swim, BBQuests::travel_500, BBQuests::make_tm},
.also_completes = {{BBQuests::photo_swim, BBQuests::travel_500}},
.expected_completed = 3,
.expected = "read process read do completed read completed read do completed end",
.expected = "read process read do completed read do completed read completed end",
.expected_attempted = {BBQuests::make_tm, BBQuests::photo_swim},
},
{
// Expected seconds per completion: make-tm 79, travel-500 89,
// auto-10 280.
.name = "doable quests run cheapest first",
.num_quests = 3,
.panel = {BBQuests::auto_10, BBQuests::travel_500, BBQuests::make_tm},
.expected_completed = 3,
.expected = round_of_3 + " end",
.expected_attempted = {BBQuests::make_tm, BBQuests::travel_500, BBQuests::auto_10},
},
{
// photo-swim 63 s at 71% (89 s), typed catch 137 s at 75%
// (183 s), tera-self 153 s at 59% (259 s).
.name = "success rate counts in the order",
.num_quests = 3,
.panel = {BBQuests::tera_self_defeat, BBQuests::catch_fire, BBQuests::photo_swim},
.expected_completed = 3,
.expected = round_of_3 + " end",
.expected_attempted = {BBQuests::photo_swim, BBQuests::catch_fire, BBQuests::tera_self_defeat},
},
{
// sneak_up has no measurement, so it stays in slot 2.
.name = "unmeasured quests keep their place",
.num_quests = 3,
.panel = {BBQuests::auto_10, BBQuests::sneak_up, BBQuests::make_tm},
.expected_completed = 3,
.expected = round_of_3 + " end",
.expected_attempted = {BBQuests::make_tm, BBQuests::sneak_up, BBQuests::auto_10},
},
{
// The first attempt fails: 3 attempts, 2 completions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga
quest_list.clear();
}

//Cheap, reliable quests first: a quest done early can also finish a later one (e.g.
//travel-500 while flying to a photo target), and a failure costs less of the round.
order_quests_by_cost(logger, quests_to_do);

for (auto current_quest : quests_to_do){
//Check if quest was already completed (ex. 500 meters completed while navigating to take a photo)
quest_list = read_panel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h"
#include "PokemonSV_BlueberryQuests.h"

#include <algorithm>
#include<vector>

namespace PokemonAutomation{
Expand Down Expand Up @@ -460,6 +461,68 @@ void reroll_quest_slot(
}
}

std::optional<double> expected_seconds_per_success(BBQuests quest){
switch (quest){
case BBQuests::make_tm: return 79;
case BBQuests::travel_500: return 89;
case BBQuests::photo_swim: return 63 / 0.71;
case BBQuests::hatch_egg: return 190;
case BBQuests::tera_self_defeat: return 153 / 0.59;
case BBQuests::auto_10: return 280;
case BBQuests::sandwich_three:
case BBQuests::bitter_sandwich:
case BBQuests::sweet_sandwich:
case BBQuests::salty_sandwich:
case BBQuests::sour_sandwich:
case BBQuests::spicy_sandwich:
return 200;
case BBQuests::catch_normal:
case BBQuests::catch_fighting:
case BBQuests::catch_flying:
case BBQuests::catch_poison:
case BBQuests::catch_ground:
case BBQuests::catch_rock:
case BBQuests::catch_bug:
case BBQuests::catch_ghost:
case BBQuests::catch_steel:
case BBQuests::catch_fire:
case BBQuests::catch_water:
case BBQuests::catch_grass:
case BBQuests::catch_electric:
case BBQuests::catch_psychic:
case BBQuests::catch_ice:
case BBQuests::catch_dragon:
case BBQuests::catch_dark:
case BBQuests::catch_fairy:
return 137 / 0.75;
default:
return std::nullopt;
}
}

void order_quests_by_cost(Logger& logger, std::vector<BBQuests>& quests){
//Only the measured quests move, among the places they hold.
std::vector<size_t> places;
std::vector<BBQuests> measured;
for (size_t i = 0; i < quests.size(); i++){
if (expected_seconds_per_success(quests[i])){
places.push_back(i);
measured.push_back(quests[i]);
}
}
std::stable_sort(measured.begin(), measured.end(), [](BBQuests a, BBQuests b){
return *expected_seconds_per_success(a) < *expected_seconds_per_success(b);
});
bool changed = false;
for (size_t i = 0; i < places.size(); i++){
changed |= quests[places[i]] != measured[i];
quests[places[i]] = measured[i];
}
if (changed){
logger.log("Running the quests with the lowest expected time per completion first.");
}
}

BBQuestPlan plan_quests(
Logger& logger,
const BBQOption& BBQ_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ BBQuestPlan plan_quests(
uint8_t eggs_hatched
);

//Expected seconds per completed quest (time per attempt / success rate), measured in lab
//runs R3-R5, or nothing for a quest that was not measured.
std::optional<double> expected_seconds_per_success(BBQuests quest);
//Reorder quests so the cheapest by expected_seconds_per_success() run first. Quests that
//were not measured keep their places; ties keep their order.
void order_quests_by_cost(Logger& logger, std::vector<BBQuests>& quests);

//The steps of rerolling one quest on the quest panel. They are injected so that the reroll
//(which quest it pays for, when it gives up) runs in tests without a Switch.
class BBQRerollActions{
Expand Down
Loading