Skip to content

Commit b615f1c

Browse files
committed
Improve reliability of BDSP trade programs.
1 parent d8239f7 commit b615f1c

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
//#include "PokemonSwSh/Inference/Battles/PokemonSwSh_BattleMenuDetector.h"
129129
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.h"
130130
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonSwapMenu.h"
131+
#include "PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h"
131132

132133

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

283+
284+
ImageRGB32 image("20250112-194339635973.png");
285+
286+
PokemonBDSP::SelectionArrowFinder detector0(console, {0.50, 0.58, 0.40, 0.10}, COLOR_RED);
287+
PokemonBDSP::SelectionArrowFinder detector1(console, {0.50, 0.52, 0.40, 0.10}, COLOR_RED);
288+
289+
cout << detector0.detect(image) << endl;
290+
cout << detector1.detect(image) << endl;
291+
292+
293+
294+
282295
#if 0
283296
PokemonSwSh::MaxLairInternal::PokemonSwapMenuReader reader(console, overlay, Language::English);
284297

@@ -341,7 +354,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
341354
);
342355
#endif
343356

344-
#if 1
357+
#if 0
345358
// VideoSnapshot image = feed.snapshot();
346359
ImageRGB32 image("20250108-151305644248.png");
347360

SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ SelectionArrowFinder::SelectionArrowFinder(
8383
, m_box(box)
8484
{}
8585

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

8989
m_arrow_boxes.clear();
9090
for (const ImagePixelBox& mark : arrows){
9191
m_arrow_boxes.emplace_back(m_overlay, translate_to_parent(screen, m_box, mark), COLOR_MAGENTA);
9292
}
93+
94+
return !m_arrow_boxes.empty();
9395
}
9496
void SelectionArrowFinder::make_overlays(VideoOverlaySet& items) const{
9597
items.add(m_color, m_box);

SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SelectionArrowFinder : public VisualInferenceCallback{
2424
Color color
2525
);
2626

27-
void detect(const ImageViewRGB32& screen);
27+
bool detect(const ImageViewRGB32& screen);
2828

2929
virtual void make_overlays(VideoOverlaySet& items) const override;
3030
virtual bool process_frame(const ImageViewRGB32& frame, WallClock timestamp) override;

SerialPrograms/Source/PokemonBDSP/Programs/Trading/PokemonBDSP_TradeRoutines.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@ void trade_current_pokemon(
4141
VideoSnapshot box_image = console.video().snapshot();
4242
ImageMatchWatcher box_detector(std::move(box_image.frame), {0.02, 0.10, 0.15, 0.80}, 50);
4343

44-
pbf_press_button(context, BUTTON_ZL, 20, 0);
44+
// pbf_press_button(context, BUTTON_ZL, 20, 0);
4545

46+
#if 0
4647
while (true){
4748
context.wait_for_all_requests();
4849
SelectionArrowFinder detector0(console, {0.50, 0.58, 0.40, 0.10}, COLOR_RED);
4950
SelectionArrowFinder detector1(console, {0.50, 0.52, 0.40, 0.10}, COLOR_RED);
50-
int ret = wait_until(
51-
console, context, std::chrono::seconds(20),
51+
int ret = run_until(
52+
console, context,
53+
[](BotBaseContext& context){
54+
pbf_mash_button(context, BUTTON_ZL, 20 * TICKS_PER_SECOND);
55+
},
5256
{detector0, detector1}
5357
);
54-
if (ret < 0){
55-
}
5658
switch (ret){
5759
case 0:
5860
console.log("Detected trade prompt.");
@@ -68,19 +70,23 @@ void trade_current_pokemon(
6870
break;
6971
default:
7072
stats.m_errors++;
71-
tracker.report_unrecoverable_error(console, "Failed to detect a prompt after 20 minutes.");
73+
tracker.report_unrecoverable_error(console, "Failed to detect a prompt after 20 seconds.");
7274
}
7375
break;
7476
}
77+
#endif
7578

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

7982
// Wait for black screen.
8083
{
8184
BlackScreenOverWatcher black_screen;
82-
int ret = wait_until(
83-
console, context, std::chrono::minutes(2),
85+
int ret = run_until(
86+
console, context,
87+
[](BotBaseContext& context){
88+
pbf_mash_button(context, BUTTON_ZL, 20 * TICKS_PER_SECOND);
89+
},
8490
{{black_screen}}
8591
);
8692
if (ret < 0){

0 commit comments

Comments
 (0)