Skip to content

Commit a74010b

Browse files
authored
Autostory Segment 22: Levincia Gym (Electric) (#679)
* autostory: checkpoint 50. arrive at Levincia (South) Pokecenter. * Autostory: checkpoint 51: At Levincia gym building. Talked to Hassel, met Rika. * Autostory: checkpoint 52: Finished Levincia gym challenge. * WhiteTriangleDetector: add more color filters * Autostory: checkpoint 53: Defeated Levincia Gym (Electric). At Levincia (North) Pokecenter.
1 parent d70b22f commit a74010b

9 files changed

+592
-62
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,8 @@ file(GLOB MAIN_SOURCES
17101710
Source/PokemonSV/Inference/PokemonSV_TutorialDetector.h
17111711
Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.cpp
17121712
Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.h
1713+
Source/PokemonSV/Inference/PokemonSV_WhiteTriangleDetector.cpp
1714+
Source/PokemonSV/Inference/PokemonSV_WhiteTriangleDetector.h
17131715
Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.cpp
17141716
Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.h
17151717
Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.cpp
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* White Triangle Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Containers/FixedLimitVector.tpp"
8+
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
9+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
10+
#include "CommonTools/Images/WaterfillUtilities.h"
11+
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
12+
#include "Kernels/Waterfill/Kernels_Waterfill_Types.h"
13+
#include "PokemonSV_WhiteTriangleDetector.h"
14+
15+
// #include <iostream>
16+
// using std::cout;
17+
// using std::endl;
18+
19+
namespace PokemonAutomation{
20+
namespace NintendoSwitch{
21+
namespace PokemonSV{
22+
23+
24+
class WhiteTriangleMatcher : public ImageMatch::WaterfillTemplateMatcher{
25+
public:
26+
27+
WhiteTriangleMatcher() : WaterfillTemplateMatcher(
28+
"PokemonSV/WhiteTriangleIcon-Template.png", Color(200,200,200), Color(255, 255, 255), 50
29+
){
30+
m_aspect_ratio_lower = 0.8;
31+
m_aspect_ratio_upper = 1.2;
32+
m_area_ratio_lower = 0.9;
33+
m_area_ratio_upper = 1.4;
34+
35+
}
36+
37+
static const ImageMatch::WaterfillTemplateMatcher& instance(){
38+
static WhiteTriangleMatcher matcher;
39+
return matcher;
40+
}
41+
};
42+
43+
44+
WhiteTriangleDetector::~WhiteTriangleDetector() = default;
45+
46+
WhiteTriangleDetector::WhiteTriangleDetector(Color color, const ImageFloatBox& box)
47+
: m_color(color)
48+
, m_box(box)
49+
{}
50+
51+
void WhiteTriangleDetector::make_overlays(VideoOverlaySet& items) const{
52+
items.add(m_color, m_box);
53+
}
54+
55+
56+
bool WhiteTriangleDetector::detect(const ImageViewRGB32& screen) {
57+
const std::vector<std::pair<uint32_t, uint32_t>> filters = {
58+
{combine_rgb(240, 240, 240), combine_rgb(255, 255, 255)},
59+
{combine_rgb(220, 220, 220), combine_rgb(240, 240, 240)},
60+
{combine_rgb(200, 200, 200), combine_rgb(220, 220, 220)},
61+
{combine_rgb(190, 190, 190), combine_rgb(210, 210, 210)},
62+
63+
};
64+
65+
const double rmsd_threshold = 50.0;
66+
67+
const double min_object_size = 100.0;
68+
69+
const double screen_rel_size = (screen.height() / 1080.0);
70+
const size_t min_size = size_t(screen_rel_size * screen_rel_size * min_object_size);
71+
72+
bool is_found = false;
73+
match_template_by_waterfill(
74+
extract_box_reference(screen, m_box),
75+
WhiteTriangleMatcher::instance(),
76+
filters,
77+
{min_size, SIZE_MAX},
78+
rmsd_threshold,
79+
[&](Kernels::Waterfill::WaterfillObject& object) -> bool {
80+
is_found = true;
81+
return true;
82+
}
83+
);
84+
85+
return is_found;
86+
}
87+
88+
89+
90+
// WhiteTriangleWatcher::~WhiteTriangleWatcher() = default;
91+
92+
// WhiteTriangleWatcher::WhiteTriangleWatcher(Color color, const ImageFloatBox& box)
93+
// : VisualInferenceCallback("WhiteTriangleWatcher")
94+
// , m_detector(color, box)
95+
// {}
96+
97+
// void WhiteTriangleWatcher::make_overlays(VideoOverlaySet& items) const{
98+
// m_detector.make_overlays(items);
99+
// }
100+
101+
// bool WhiteTriangleWatcher::process_frame(const ImageViewRGB32& screen, WallClock timestamp){
102+
// return m_detector.detect(screen);
103+
// }
104+
105+
106+
107+
108+
109+
110+
111+
112+
}
113+
}
114+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* White Triangle Detector
2+
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonSV_WhiteTriangleDetector_H
8+
#define PokemonAutomation_PokemonSV_WhiteTriangleDetector_H
9+
10+
#include <vector>
11+
#include "Common/Cpp/Color.h"
12+
#include "Common/Cpp/Containers/FixedLimitVector.h"
13+
#include "CommonFramework/ImageTools/ImageBoxes.h"
14+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
15+
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
16+
#include "CommonTools/VisualDetector.h"
17+
18+
namespace PokemonAutomation{
19+
20+
class VideoOverlaySet;
21+
class VideoOverlay;
22+
class OverlayBoxScope;
23+
24+
namespace NintendoSwitch{
25+
namespace PokemonSV{
26+
27+
class WhiteTriangleDetector : public StaticScreenDetector{
28+
public:
29+
WhiteTriangleDetector(Color color, const ImageFloatBox& box);
30+
virtual ~WhiteTriangleDetector();
31+
32+
virtual void make_overlays(VideoOverlaySet& items) const override;
33+
virtual bool detect(const ImageViewRGB32& screen) override;
34+
35+
protected:
36+
Color m_color;
37+
ImageFloatBox m_box;
38+
};
39+
40+
41+
42+
class WhiteTriangleWatcher : public DetectorToFinder<WhiteTriangleDetector>{
43+
public:
44+
WhiteTriangleWatcher(
45+
Color color,
46+
const ImageFloatBox& box,
47+
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
48+
)
49+
: DetectorToFinder("WhiteTriangleDetector", hold_duration, color, box)
50+
{}
51+
};
52+
53+
54+
55+
56+
57+
}
58+
}
59+
}
60+
#endif

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
6+
#include "CommonFramework/Exceptions/OperationFailedException.h"
7+
#include "CommonTools/Async/InferenceRoutines.h"
8+
69

710
#include "CommonFramework/GlobalSettingsPanel.h"
811
#include "CommonFramework/Notifications/ProgramNotifications.h"
@@ -84,7 +87,7 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
8487
segment_list.emplace_back(std::make_unique<AutoStory_Segment_19>());
8588
segment_list.emplace_back(std::make_unique<AutoStory_Segment_20>());
8689
segment_list.emplace_back(std::make_unique<AutoStory_Segment_21>());
87-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_22>());
90+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_22>());
8891
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_23>());
8992
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_24>());
9093

