Skip to content
Merged
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 @@ -10,14 +10,13 @@
#include "PokemonFRLG_Panels.h"

#include "PokemonFRLG_Settings.h"

#include "Programs/BoxOrganization/PokemonFRLG_BoxSorter.h"
#include "Programs/Farming/PokemonFRLG_EliteFourFarmer.h"
#include "Programs/Farming/PokemonFRLG_HeldItemFarmer-SafariZone.h"
#include "Programs/Farming/PokemonFRLG_ItemDuplication.h"
#include "Programs/Farming/PokemonFRLG_NuggetBridgeFarmer.h"
#include "Programs/Farming/PokemonFRLG_PickupFarmer.h"
#include "Programs/Farming/PokemonFRLG_EvTrainer.h"

#include "Programs/ShinyHunting/PokemonFRLG_GiftReset.h"
#include "Programs/ShinyHunting/PokemonFRLG_LegendaryReset.h"
#include "Programs/ShinyHunting/PokemonFRLG_LegendaryRunAway.h"
Expand Down Expand Up @@ -91,7 +90,8 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
ret.emplace_back(make_SingleSwitchProgram<EggRng>());

if (IS_BETA_VERSION || STATIC_GLOBALS.DEVELOPER_MODE){
// ret.emplace_back("---- Untested/Beta/WIP ----");
ret.emplace_back("---- Untested/Beta/WIP ----");
ret.emplace_back(make_SingleSwitchProgram<BoxSorter>());
}

if (STATIC_GLOBALS.DEVELOPER_MODE){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "Pokemon/Pokemon_BoxCursor.h"
#include "Pokemon/Pokemon_CollectedPokemonInfo.h"
#include "VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_BoxSelectionModeDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* Box Sorter
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <algorithm>
#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonTools/StartupChecks/StartProgramChecks.h"
#include "Pokemon/Pokemon_CollectedPokemonInfo.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonFRLG_BoxOrganization.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h"
#include "PokemonFRLG_BoxSorter.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

using namespace Pokemon;

namespace{

constexpr uint16_t MAX_BOXES = 14;

}

BoxSorter_Descriptor::BoxSorter_Descriptor()
: SingleSwitchProgramDescriptor(
"PokemonFRLG:BoxSorter",
Pokemon::STRING_POKEMON + " FRLG", "Box Sorter",
"Programs/PokemonFRLG/BoxSorter.html",
"Sort boxes of " + STRING_POKEMON + ". Start in Move " + STRING_POKEMON +
" with an empty hand in the first box to sort. Uses English species names.",
PanelQualityStanding::OFFICIAL_BETA,
ProgramControllerClass::StandardController_NoRestrictions,
FeedbackType::REQUIRED,
AllowCommandsWhenRunning::DISABLE_COMMANDS
)
{}


std::unique_ptr<StatsTracker> BoxSorter_Descriptor::make_stats() const{
return std::unique_ptr<StatsTracker>(new Stats());
}

BoxSorter::BoxSorter()
: NUM_BOXES(
"<b>Number of Boxes to Sort:</b><br>Starting with the current box and continuing to the right.",
LockMode::LOCK_WHILE_RUNNING, 1, 1, MAX_BOXES
)
, SORT_TABLE(
"<b>Sort Order Rules:</b><br>Sort order rules will be applied top to bottom.",
{SortingRuleType::DexNo, SortingRuleType::Level, SortingRuleType::Gender, SortingRuleType::Shiny}
)
, DRY_RUN(
"<b>Dry Run:</b><br>Scan boxes and write frlg-box_order.json and "
"frlg-box_order-sorted.json without moving any " + STRING_POKEMON + ".",
LockMode::LOCK_WHILE_RUNNING, false
)
, NOTIFICATIONS({&NOTIFICATION_PROGRAM_FINISH, &NOTIFICATION_ERROR_FATAL})
{
PA_ADD_OPTION(NUM_BOXES);
PA_ADD_OPTION(SORT_TABLE);
PA_ADD_OPTION(DRY_RUN);
PA_ADD_OPTION(NOTIFICATIONS);
}

void BoxSorter::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
home_black_border_check(env.console, context);

const std::vector<SortingRule> preferences = SORT_TABLE.preferences();
if (preferences.empty()){
throw UserSetupError(env.console, "Select at least one sorting rule.");
}

auto& stats = env.current_stats<BoxSorter_Descriptor::Stats>();
BoxOrganizationScan scan = scan_box_data(env, context, preferences, (uint16_t)NUM_BOXES);
const auto& boxes_data = scan.boxes_data;

// Stable ordering avoids unnecessary moves for Pokemon with identical sort keys.
auto boxes_sorted = boxes_data;
std::stable_sort(boxes_sorted.begin(), boxes_sorted.end());
const BoxSortingPlan plan = make_box_sorting_plan(boxes_data, boxes_sorted);
stats.compares += plan.compares;
env.update_stats();
save_boxes_data_to_json(boxes_data, "frlg-box_order.json");
save_boxes_data_to_json(boxes_sorted, "frlg-box_order-sorted.json");
env.log("Saved current and sorted box catalogues.");

if (DRY_RUN){
env.log("Dry run complete.");
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
return;
}

env.log("Start sorting...");
execute_box_sorting_plan(env, context, plan, scan.cursor, scan.mode);

send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Box Sorter
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonFRLG_BoxSorter_H
#define PokemonAutomation_PokemonFRLG_BoxSorter_H

#include <cstdint>
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "Pokemon/Options/Pokemon_BoxSortingTable.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

struct BoxOrganizationStats;

class BoxSorter_Descriptor : public SingleSwitchProgramDescriptor{
public:
BoxSorter_Descriptor();

using Stats = BoxOrganizationStats;
virtual std::unique_ptr<StatsTracker> make_stats() const override;
};


class BoxSorter : public SingleSwitchProgramInstance{
public:
using Descriptor = BoxSorter_Descriptor;
BoxSorter();

virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
virtual void start_program_border_check(VideoStream&, FeedbackType) override{}


private:
SimpleIntegerOption<uint16_t> NUM_BOXES;
Pokemon::BoxSortingTable SORT_TABLE;
BooleanCheckBoxOption DRY_RUN;
EventNotificationsOption NOTIFICATIONS;
};


}
}
}
#endif
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,8 @@ file(GLOB LIBRARY_SOURCES
Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.h
Source/VideoGames/PokemonFRLG/Programs/BoxOrganization/PokemonFRLG_BoxOrganization.cpp
Source/VideoGames/PokemonFRLG/Programs/BoxOrganization/PokemonFRLG_BoxOrganization.h
Source/VideoGames/PokemonFRLG/Programs/BoxOrganization/PokemonFRLG_BoxSorter.cpp
Source/VideoGames/PokemonFRLG/Programs/BoxOrganization/PokemonFRLG_BoxSorter.h
Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.cpp
Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.h
Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EvTrainer.cpp
Expand Down
Loading