Skip to content

Commit

Permalink
Improve reliability of BDSP trade programs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Jan 13, 2025
1 parent d8239f7 commit b615f1c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
//#include "PokemonSwSh/Inference/Battles/PokemonSwSh_BattleMenuDetector.h"
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.h"
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonSwapMenu.h"
#include "PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h"


#include <QPixmap>
Expand Down Expand Up @@ -279,6 +280,18 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
BotBaseContext context(scope, console.botbase());
VideoOverlaySet overlays(overlay);


ImageRGB32 image("20250112-194339635973.png");

PokemonBDSP::SelectionArrowFinder detector0(console, {0.50, 0.58, 0.40, 0.10}, COLOR_RED);
PokemonBDSP::SelectionArrowFinder detector1(console, {0.50, 0.52, 0.40, 0.10}, COLOR_RED);

cout << detector0.detect(image) << endl;
cout << detector1.detect(image) << endl;




#if 0
PokemonSwSh::MaxLairInternal::PokemonSwapMenuReader reader(console, overlay, Language::English);

Expand Down Expand Up @@ -341,7 +354,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
);
#endif

#if 1
#if 0
// VideoSnapshot image = feed.snapshot();
ImageRGB32 image("20250108-151305644248.png");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ SelectionArrowFinder::SelectionArrowFinder(
, m_box(box)
{}

void SelectionArrowFinder::detect(const ImageViewRGB32& screen){
bool SelectionArrowFinder::detect(const ImageViewRGB32& screen){
std::vector<ImagePixelBox> arrows = find_selection_arrows(extract_box_reference(screen, m_box));

m_arrow_boxes.clear();
for (const ImagePixelBox& mark : arrows){
m_arrow_boxes.emplace_back(m_overlay, translate_to_parent(screen, m_box, mark), COLOR_MAGENTA);
}

return !m_arrow_boxes.empty();
}
void SelectionArrowFinder::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_box);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SelectionArrowFinder : public VisualInferenceCallback{
Color color
);

void detect(const ImageViewRGB32& screen);
bool detect(const ImageViewRGB32& screen);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool process_frame(const ImageViewRGB32& frame, WallClock timestamp) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ void trade_current_pokemon(
VideoSnapshot box_image = console.video().snapshot();
ImageMatchWatcher box_detector(std::move(box_image.frame), {0.02, 0.10, 0.15, 0.80}, 50);

pbf_press_button(context, BUTTON_ZL, 20, 0);
// pbf_press_button(context, BUTTON_ZL, 20, 0);

#if 0
while (true){
context.wait_for_all_requests();
SelectionArrowFinder detector0(console, {0.50, 0.58, 0.40, 0.10}, COLOR_RED);
SelectionArrowFinder detector1(console, {0.50, 0.52, 0.40, 0.10}, COLOR_RED);
int ret = wait_until(
console, context, std::chrono::seconds(20),
int ret = run_until(
console, context,
[](BotBaseContext& context){
pbf_mash_button(context, BUTTON_ZL, 20 * TICKS_PER_SECOND);
},
{detector0, detector1}
);
if (ret < 0){
}
switch (ret){
case 0:
console.log("Detected trade prompt.");
Expand All @@ -68,19 +70,23 @@ void trade_current_pokemon(
break;
default:
stats.m_errors++;
tracker.report_unrecoverable_error(console, "Failed to detect a prompt after 20 minutes.");
tracker.report_unrecoverable_error(console, "Failed to detect a prompt after 20 seconds.");
}
break;
}
#endif

// Start trade.
// pbf_press_button(context, BUTTON_ZL, 20, 0);

// Wait for black screen.
{
BlackScreenOverWatcher black_screen;
int ret = wait_until(
console, context, std::chrono::minutes(2),
int ret = run_until(
console, context,
[](BotBaseContext& context){
pbf_mash_button(context, BUTTON_ZL, 20 * TICKS_PER_SECOND);
},
{{black_screen}}
);
if (ret < 0){
Expand Down

0 comments on commit b615f1c

Please sign in to comment.