@@ -638,6 +641,11 @@ void AutoStory::test_checkpoints(
638641
checkpoint_list.push_back([&](){checkpoint_53(env, context, notif_status_update, stats);});
639642
checkpoint_list.push_back([&](){checkpoint_54(env, context, notif_status_update, stats);});
640643
checkpoint_list.push_back([&](){checkpoint_55(env, context, notif_status_update, stats);});
644+
checkpoint_list.push_back([&](){checkpoint_56(env, context, notif_status_update, stats);});
645+
checkpoint_list.push_back([&](){checkpoint_57(env, context, notif_status_update, stats);});
646+
checkpoint_list.push_back([&](){checkpoint_58(env, context, notif_status_update, stats);});
647+
checkpoint_list.push_back([&](){checkpoint_59(env, context, notif_status_update, stats);});
648+
checkpoint_list.push_back([&](){checkpoint_60(env, context, notif_status_update, stats);});
641649

642650

643651
for (int checkpoint = start; checkpoint <= end; checkpoint++){
@@ -798,7 +806,8 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerCont
798806
// 128, 0, 60, 10, false);
799807

800808
DirectionDetector direction;
801-
809+
810+
802811
return;
803812
}
804813

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_21.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
#include "CommonTools/Async/InferenceRoutines.h"
88

99
#include "CommonFramework/Exceptions/OperationFailedException.h"
10-
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
1110
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1211
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
13-
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
14-
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
1512
#include "PokemonSV/Programs/PokemonSV_MenuNavigation.h"
1613
#include "PokemonSV/Programs/PokemonSV_WorldNavigation.h"
1714
#include "PokemonSV_AutoStoryTools.h"

0 commit comments

Comments
 (0)