Skip to content

Commit

Permalink
Merge branch 'PokemonAutomation:main' into flyingtrailfarmer
Browse files Browse the repository at this point in the history
  • Loading branch information
NympheaR authored Jan 17, 2024
2 parents 8e15f98 + cab550b commit 83916a8
Show file tree
Hide file tree
Showing 25 changed files with 762 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cpp-ci-serial-programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
robocopy Packages/PABotBase/PABotBase-Switch Output/PABotBase /s
robocopy Arduino-Source/SerialPrograms/bin Output/Binaries dpp.dll libcrypto-1_1-x64.dll libsodium.dll libssl-1_1-x64.dll opencv_world460.dll opus.dll Sleepy.dll tesseractPA.dll zlib1.dll
robocopy Arduino-Source/SerialPrograms/bin/Release Output/Binaries SerialPrograms.exe
echo https://github.com/${{github.repository}}/commit/${{github.sha}} > Output/version.txt
write-host "Robocopy exited with exit code:" $lastexitcode
if ($lastexitcode -eq 1)
{
Expand Down
6 changes: 4 additions & 2 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,8 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h
Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp
Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.h
Source/PokemonSV/Programs/Farming/PokemonSV_WildItemFarmer.cpp
Source/PokemonSV/Programs/Farming/PokemonSV_WildItemFarmer.h
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_ClipboardFastCodeEntry.cpp
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_ClipboardFastCodeEntry.h
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_CodeEntry.cpp
Expand All @@ -1458,8 +1460,8 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Programs/General/PokemonSV_SizeChecker.h
Source/PokemonSV/Programs/General/PokemonSV_StatsReset.cpp
Source/PokemonSV/Programs/General/PokemonSV_StatsReset.h
Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.cpp
Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.h
Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.cpp
Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.h
Source/PokemonSV/Programs/Glitches/PokemonSV_CloneItems-1.0.1.cpp
Source/PokemonSV/Programs/Glitches/PokemonSV_CloneItems-1.0.1.h
Source/PokemonSV/Programs/Glitches/PokemonSV_RideCloner-1.0.1.cpp
Expand Down
6 changes: 4 additions & 2 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ SOURCES += \
Source/PokemonSV/Programs/Farming/PokemonSV_LPFarmer.cpp \
Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.cpp \
Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp \
Source/PokemonSV/Programs/Farming/PokemonSV_WildItemFarmer.cpp \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_ClipboardFastCodeEntry.cpp \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_CodeEntry.cpp \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_FastCodeEntry.cpp \
Expand All @@ -728,7 +729,7 @@ SOURCES += \
Source/PokemonSV/Programs/General/PokemonSV_MassPurchase.cpp \
Source/PokemonSV/Programs/General/PokemonSV_SizeChecker.cpp \
Source/PokemonSV/Programs/General/PokemonSV_StatsReset.cpp \
Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.cpp \
Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.cpp \
Source/PokemonSV/Programs/Glitches/PokemonSV_CloneItems-1.0.1.cpp \
Source/PokemonSV/Programs/Glitches/PokemonSV_RideCloner-1.0.1.cpp \
Source/PokemonSV/Programs/PokemonSV_AreaZero.cpp \
Expand Down Expand Up @@ -1775,6 +1776,7 @@ HEADERS += \
Source/PokemonSV/Programs/Farming/PokemonSV_LPFarmer.h \
Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h \
Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.h \
Source/PokemonSV/Programs/Farming/PokemonSV_WildItemFarmer.h \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_ClipboardFastCodeEntry.h \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_CodeEntry.h \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_FastCodeEntry.h \
Expand All @@ -1785,7 +1787,7 @@ HEADERS += \
Source/PokemonSV/Programs/General/PokemonSV_MassPurchase.h \
Source/PokemonSV/Programs/General/PokemonSV_SizeChecker.h \
Source/PokemonSV/Programs/General/PokemonSV_StatsReset.h \
Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.h \
Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.h \
Source/PokemonSV/Programs/Glitches/PokemonSV_CloneItems-1.0.1.h \
Source/PokemonSV/Programs/Glitches/PokemonSV_RideCloner-1.0.1.h \
Source/PokemonSV/Programs/PokemonSV_AreaZero.h \
Expand Down
4 changes: 2 additions & 2 deletions SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace PokemonAutomation{

const bool IS_BETA_VERSION = true;
const int PROGRAM_VERSION_MAJOR = 0;
const int PROGRAM_VERSION_MINOR = 45;
const int PROGRAM_VERSION_PATCH = 1;
const int PROGRAM_VERSION_MINOR = 46;
const int PROGRAM_VERSION_PATCH = 4;

const std::string PROGRAM_VERSION_BASE =
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ bool cluster_fit_2(
ratio_sum += count_ratio_desired[c];
center_actual[c] = cluster[c].center();
}
// cout << "---------------" << endl;
for (size_t c = 0; c < NUM_CLUSTERS; c++){
// cout << cluster[c].count() << ": " << cluster[c].center() << ", " << cluster[c].deviation() << endl;

Expand All @@ -152,12 +153,14 @@ bool cluster_fit_2(
}

if (center_desired[c].sum() < 50){
// cout << "Black" << endl;
double distance = euclidean_distance(center_desired[c], center_actual[c]) * count_ratio_desired[c];
if (distance > 40){
// cout << "Black Distance is Too Large: " << distance << endl;
return false;
}
}else{
// cout << "Not Black" << endl;
FloatPixel ratio_desired = center_desired[c] / center_desired[c].sum();
FloatPixel ratio_actual = center_actual[c] / center_actual[c].sum();
double distance = euclidean_distance(ratio_desired, ratio_actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool cluster_fit_2(
Color color1, double ratio1,
double ratio_threshold = 0.2,
double deviation_threshold = 50,
double distance_threshold = 0.2
double distance_threshold = 0.25
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const std::map<std::string, std::string> STATS_DATABASE_ALIASES{
{"Shiny Hunt Autonomous - Whistling", "PokemonSwSh:ShinyHuntAutonomousWhistling"},
{"Shiny Hunt Autonomous - Fishing", "PokemonSwSh:ShinyHuntAutonomousFishing"},
{"Shiny Hunt Autonomous - Overworld", "PokemonSwSh:ShinyHuntAutonomousOverworld"},
{"PokemonSV:StatsResetBloodmoon", "PokemonSV:StatsResetEventBattle"},
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,15 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco
using namespace Kernels;
using namespace NintendoSwitch;
// using namespace NintendoSwitch::PokemonSwSh;
using namespace NintendoSwitch::PokemonSV;
// using namespace NintendoSwitch::PokemonSV;
using namespace Pokemon;
// using namespace NintendoSwitch::PokemonSwSh::MaxLairInternal;
using namespace NintendoSwitch::PokemonSwSh::MaxLairInternal;


ImageRGB32 image("20231230-221510445509-ProgramHang.png");

BattleMenuDetector detector;
cout << detector.detect(image) << endl;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
// run_singles_battle(env, console, context, battle_AI, false);


VideoSnapshot screen = console.video().snapshot();

PokemonSummaryDetector summary;
cout << summary.detect(screen) << endl;


#if 0
ImageViewRGB32 box = extract_box_reference(screen, ImageFloatBox(0.28, 0.20, 0.03, 0.055));
ImageStats stats = image_stats(box);
cout << stats.average << stats.stddev << endl;

bool item_held = !is_solid(stats, {0.550405, 0.449595, 0.}, 0.20);
cout << "item_held = " << item_held << endl;
#endif

#if 0
run_pokemon(
console, context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct Pokemon{
bool gmax = false;
std::string ball_slug = "";
StatsHuntGenderFilter gender = StatsHuntGenderFilter::Genderless;
uint16_t ot_id = 0;
uint32_t ot_id = 0;
};

bool operator==(const Pokemon& lhs, const Pokemon& rhs){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,20 +540,48 @@ std::set<std::string> OutbreakFinder::enter_region_and_read_MMO(

pbf_mash_button(context, BUTTON_A, 350);
context.wait_for_all_requests();

// Wait for the last dialog box before the MMO pokemon sprites are revealed.
EventDialogDetector event_dialog_detector(env.logger(), env.console.overlay(), true);
int ret = wait_until(env.console, context, std::chrono::seconds(10), {{event_dialog_detector}});
if (ret < 0){
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, env.console,
"Dialog box not detected when waiting for MMO map.",
true
);
{
EventDialogDetector event_dialog_detector(env.logger(), env.console.overlay(), true);
int ret = wait_until(env.console, context, std::chrono::seconds(10), {{event_dialog_detector}});
if (ret < 0){
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, env.console,
"Dialog box not detected when waiting for MMO map.",
true
);
}
}

pbf_press_button(context, BUTTON_B, 50, 50);

while (true){
EventDialogDetector event_dialog_detector(env.logger(), env.console.overlay(), true);
MapDetector map_detector;
context.wait_for_all_requests();
int ret = wait_until(
env.console, context, std::chrono::seconds(10),
{event_dialog_detector, map_detector}
);
switch (ret){
case 0:
env.console.log("Detected dialog.");
pbf_press_button(context, BUTTON_B, 20, 105);
continue;
case 1:
env.console.log("Found revealed map thanks to Munchlax!");
break;
default:
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, env.console,
"Map not detected after talking to Mai.",
true
);
}
break;
}

#if 0
MapDetector map_detector;
ret = wait_until(env.console, context, std::chrono::seconds(5), {{map_detector}});
if (ret < 0){
Expand All @@ -564,6 +592,7 @@ std::set<std::string> OutbreakFinder::enter_region_and_read_MMO(
);
}
env.console.log("Found revealed map thanks to Munchlax!");
#endif

VideoOverlaySet mmo_sprites_overlay(env.console);
for (size_t i = 0; i < new_boxes.size(); i++){
Expand Down Expand Up @@ -609,7 +638,7 @@ std::set<std::string> OutbreakFinder::enter_region_and_read_MMO(
MMOSpriteStarSymbolDetector star_detector(sprites_screen, star_boxes);

env.log("Detect star symbols...");
ret = wait_until(env.console, context, std::chrono::seconds(5), {{star_detector}});
wait_until(env.console, context, std::chrono::seconds(5), {{star_detector}});
for (size_t i = 0; i < new_boxes.size(); i++){
std::ostringstream os;
os << "- " << sprites[i] << " box [" << star_boxes[i].min_x << ", " << star_boxes[i].min_y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool NormalBattleMenuDetector::move_to_slot(ConsoleHandle& console, BotBaseConte
context.wait_for(std::chrono::milliseconds(500));
continue;
// static int c = 0;
// screen->save("bad-" + std::to_string(c++) + ".png"); // REMOVE
// screen->save("bad-" + std::to_string(c++) + ".png");
// return false;
}
if (attempts > 10){
Expand All @@ -81,7 +81,7 @@ bool NormalBattleMenuDetector::move_to_slot(ConsoleHandle& console, BotBaseConte
switch (diff){
case 0:{
// static int c = 0;
// screen->save("good-" + std::to_string(c++) + ".png"); // REMOVE
// screen->save("good-" + std::to_string(c++) + ".png");
return true;
}
case 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ bool MainMenuDetector::move_cursor(
}
consecutive_detection_fails = 0;

if (moves >= 10){
console.log("Unable to move to target after 10 moves.", COLOR_RED);
if (moves >= 20){
console.log("Unable to move to target after 20 moves.", COLOR_RED);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace PokemonSV{


bool is_summary_color(const ImageStats& stats){
return is_solid(stats, {0.648549, 0.2861580, 0.0652928}, 0.15, 20) // Scarlet
|| is_solid(stats, {0.367816, 0.0746615, 0.5575230}, 0.15, 20) // Violet
|| is_solid(stats, {0.196536, 0.5933000, 0.2101630}, 0.18, 20) // DLC1 Green
|| is_solid(stats, {0.169492, 0.330508 , 0.5 }, 0.18, 20) // DLC2 Dark Blue
return is_solid(stats, {0.648549, 0.2861580, 0.0652928}, 0.15, 25) // Scarlet
|| is_solid(stats, {0.367816, 0.0746615, 0.5575230}, 0.15, 25) // Violet
|| is_solid(stats, {0.196536, 0.5933000, 0.2101630}, 0.18, 25) // DLC1 Green
|| is_solid(stats, {0.169492, 0.330508 , 0.5 }, 0.18, 25) // DLC2 Dark Blue
|| (stats.average.g / stats.average.sum()) > 0.5;
}

Expand Down Expand Up @@ -68,14 +68,17 @@ bool PokemonSummaryDetector::detect(const ImageViewRGB32& screen) const{
}
#else
if (!is_summary_color(bottom)){
// cout << "bad summary color" << endl;
return false;
}
#endif

if (!m_arrow_left.detect(screen)){
// cout << "bad arrow left" << endl;
return false;
}
if (!m_arrow_right.detect(screen)){
// cout << "bad arrow right" << endl;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using namespace Pokemon;



SinglesAIOption::~SinglesAIOption() = default;
SinglesAIOption::SinglesAIOption(bool trainer_battle)
: GroupOption(
"Battle AI",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace PokemonSV{

class SinglesAIOption : public GroupOption{
public:
~SinglesAIOption();
SinglesAIOption(bool trainer_battle);

public:
Expand Down
16 changes: 10 additions & 6 deletions SerialPrograms/Source/PokemonSV/PokemonSV_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Programs/Farming/PokemonSV_TournamentFarmer.h"
#include "Programs/Farming/PokemonSV_TournamentFarmer2.h"
#include "Programs/Farming/PokemonSV_FlyingTrialFarmer.h"
#include "Programs/Farming/PokemonSV_WildItemFarmer.h"

#include "Programs/Eggs/PokemonSV_EggFetcher.h"
#include "Programs/Eggs/PokemonSV_EggHatcher.h"
Expand All @@ -45,7 +46,7 @@
#include "Programs/FastCodeEntry/PokemonSV_VideoFastCodeEntry.h"

#include "Programs/General/PokemonSV_StatsReset.h"
#include "Programs/General/PokemonSV_StatsResetBloodmoon.h"
#include "Programs/General/PokemonSV_StatsResetEventBattle.h"

#include "Programs/ShinyHunting/PokemonSV_ShinyHunt-AreaZeroPlatform.h"
#include "Programs/ShinyHunting/PokemonSV_ShinyHunt-Scatterbug.h"
Expand Down Expand Up @@ -80,7 +81,9 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
ret.emplace_back(make_single_switch_program<ClothingBuyer_Descriptor, ClothingBuyer>());
ret.emplace_back(make_single_switch_program<AutonomousBallThrower_Descriptor, AutonomousBallThrower>());
ret.emplace_back(make_single_switch_program<SizeChecker_Descriptor, SizeChecker>());
ret.emplace_back(make_single_switch_program<AutoItemPrinter_Descriptor, AutoItemPrinter>());
if (IS_BETA_VERSION){
ret.emplace_back(make_single_switch_program<AutoItemPrinter_Descriptor, AutoItemPrinter>());
}

// ret.emplace_back("---- Trading ----");
ret.emplace_back(make_multi_switch_program<SelfBoxTrade_Descriptor, SelfBoxTrade>());
Expand All @@ -99,10 +102,11 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
ret.emplace_back(make_single_switch_program<AuctionFarmer_Descriptor, AuctionFarmer>());
ret.emplace_back(make_single_switch_program<ESPTraining_Descriptor, ESPTraining>());
ret.emplace_back(make_single_switch_program<TournamentFarmer_Descriptor, TournamentFarmer>());
if (PreloadSettings::instance().DEVELOPER_MODE){
ret.emplace_back(make_single_switch_program<TournamentFarmer2_Descriptor, TournamentFarmer2>());
}
ret.emplace_back(make_single_switch_program<TournamentFarmer2_Descriptor, TournamentFarmer2>());
ret.emplace_back(make_single_switch_program<FlyingTrialFarmer_Descriptor, FlyingTrialFarmer>());
if (IS_BETA_VERSION){
ret.emplace_back(make_single_switch_program<WildItemFarmer_Descriptor, WildItemFarmer>());
}

ret.emplace_back("---- Eggs ----");
ret.emplace_back(make_single_switch_program<EggFetcher_Descriptor, EggFetcher>());
Expand All @@ -122,7 +126,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{

ret.emplace_back("---- Stats Hunting ----");
ret.emplace_back(make_single_switch_program<StatsReset_Descriptor, StatsReset>());
ret.emplace_back(make_single_switch_program<StatsResetBloodmoon_Descriptor, StatsResetBloodmoon>());
ret.emplace_back(make_single_switch_program<StatsResetEventBattle_Descriptor, StatsResetEventBattle>());

ret.emplace_back("---- Shiny Hunting ----");
ret.emplace_back(make_single_switch_program<ShinyHuntAreaZeroPlatform_Descriptor, ShinyHuntAreaZeroPlatform>());
Expand Down
Loading

0 comments on commit 83916a8

Please sign in to comment.