Skip to content

Commit 9c44282

Browse files
committed
Fix AutoDA Path Select false positives. Minor cleanup.
1 parent f0341fd commit 9c44282

File tree

7 files changed

+87
-70
lines changed

7 files changed

+87
-70
lines changed

SerialPrograms/Source/CommonTools/InferenceCallbacks/InferenceCallback.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ enum class InferenceType{
1717
AUDIO,
1818
};
1919

20-
// Base class for an inference object to be called perioridically by
21-
// inference routines in InferenceRoutines.h.
20+
// Base class for an inference object to be called perioridically by
21+
// inference routines in InferenceRoutines.h.
2222
class InferenceCallback{
2323
// Disable these to prevent accidental copying/slicing.
2424
InferenceCallback(const InferenceCallback&) = delete;
@@ -27,9 +27,9 @@ class InferenceCallback{
2727
public:
2828
virtual ~InferenceCallback() = default;
2929

30-
// Is it a visual or audio inference.
30+
// Is it a visual or audio inference.
3131
InferenceType type() const{ return m_type; }
32-
// Name of the inference object.
32+
// Name of the inference object.
3333
const std::string& label() const{ return m_label; }
3434

3535

@@ -47,15 +47,14 @@ class InferenceCallback{
4747

4848

4949

50-
// Used by inference routines in InferenceRoutines.h.
51-
// The struct contains an inference callback and its inference period: how
52-
// long should an inference routine wait before calling the callback object
53-
// again.
50+
// Used by inference routines in InferenceRoutines.h.
51+
// The struct contains an inference callback and its inference period: how long
52+
// should an inference routine wait before calling the callback object again.
5453
struct PeriodicInferenceCallback{
5554
InferenceCallback* callback;
56-
// inference period. 0 value means the inference routine should use the
57-
// default inference period, which is set as a parameter to the inference
58-
// routine.
55+
// Inference period. 0 value means the inference routine should use the
56+
// default inference period, which is set as a parameter to the inference
57+
// routine.
5958
std::chrono::milliseconds period;
6059

6160
PeriodicInferenceCallback()

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
#include "PokemonSwSh/Programs/PokemonSwSh_GameEntry.h"
135135
#include "PokemonSwSh/PokemonSwSh_Settings.h"
136136
#include "PokemonSV/Inference/Battles/PokemonSV_StartBattleYellowBar.h"
137+
#include "PokemonLA/Inference/Map/PokemonLA_SelectedRegionDetector.h"
138+
#include "PokemonHome/Inference/PokemonHome_BallReader.h"
139+
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathSide.h"
137140

138141
#include <QPixmap>
139142
#include <QVideoFrame>
@@ -193,32 +196,6 @@ TestProgram::TestProgram()
193196
, IMAGE_PATH(false, "Path to image for testing", LockMode::UNLOCK_WHILE_RUNNING, "default.png", "default.png")
194197
, STATIC_TEXT("Test text...")
195198
// , PLAYER_LIST("Test Table", LockMode::UNLOCK_WHILE_RUNNING, "Notes")
196-
, DATE0(
197-
"Date",
198-
LockMode::UNLOCK_WHILE_RUNNING,
199-
DateTimeOption::DATE_HOUR_MIN,
200-
DateTime{2000, 1, 1, 0, 0, 0},
201-
DateTime{2060, 12, 31, 23, 59, 59},
202-
DateTime{2024, 4, 12, 2, 16, 30}
203-
)
204-
, DATE1(
205-
"Date",
206-
LockMode::UNLOCK_WHILE_RUNNING,
207-
DateTimeOption::DATE_HOUR_MIN,
208-
DateTime{2000, 1, 1, 0, 0, 0},
209-
DateTime{2060, 12, 31, 23, 59, 59},
210-
DateTime{2048, 1, 13, 20, 48}
211-
)
212-
, DURATION(
213-
"Duration",
214-
LockMode::UNLOCK_WHILE_RUNNING,
215-
"100"
216-
)
217-
, COLOR(
218-
LockMode::UNLOCK_WHILE_RUNNING,
219-
false,
220-
0x000000, 0x000000
221-
)
222199
, NOTIFICATION_TEST("Test", true, true, ImageAttachmentMode::JPG)
223200
, NOTIFICATIONS({
224201
&NOTIFICATION_TEST,
@@ -234,11 +211,6 @@ TestProgram::TestProgram()
234211
PA_ADD_OPTION(STATIC_TEXT);
235212
// PA_ADD_OPTION(PLAYER_LIST);
236213
// PA_ADD_OPTION(battle_AI);
237-
PA_ADD_OPTION(DATE0);
238-
PA_ADD_OPTION(DATE1);
239-
PA_ADD_OPTION(DURATION);
240-
PA_ADD_OPTION(COLOR);
241-
PA_ADD_OPTION(CONTROLLER_TABLE);
242214
PA_ADD_OPTION(NOTIFICATIONS);
243215
BUTTON0.add_listener(*this);
244216
BUTTON1.add_listener(*this);
@@ -263,10 +235,6 @@ void TestProgram::on_press(){
263235

264236

265237

266-
267-
268-
269-
270238
void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope& scope){
271239
using namespace Kernels;
272240
using namespace Kernels::Waterfill;
@@ -286,14 +254,59 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
286254
ProControllerContext context(scope, console.pro_controller());
287255
VideoOverlaySet overlays(overlay);
288256

257+
auto screenshot = feed.snapshot();
258+
259+
PokemonSwSh::MaxLairInternal::PathSelectDetector detector;
260+
detector.detect(screenshot);
261+
262+
// int ret = PokemonSwSh::MaxLairInternal::read_side(screenshot);
263+
// cout << "ret = " << ret << endl;
289264

265+
266+
267+
268+
#if 0
269+
ImageRGB32 image("20250717-121112090631.png");
270+
271+
AdvanceDialogDetector detector;
272+
detector.make_overlays(overlays);
273+
cout << detector.detect(image) << endl;
274+
#endif
275+
276+
#if 0
277+
ImageRGB32 image(RESOURCE_PATH() + "PokemonHome/PokeballSprites.png");
278+
image = remove_white_border(image);
279+
image.save("test.png");
280+
#endif
281+
282+
283+
#if 0
290284
auto screenshot = feed.snapshot();
291285

286+
PokemonHome::BallReader reader(console);
287+
288+
reader.read_ball(screenshot);
289+
#endif
290+
291+
292+
293+
// pbf_press_button(context, );
294+
295+
296+
297+
298+
// PokemonLA::detect_selected_region(console, scope);
299+
300+
301+
302+
303+
#if 0
304+
auto screenshot = feed.snapshot();
292305

293306

294307
StartBattleYellowBarDetector detector(COLOR_RED);
295308
cout << detector.detect(screenshot) << endl;
296-
309+
#endif
297310

298311

299312

@@ -307,14 +320,14 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
307320

308321
#if 0
309322
HomeMenuDetector detector0(console);
310-
StartGameUserSelectDetector detector1(console);
311-
UpdatePopupDetector detector2(console);
323+
// StartGameUserSelectDetector detector1(console);
324+
// UpdatePopupDetector detector2(console);
312325
detector0.make_overlays(overlays);
313-
detector1.make_overlays(overlays);
314-
detector2.make_overlays(overlays);
326+
// detector1.make_overlays(overlays);
327+
// detector2.make_overlays(overlays);
315328
cout << detector0.detect(feed.snapshot()) << endl;
316-
cout << detector1.detect(feed.snapshot()) << endl;
317-
cout << detector2.detect(feed.snapshot()) << endl;
329+
// cout << detector1.detect(feed.snapshot()) << endl;
330+
// cout << detector2.detect(feed.snapshot()) << endl;
318331
#endif
319332

320333

@@ -336,7 +349,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
336349
auto screenshot = feed.snapshot();
337350

338351

339-
BinarySliderDetector detector(COLOR_RED, {0.831784, 0.140496, 0.088290, 0.671074});
352+
BinarySliderDetector detector(COLOR_RED, {0.836431, 0.097521, 0.069703, 0.796694});
340353
auto sliders = detector.detect(screenshot);
341354

342355
for (auto& item : sliders){

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@ class TestProgram : public MultiSwitchProgramInstance, public ButtonListener{
7373

7474
StaticTextOption STATIC_TEXT;
7575

76-
// PokemonSV::PlayerListTable PLAYER_LIST;
77-
DateTimeOption DATE0;
78-
DateTimeOption DATE1;
79-
// ConsoleModelOption CONSOLE_MODEL;
80-
81-
MillisecondsOption DURATION;
82-
ColorCell COLOR;
83-
ControllerSettingsTable CONTROLLER_TABLE;
84-
8576

8677
// PokemonSV::SinglesAIOption battle_AI;
8778

SerialPrograms/Source/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathSelect.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ PathSelectDetector::PathSelectDetector()
9898
, m_dialog_middle(0.500, 0.880, 0.180, 0.050)
9999
// , m_dialog_right(0.710, 0.880, 0.030, 0.050)
100100
, m_left(0.050, 0.100, 0.200, 0.700)
101+
, m_path_box(0.150, 0.020, 0.800, 0.780)
101102
{}
102103
void PathSelectDetector::make_overlays(VideoOverlaySet& items) const{
103104
items.add(COLOR_CYAN, m_bottom_right);
@@ -147,6 +148,14 @@ bool PathSelectDetector::detect(const ImageViewRGB32& screen) const{
147148
// if (dialog_right.average.sum() > dialog_middle.average.sum()){
148149
// return false;
149150
// }
151+
152+
ImageViewRGB32 path_box = extract_box_reference(screen, m_path_box);
153+
if (read_side(path_box) < 0){
154+
// cout << "PathSelectDetector(): read_side(screen) < 0" << endl;
155+
return false;
156+
}
157+
158+
// cout << "PathSelectDetector(): Passed" << endl;
150159
return true;
151160
}
152161
bool PathSelectDetector::process_frame(const ImageViewRGB32& frame, WallClock timestamp){

SerialPrograms/Source/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathSelect.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class PathSelectDetector : public PathScreenDetector{
5656
ImageFloatBox m_dialog_middle;
5757
// ImageFloatBox m_dialog_right;
5858
ImageFloatBox m_left;
59+
ImageFloatBox m_path_box;
5960
};
6061

6162

@@ -99,8 +100,6 @@ class PathReader{
99100
void read_sprites(Logger& logger, const ImageViewRGB32& screen, std::string slugs[4]) const;
100101
void read_hp(Logger& logger, const ImageViewRGB32& screen, double hp[4]) const;
101102

102-
static int8_t read_side(const ImageViewRGB32& image, int p_min_rgb_sum);
103-
104103
private:
105104
size_t m_player_index;
106105
OverlayBoxScope m_path;

SerialPrograms/Source/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathSide.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,19 @@ int8_t read_side(WaterfillSession& session, const ImageViewRGB32& image, uint8_t
325325
// cout << "pixel_threshold = " << (int)pixel_threshold << endl;
326326
session.set_source(matrix);
327327

328-
auto finder = session.make_iterator(300);
328+
size_t min_area = image.total_pixels();
329+
min_area = (size_t)((double)300 * min_area / 1293312);
330+
331+
auto finder = session.make_iterator(min_area);
329332
WaterfillObject arrow;
330333
WaterfillObject object;
331334
size_t count = 0;
332335
while (finder->find_next(object, true)){
333-
if (is_arrow(image, object)){
334-
count++;
335-
arrow = object;
336+
if (!is_arrow(image, object)){
337+
continue;
336338
}
339+
count++;
340+
arrow = object;
337341
}
338342
// cout << "count = " << count << endl;
339343
if (count != 1){
@@ -348,6 +352,7 @@ int8_t read_side(WaterfillSession& session, const ImageViewRGB32& image, uint8_t
348352
}
349353

350354
int8_t read_side(const ImageViewRGB32& image){
355+
// cout << image.width() * image.height() << endl;
351356
auto session = make_WaterfillSession();
352357
int8_t ret;
353358
if ((ret = read_side(*session, image, 160)) != -1) return ret;

SerialPrograms/Source/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options_Consoles.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ CaughtScreenActionsOption::CaughtScreenActionsOption(
6565
"<b>Boss/Legendary is Shiny:</b><br>If there are multiple shinies where one is the boss, this option still applies.<br><br>"
6666
"<font color=\"red\">For safety reasons, this program will <i>NEVER</i> automatically take a boss. "
6767
"Likewise, the settings here are intentionally worded so that it's impossible to ask the program to take a boss. "
68-
"Because taking a boss is irreversible, we refuse to automate it and require you to do it manually to avoid any mistakes.</font>",
68+
"Taking a boss is irreversible, therefore we refuse to automate it. We require you to do it manually to avoid any mistakes.<br><br>"
69+
"<b>Please DO NOT ask us to implement the ability to automatically take a boss. Thank you.</b></font>",
6970
default_shiny_boss
7071
)
7172
, description(

0 commit comments

Comments
 (0)